protected function getcapabilities() { $cacheId = $this->repository->getKey() . '_' . $this->project->getKey() . '_' . $this->param('service'); $hash = jCache::get($cacheId . '_hash'); $cachedMime = jCache::get($cacheId . '_mime'); $cachedData = jCache::get($cacheId . '_data'); $newhash = md5_file(realpath($this->repository->getPath()) . '/' . $this->project->getKey() . ".qgs"); // Verifying cache content if ($cachedData && preg_match('#ServiceExceptionReport#i', $cachedData)) { $hash = null; $cachedMime = null; $cachedData = null; jCache::delete($cacheId . '_hash'); } // Cache exists for the unchanged QGIS project file if ($hash and $cachedMime and $cachedData and $hash == $newhash) { return (object) array('code' => 200, 'mime' => $cachedMime, 'data' => $cachedData, 'cached' => True); } // No cache or the file content has changed $url = $this->services->wmsServerURL . '?'; $bparams = http_build_query($this->params); $querystring = $url . $bparams; // Get remote data $getRemoteData = lizmapProxy::getRemoteData($querystring, $this->services->proxyMethod, $this->services->debugMode); $data = $getRemoteData[0]; $mime = $getRemoteData[1]; $code = $getRemoteData[2]; return (object) array('code' => $code, 'mime' => $mime, 'data' => $data, 'cached' => False); }
public function testGet() { parent::testGet(); $this->insertRecordsIntoTable('jlx_cache', array('cache_key', 'cache_data', 'cache_date'), array(array('cache_key' => 'phpIncompleteClassKey', 'cache_data' => 'O:9:"dummyData":2:{s:5:"label";s:23:"test unserializing data";s:11:"description";s:26:"for expecting an exception";}', 'cache_date' => null))); $data = jCache::get('phpIncompleteClassKey', $this->profile); if (!is_object($data)) { $this->pass(); } else { $this->fail(); } }
/** * */ function seeding() { $fakeServer = new jelix\FakeServerConf\ApacheMod(jApp::wwwPath(), '/index.php'); $forced = $this->option('-f'); $verbose = $this->option('-v'); $rep = $this->getResponse(); // cmdline response by default $project = null; try { $project = lizmap::getProject($this->param('repository') . '~' . $this->param('project')); // Project not found if (!$project) { $rep->addContent("The project has not be found!\n"); return $rep; } } catch (UnknownLizmapProjectException $e) { $rep->addContent("The project has not be found!\n"); return $rep; } $repository = $project->getRepository(); $cacheId = $repository->getKey() . '_' . $project->getKey() . '_WMTS'; $tileMatrixSetList = jCache::get($cacheId . '_tileMatrixSetList'); if (!$tileMatrixSetList) { $request = new lizmapWMTSRequest($project, array('service' => 'WMTS', 'request' => 'GetCapabilities')); $result = $request->process(); $tileMatrixSetList = jCache::get($cacheId . '_tileMatrixSetList'); } $layers = $tileMatrixSetList = jCache::get($cacheId . '_layers'); $layerIds = explode(',', $this->param('layers')); $selectedLayers = array(); foreach ($layers as $l) { if (in_array('*', $layerIds) || in_array($l->name, $layerIds)) { $selectedLayers[] = $l; } } // Layer not found if (count($selectedLayers) == 0) { $rep->addContent("The layers '" . implode(',', $layerIds) . "' have not be found!\n"); return $rep; } foreach ($selectedLayers as $layer) { $TileMatrixSetId = $this->param('TileMatrixSet'); $tileMatrixSetLink = null; foreach ($layer->tileMatrixSetLinkList as $tms) { if ($tms->ref == $TileMatrixSetId) { $tileMatrixSetLink = $tms; break; } } // TileMatrixSet not found if (!$tileMatrixSetLink) { $rep->addContent("The TileMatrixSet '" . $TileMatrixSetId . "' has not be found!\n"); continue; } $TileMatrixMin = (int) $this->param('TileMatrixMin'); $TileMatrixMax = (int) $this->param('TileMatrixMax'); // count tiles $tileCount = 0; foreach ($tileMatrixSetLink->tileMatrixLimits as $tileMatrixLimit) { if ($tileMatrixLimit->id >= $TileMatrixMin && $tileMatrixLimit->id <= $TileMatrixMax) { $tmCount = ($tileMatrixLimit->maxRow - $tileMatrixLimit->minRow + 1) * ($tileMatrixLimit->maxCol - $tileMatrixLimit->minCol + 1); if ($verbose) { $rep->addContent($tmCount . ' tiles to generate for "' . $layer->name . '" "' . $TileMatrixSetId . '" "' . $tileMatrixLimit->id . '"' . "\n"); } $tileCount += $tmCount; } } if ($verbose) { $rep->addContent($tileCount . ' tiles to generate for "' . $layer->name . '" "' . $TileMatrixSetId . '" between "' . $TileMatrixMin . '" and "' . $TileMatrixMax . '"' . "\n"); } // generate tiles $rep->addContent("Start generation\n"); $rep->addContent("================\n"); $tileProgress = 0; $tileStepHeight = max(5.0, floor(5 * 100 / $tileCount)); $tileStep = $tileStepHeight; foreach ($tileMatrixSetLink->tileMatrixLimits as $tileMatrixLimit) { if ($tileMatrixLimit->id >= $TileMatrixMin && $tileMatrixLimit->id <= $TileMatrixMax) { $row = (int) $tileMatrixLimit->minRow; //$rep->addContent( $tileMatrixLimit->id.' '.$tileMatrixLimit->minRow.' '.$tileMatrixLimit->maxRow.' '.$tileMatrixLimit->minCol.' '.$tileMatrixLimit->maxCol."\n"); while ($row <= $tileMatrixLimit->maxRow) { $col = (int) $tileMatrixLimit->minCol; while ($col <= $tileMatrixLimit->maxCol) { $request = new lizmapWMTSRequest($project, array('service' => 'WMTS', 'version' => '1.0.0', 'request' => 'GetTile', 'layer' => $layer->name, 'format' => $layer->imageFormat, 'TileMatrixSet' => $TileMatrixSetId, 'TileMatrix' => $tileMatrixLimit->id, 'TileRow' => $row, 'TileCol' => $col)); if ($forced) { $request->setForceRequest(True); } $result = $request->process(); //$rep->addContent($layer->name.' '.$layer->imageFormat.' '.$TileMatrixSetId.' '.$tileMatrixLimit->id.' '.$row.' '.$col.' '.$result->code."\n"); $col += 1; $tileProgress += 1; if ($verbose && $tileProgress * 100 / $tileCount >= $tileStep) { $tileStep = floor($tileProgress * 100 / $tileCount); $rep->addContent('Progression: ' . $tileStep . '%, ' . $tileProgress . ' tiles generated on ' . $tileCount . ' tiles' . "\n"); $tileStep = $tileStep + $tileStepHeight; } } $row += 1; } } } $rep->addContent("================\n"); $rep->addContent("End generation\n"); } return $rep; }
public function testDelete() { $this->assertTrue(jCache::set('deleteKey', 'data to delete', 0, $this->profile)); $this->assertTrue(jCache::delete('deleteKey', $this->profile)); $this->assertFalse(jCache::get('deleteKey', $this->profile)); $this->assertFalse(jCache::delete('inexistentKey', $this->profile)); }
public function garbage() { jCache::garbage('jforms'); foreach ($this->containers as $key => $container) { if (!jCache::get($key, 'jforms')) { unset($this->containers[$key]); } } }
protected function getAnonymousRight($subject, $resource = '-') { if (empty($resource)) { $resource = '-'; } if ($this->anonacl === null) { $rights = jCache::get('acl2dbanon/rights', 'acl2db'); if ($rights === false) { // let's load rights for anonymous group $dao = jDao::get('jacl2db~jacl2rights', 'jacl2_profile'); $this->anonacl = array(); foreach ($dao->getAllAnonymousRights() as $rec) { if (isset($this->anonacl[$rec->id_aclsbj])) { if ($rec->canceled) { $this->anonacl[$rec->id_aclsbj] = false; } } else { $this->anonacl[$rec->id_aclsbj] = $rec->canceled ? false : true; } } jCache::set('acl2dbanon/rights', $this->anonacl, null, 'acl2db'); } else { $this->anonacl = $rights; } } if (!isset($this->anonacl[$subject])) { $this->anonacl[$subject] = false; jCache::set('acl2dbanon/rights', $this->anonacl, null, 'acl2db'); } // no resource given, just return the global right for the given subject if ($resource === '-') { return $this->anonacl[$subject]; } if (!isset($this->anonaclres[$subject])) { $rights = jCache::get('acl2dbanon/rightsres/' . $subject, 'acl2db'); if ($rights !== false) { $this->anonaclres[$subject] = $rights; } } // if we already have loaded the corresponding right, returns it if (isset($this->anonaclres[$subject][$resource])) { return $this->anonaclres[$subject][$resource]; } // default right for the resource is the global right $this->anonaclres[$subject][$resource] = $this->anonacl[$subject]; // if the general right is not given, check the specific right for the resource if (!$this->anonacl[$subject]) { $dao = jDao::get('jacl2db~jacl2rights', 'jacl2_profile'); $right = $dao->getAnonymousRightWithRes($subject, $resource); $this->anonaclres[$subject][$resource] = $right != false ? $right->canceled ? false : true : false; jCache::set('acl2dbanon/rightsres/' . $subject, $this->anonaclres[$subject], null, 'acl2db'); return $this->anonaclres[$subject][$resource]; } else { jCache::set('acl2dbanon/rightsres/' . $subject, $this->anonaclres[$subject], null, 'acl2db'); return true; } }
/** * Get data from map service or from the cache. * @param lizmapProject $project The project. * @param array $params Array of parameters. * @return array $data Normalized and filtered array. */ public static function getMap($project, $params, $forced = False) { // Get cache if exists $keyParams = array(); foreach ($params as $pk => $value) { if (in_array($pk, array("bbox", "format", "height", "layers", "transparent"))) { $keyParams[$pk] = $value; } } ksort($keyParams); $layers = str_replace(',', '_', $params['layers']); $crs = preg_replace('#[^a-zA-Z0-9_]#', '_', $params['crs']); // Get repository data $ser = lizmap::getServices(); $lrep = $project->getRepository(); $lproj = $project; $project = $lproj->getKey(); $repository = $lrep->getKey(); // Change to true to put some information in debug files $debug = $ser->debugMode; // Read config file for the current project $layername = $params["layers"]; $configLayers = $lproj->getLayers(); $configLayer = null; if (property_exists($configLayers, $layername)) { $configLayer = $configLayers->{$layername}; } // Set or get tile from the parent project in case of embedded layers if ($configLayer and property_exists($configLayer, 'sourceRepository') and property_exists($configLayer, 'sourceProject')) { $newRepository = (string) $configLayer->sourceRepository; $newProject = (string) $configLayer->sourceProject; $repository = $newRepository; $project = $newProject; $lrep = lizmap::getRepository($repository); if (!$lrep) { jMessage::add('The repository ' . strtoupper($repository) . ' does not exist !', 'RepositoryNotDefined'); return array('error', 'text/plain', '404'); } try { $lproj = lizmap::getProject($repository . '~' . $project); if (!$lproj) { jMessage::add('The lizmapProject ' . strtoupper($project) . ' does not exist !', 'ProjectNotDefined'); return array('error', 'text/plain', '404'); } } catch (UnknownLizmapProjectException $e) { jLog::logEx($e, 'error'); jMessage::add('The lizmapProject ' . strtoupper($project) . ' does not exist !', 'ProjectNotDefined'); return array('error', 'text/plain', '404'); } } $key = md5(serialize($keyParams)); // Get tile cache virtual profile (tile storage) // And get tile if already in cache // --> must be done after checking that parent project is involved $profile = lizmapProxy::createVirtualProfile($repository, $project, $layers, $crs); if ($debug) { lizmap::logMetric('LIZMAP_PROXY_READ_LAYER_CONFIG'); } // Has the user asked for cache for this layer ? $useCache = False; if ($configLayer) { $useCache = strtolower($configLayer->cached) == 'true'; } // Avoid using cache for requests concerning not square tiles or too big // Focus on real web square tiles $wmsClient = 'web'; if ($useCache and $params['width'] != $params['height'] and ($params['width'] > 300 or $params['height'] > 300)) { $wmsClient = 'gis'; $useCache = False; } if ($useCache and !$forced) { $tile = jCache::get($key, $profile); if ($tile) { $_SESSION['LIZMAP_GETMAP_CACHE_STATUS'] = 'read'; $mime = 'image/jpeg'; if (preg_match('#png#', $params['format'])) { $mime = 'image/png'; } if ($debug) { lizmap::logMetric('LIZMAP_PROXY_HIT_CACHE'); } return array($tile, $mime, 200); } } // *************************** // No cache hit : need to ask the tile from QGIS Server // *************************** // Construction of the WMS url : base url + parameters $url = $ser->wmsServerURL . '?'; // Add project path into map parameter $params["map"] = realpath($lproj->getQgisPath()); // Metatile : if needed, change the bbox // Avoid metatiling when the cache is not active for the layer $metatileSize = '1,1'; if ($configLayer and property_exists($configLayer, 'metatileSize')) { if (preg_match('#^[3579],[3579]$#', $configLayer->metatileSize)) { $metatileSize = $configLayer->metatileSize; } } # Metatile buffer $metatileBuffer = 5; // Also checks if gd is installed if ($metatileSize and $useCache and $wmsClient == 'web' and extension_loaded('gd') && function_exists('gd_info')) { # Metatile Size $metatileSizeExp = explode(',', $metatileSize); $metatileSizeX = (int) $metatileSizeExp[0]; $metatileSizeY = (int) $metatileSizeExp[1]; # Get requested bbox $bboxExp = explode(',', $params['bbox']); $width = $bboxExp[2] - $bboxExp[0]; $height = $bboxExp[3] - $bboxExp[1]; # Calculate factors $xFactor = (int) ($metatileSizeX / 2); $yFactor = (int) ($metatileSizeY / 2); # Calculate the new bbox $xmin = $bboxExp[0] - $xFactor * $width - $metatileBuffer * $width / $params["width"]; $ymin = $bboxExp[1] - $yFactor * $height - $metatileBuffer * $height / $params["height"]; $xmax = $bboxExp[2] + $xFactor * $width + $metatileBuffer * $width / $params["width"]; $ymax = $bboxExp[3] + $yFactor * $height + $metatileBuffer * $height / $params["height"]; # Replace request bbox by metatile bbox $params["bbox"] = "{$xmin},{$ymin},{$xmax},{$ymax}"; # Keep original param value $originalParams = array("width" => $params["width"], "height" => $params["height"]); # Replace width and height before requesting the image from qgis $params["width"] = $metatileSizeX * $params["width"] + 2 * $metatileBuffer; $params["height"] = $metatileSizeY * $params["height"] + 2 * $metatileBuffer; } // Build params before send the request to Qgis $builtParams = http_build_query($params); // Replace needed characters (not needed for php >= 5.4, just use the 4th parameter of the method http_build_query) $a = array('+', '_', '.', '-'); $b = array('%20', '%5F', '%2E', '%2D'); $builtParams = str_replace($a, $b, $builtParams); // Get data from the map server $proxyMethod = $ser->proxyMethod; $getRemoteData = lizmapProxy::getRemoteData($url . $builtParams, $proxyMethod, $debug); $data = $getRemoteData[0]; $mime = $getRemoteData[1]; $code = $getRemoteData[2]; if ($debug) { lizmap::logMetric('LIZMAP_PROXY_REQUEST_QGIS_MAP'); } if ($useCache && !preg_match('/^image/', $mime)) { $useCache = False; } // Metatile : if needed, crop the metatile into a single tile // Also checks if gd is installed if ($metatileSize and $useCache and $wmsClient == 'web' and extension_loaded('gd') && function_exists('gd_info')) { # Save original content into an image var $original = imagecreatefromstring($data); # crop parameters $newWidth = (int) $originalParams["width"]; // px $newHeight = (int) $originalParams["height"]; // px $positionX = (int) ($xFactor * $originalParams["width"]) + $metatileBuffer; // left translation of 30px $positionY = (int) ($yFactor * $originalParams["height"]) + $metatileBuffer; // top translation of 20px # create new gd image $image = imageCreateTrueColor($newWidth, $newHeight); # save transparency if needed if (preg_match('#png#', $params['format'])) { imagesavealpha($original, true); imagealphablending($image, false); $color = imagecolortransparent($image, imagecolorallocatealpha($image, 0, 0, 0, 127)); imagefill($image, 0, 0, $color); imagesavealpha($image, true); } # crop image imagecopyresampled($image, $original, 0, 0, $positionX, $positionY, $newWidth, $newHeight, $newWidth, $newHeight); # Output the image as a string (use PHP buffering) ob_start(); if (preg_match('#png#', $params['format'])) { imagepng($image, null, 9); } else { imagejpeg($image, null, 90); } $data = ob_get_contents(); // read from buffer ob_end_clean(); // delete buffer // Destroy image handlers imagedestroy($original); imagedestroy($image); if ($debug) { lizmap::logMetric('LIZMAP_PROXY_CROP_METATILE'); } } $_SESSION['LIZMAP_GETMAP_CACHE_STATUS'] = 'off'; // Store into cache if needed if ($useCache) { //~ jLog::log( ' Store into cache'); $cacheExpiration = (int) $ser->cacheExpiration; if (property_exists($configLayer, 'cacheExpiration')) { $cacheExpiration = (int) $configLayer->cacheExpiration; } jCache::set($key, $data, $cacheExpiration, $profile); $_SESSION['LIZMAP_GETMAP_CACHE_STATUS'] = 'write'; if ($debug) { lizmap::logMetric('LIZMAP_PROXY_WRITE_CACHE'); } } return array($data, $mime, $code); }
/** * Get data from map service or from the cache. * @param string $repository The repository. * @param string $project The project. * @param array $params Array of parameters. * @return array $data Normalized and filtered array. */ public static function getServiceData($repository, $project, $params) { // Get cache if exists $keyParams = $params; if (array_key_exists('map', $keyParams)) { unset($keyParams['map']); } ksort($keyParams); $key = md5(serialize($keyParams)); $layers = str_replace(',', '_', $params['layers']); $crs = preg_replace('#[^a-zA-Z0-9_]#', '_', $params['crs']); // Get repository data $ser = lizmap::getServices(); $lrep = lizmap::getRepository($repository); $lproj = lizmap::getProject($repository . '~' . $project); // Change to true to put some information in debug files $debug = $ser->debugMode; // Read config file for the current project $layername = $params["layers"]; $configLayers = $lproj->getLayers(); $configLayer = null; if (property_exists($configLayers, $layername)) { $configLayers->{$layername}; } // Set or get tile from the parent project in case of embedded layers if ($configLayer and property_exists($configLayer, 'sourceRepository') and property_exists($configLayer, 'sourceProject')) { $newRepository = (string) $configLayer->sourceRepository; $newProject = (string) $configLayer->sourceProject; $repository = $newRepository; $project = $newProject; $lrep = lizmap::getRepository($repository); $lproj = lizmap::getProject($repository . '~' . $project); } // Get tile cache virtual profile (tile storage) // And get tile if already in cache // --> must be done after checking that parent project is involved $profile = 'lizmapCache_' . $repository . '_' . $project . '_' . $layers . '_' . $crs; lizmapCache::createVirtualProfile($repository, $project, $layers, $crs); $tile = jCache::get($key, $profile); // Return tile if cache hit ! if ($tile) { //~ jLog::log( 'cache hit !'); return $tile; } // Has the user asked for cache for this layer ? $string2bool = array('false' => False, 'False' => False, 'True' => True, 'true' => True); $useCache = False; if ($configLayer) { $string2bool[$configLayer->cached]; } // Avoid using cache for requests concerning not square tiles or too big // Focus on real web square tiles $wmsClient = 'web'; if ($useCache and $params['width'] != $params['height'] and ($params['width'] > 300 or $params['height'] > 300)) { $wmsClient = 'gis'; $useCache = False; } // *************************** // No cache hit : need to ask the tile from QGIS Server // *************************** // Construction of the WMS url : base url + parameters $url = $ser->wmsServerURL . '?'; // Add project path into map parameter $params["map"] = realpath($lrep->getPath()) . '/' . $lproj->getKey() . ".qgs"; // Metatile : if needed, change the bbox // Avoid metatiling when the cache is not active for the layer $metatileSize = '1,1'; if ($configLayer and property_exists($configLayer, 'metatileSize')) { if (preg_match('#^[3579],[3579]$#', $configLayer->metatileSize)) { $metatileSize = $configLayer->metatileSize; } } # Metatile buffer $metatileBuffer = 5; // Also checks if gd is installed if ($metatileSize and $useCache and $wmsClient == 'web' and extension_loaded('gd') && function_exists('gd_info')) { # Metatile Size $metatileSizeExp = explode(',', $metatileSize); $metatileSizeX = (int) $metatileSizeExp[0]; $metatileSizeY = (int) $metatileSizeExp[1]; # Get requested bbox $bboxExp = explode(',', $params['bbox']); $width = $bboxExp[2] - $bboxExp[0]; $height = $bboxExp[3] - $bboxExp[1]; # Calculate factors $xFactor = (int) ($metatileSizeX / 2); $yFactor = (int) ($metatileSizeY / 2); # Calculate the new bbox $xmin = $bboxExp[0] - $xFactor * $width - $metatileBuffer * $width / $params["width"]; $ymin = $bboxExp[1] - $yFactor * $height - $metatileBuffer * $height / $params["height"]; $xmax = $bboxExp[2] + $xFactor * $width + $metatileBuffer * $width / $params["width"]; $ymax = $bboxExp[3] + $yFactor * $height + $metatileBuffer * $height / $params["height"]; # Replace request bbox by metatile bbox $params["bbox"] = "{$xmin},{$ymin},{$xmax},{$ymax}"; # Keep original param value $originalParams = array("width" => $params["width"], "height" => $params["height"]); # Replace width and height before requesting the image from qgis $params["width"] = $metatileSizeX * $params["width"] + 2 * $metatileBuffer; $params["height"] = $metatileSizeY * $params["height"] + 2 * $metatileBuffer; } // Build params before send the request to Qgis $builtParams = http_build_query($params); // Replace needed characters (not needed for php >= 5.4, just use the 4th parameter of the method http_build_query) $a = array('+', '_', '.', '-'); $b = array('%20', '%5F', '%2E', '%2D'); $builtParams = str_replace($a, $b, $builtParams); // Get data from the map server $proxyMethod = $ser->proxyMethod; $getRemoteData = lizmapCache::getRemoteData($url . $builtParams, $proxyMethod, $debug); $data = $getRemoteData[0]; $mime = $getRemoteData[1]; if ($useCache && !preg_match('/^image/', $mime)) { $useCache = False; } // Metatile : if needed, crop the metatile into a single tile // Also checks if gd is installed if ($metatileSize and $useCache and $wmsClient == 'web' and extension_loaded('gd') && function_exists('gd_info')) { # Save original content into an image var $original = imagecreatefromstring($data); # crop parameters $newWidth = (int) $originalParams["width"]; // px $newHeight = (int) $originalParams["height"]; // px $positionX = (int) ($xFactor * $originalParams["width"]) + $metatileBuffer; // left translation of 30px $positionY = (int) ($yFactor * $originalParams["height"]) + $metatileBuffer; // top translation of 20px # create new gd image $image = imageCreateTrueColor($newWidth, $newHeight); # save transparency if needed if (preg_match('#png#', $params['format'])) { imagesavealpha($original, true); imagealphablending($image, false); $color = imagecolortransparent($image, imagecolorallocatealpha($image, 0, 0, 0, 127)); imagefill($image, 0, 0, $color); imagesavealpha($image, true); } # crop image imagecopyresampled($image, $original, 0, 0, $positionX, $positionY, $newWidth, $newHeight, $newWidth, $newHeight); # Output the image as a string (use PHP buffering) ob_start(); if (preg_match('#png#', $params['format'])) { imagepng($image, null); } else { imagejpeg($image, null, 80); } $data = ob_get_contents(); // read from buffer ob_end_clean(); // delete buffer // Destroy image handlers imagedestroy($original); imagedestroy($image); } // Store into cache if needed if ($useCache) { //~ jLog::log( ' Store into cache'); $cacheExpiration = (int) $ser->cacheExpiration; if (property_exists($configLayer, 'cacheExpiration')) { $cacheExpiration = (int) $configLayer->cacheExpiration; } jCache::set($key, $data, $cacheExpiration, $profile); } return $data; }
function gettile() { //jLog::log('GetTile '.http_build_query($this->params)); // Get the layer $LayerName = $this->param('Layer'); if (!$LayerName) { // Error message jMessage::add('The parameter Layer is mandatory !', 'MissingParameter'); return $this->serviceException(); } $Format = $this->param('Format'); if (!$Format) { // Error message jMessage::add('The parameter Format is mandatory !', 'MissingParameter'); return $this->serviceException(); } $TileMatrixSetId = $this->param('TileMatrixSet'); if (!$TileMatrixSetId) { // Error message jMessage::add('The parameter TileMatrixSet is mandatory !', 'MissingParameter'); return $this->serviceException(); } $TileMatrixId = $this->param('TileMatrix'); if ($TileMatrixId === null) { // Error message jMessage::add('The parameter TileMatrix is mandatory !', 'MissingParameter'); return $this->serviceException(); } $TileRow = $this->param('TileRow'); if ($TileRow === null) { // Error message jMessage::add('The parameter TileRow is mandatory !', 'MissingParameter'); return $this->serviceException(); } $TileCol = $this->param('TileCol'); if ($TileCol === null) { // Error message jMessage::add('The parameter TileCol is mandatory !', 'MissingParameter'); return $this->serviceException(); } $cacheId = $this->repository->getKey() . '_' . $this->project->getKey() . '_WMTS'; $tileMatrixSetList = jCache::get($cacheId . '_tilematrixsetlist'); if (!$tileMatrixSetList) { $this->getcapabilities(); $tileMatrixSetList = jCache::get($cacheId . '_tilematrixsetlist'); } $tileMatrixSet = null; foreach ($tileMatrixSetList as $tms) { if ($tms->ref == $TileMatrixSetId) { $tileMatrixSet = $tms; break; } } if ($tileMatrixSet === null) { // Error message jMessage::add('TileMatrixSet seems to be wrong', 'MissingParameter'); return $this->serviceException(); } $tileWidth = 256.0; $tileHeight = 256.0; $tileMatrix = $tileMatrixSet->tileMatrixList[(int) $TileMatrixId]; $res = $tileMatrix->resolution; $minx = $tileMatrix->left + (int) $TileCol * ($tileWidth * $res); $miny = $tileMatrix->top - (int) $TileRow * ($tileHeight * $res); $maxx = $tileMatrix->left + ((int) $TileCol + 1) * ($tileWidth * $res); $maxy = $tileMatrix->top - ((int) $TileRow + 1) * ($tileHeight * $res); $params['service'] = 'WMS'; $params['version'] = '1.3.0'; $params['request'] = 'GetMap'; $params['layers'] = $LayerName; $params['styles'] = ''; $params['format'] = $Format; $params['crs'] = $TileMatrixSetId; $params['bbox'] = (string) round($minx, 6) . ',' . (string) round($miny, 6) . ',' . (string) round($maxx, 6) . ',' . (string) round($maxy, 6); $params['width'] = $tileWidth; $params['height'] = $tileHeight; $params['dpi'] = '96'; if (preg_match('#png#', $Format)) { $params['transparent'] = 'true'; } $wmsRequest = new lizmapWMSRequest($this->project, $params); $wmsRequest->setForceRequest($this->forceRequest); return $wmsRequest->process(); }
/** * constructor * @param string $key : the project name * @param lizmapRepository $ rep : the repository */ public function __construct($key, $rep) { $this->key = $key; $this->repository = $rep; $file = $rep->getPath() . $key . '.qgs'; // Verifying if the files exist if (!file_exists($file)) { throw new UnknownLizmapProjectException('The QGIS project ' . $file . ' does not exist!'); } if (!file_exists($file . '.cfg')) { throw new UnknownLizmapProjectException('The lizmap config ' . $file . '.cfg does not exist!'); } // For the cache key, we use the full path of the project file // to avoid collision in the cache engine $data = false; try { $data = jCache::get($file, 'qgisprojects'); } catch (Exception $e) { // if qgisprojects profile does not exist, or if there is an // other error about the cache, let's log it jLog::log($e->getMessage(), 'error'); } if ($data === false || $data['qgsmtime'] < filemtime($file) || $data['qgscfgmtime'] < filemtime($file . '.cfg')) { // FIXME reading XML could take time, so many process could // read it and construct the cache at the same time. We should // have a kind of lock to avoid this issue. $this->readXml($key, $rep); $data['qgsmtime'] = filemtime($file); $data['qgscfgmtime'] = filemtime($file . '.cfg'); foreach ($this->cachedProperties as $prop) { $data[$prop] = $this->{$prop}; } try { jCache::set($file, $data, null, 'qgisprojects'); } catch (Exception $e) { jLog::log($e->getMessage(), 'error'); } } else { foreach ($this->cachedProperties as $prop) { $this->{$prop} = $data[$prop]; } } }