예제 #1
0
 public function testFlush()
 {
     parent::testFlush();
     $this->assertTableHasNRecords('jlx_cache', 3);
     $this->assertTrue(jCache::flush($this->profile));
     $this->assertTableIsEmpty('jlx_cache');
 }
 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);
 }
 protected function getcapabilities()
 {
     $result = parent::getcapabilities();
     if ($result->cached) {
         return $result;
     }
     $data = $result->data;
     if (empty($data) or floor($result->code / 100) >= 4) {
         jMessage::add('Server Error !', 'Error');
         return $this->serviceException();
     }
     if (preg_match('#ServiceExceptionReport#i', $data)) {
         return $result;
     }
     // Replace qgis server url in the XML (hide real location)
     $sUrl = jUrl::getFull("lizmap~service:index", array("repository" => $this->repository->getKey(), "project" => $this->project->getKey()));
     $sUrl = str_replace('&', '&', $sUrl);
     preg_match('/<get>.*\\n*.+xlink\\:href="(.+)"/i', $data, $matches);
     if (count($matches) < 2) {
         preg_match('/get onlineresource="(.+)"/i', $data, $matches);
     }
     if (count($matches) > 1) {
         $data = str_replace($matches[1], $sUrl, $data);
     }
     $data = str_replace('&amp;&amp;', '&amp;', $data);
     // Add response to cache
     $cacheId = $this->repository->getKey() . '_' . $this->project->getKey() . '_' . $this->param('service');
     $newhash = md5_file(realpath($this->repository->getPath()) . '/' . $this->project->getKey() . ".qgs");
     jCache::set($cacheId . '_hash', $newhash);
     jCache::set($cacheId . '_mime', $result->mime);
     jCache::set($cacheId . '_data', $data);
     return (object) array('code' => 200, 'mime' => $result->mime, 'data' => $data, 'cached' => False);
 }
 protected function getcapabilities()
 {
     $result = parent::getcapabilities();
     if ($result->cached) {
         return $result;
     }
     $data = $result->data;
     if (empty($data) or floor($result->code / 100) >= 4) {
         jMessage::add('Server Error !', 'Error');
         return $this->serviceException();
     }
     if (preg_match('#ServiceExceptionReport#i', $data)) {
         return $result;
     }
     // Remove no interoparable elements
     $data = preg_replace('@<GetPrint[^>]*?>.*?</GetPrint>@si', '', $data);
     $data = preg_replace('@<ComposerTemplates[^>]*?>.*?</ComposerTemplates>@si', '', $data);
     // Replace qgis server url in the XML (hide real location)
     $sUrl = jUrl::getFull("lizmap~service:index", array("repository" => $this->repository->getKey(), "project" => $this->project->getKey()));
     $sUrl = str_replace('&', '&amp;', $sUrl);
     preg_match('/<get>.*\\n*.+xlink\\:href="(.+)"/i', $data, $matches);
     if (count($matches) < 2) {
         preg_match('/get onlineresource="(.+)"/i', $data, $matches);
     }
     if (count($matches) > 1) {
         $data = str_replace($matches[1], $sUrl, $data);
     }
     $data = str_replace('&amp;&amp;', '&amp;', $data);
     if (preg_match('@WMS_Capabilities@i', $data)) {
         // Update namespace
         $schemaLocation = "http://www.opengis.net/wms";
         $schemaLocation .= " http://schemas.opengis.net/wms/1.3.0/capabilities_1_3_0.xsd";
         $schemaLocation .= " http://www.opengis.net/sld";
         $schemaLocation .= " http://schemas.opengis.net/sld/1.1.0/sld_capabilities.xsd";
         $schemaLocation .= " http://www.qgis.org/wms";
         $schemaLocation .= " " . $sUrl . "SERVICE=WMS&amp;REQUEST=GetSchemaExtension";
         $data = preg_replace('@xsi:schemaLocation=".*?"@si', 'xsi:schemaLocation="' . $schemaLocation . '"', $data);
         if (!preg_match('@xmlns:qgs@i', $data)) {
             $data = preg_replace('@xmlns="http://www.opengis.net/wms"@', 'xmlns="http://www.opengis.net/wms" xmlns:qgs="http://www.qgis.org/wms"', $data);
             $data = preg_replace('@GetStyles@', 'qgs:GetStyles', $data);
         }
         if (!preg_match('@xmlns:sld@i', $data)) {
             $data = preg_replace('@xmlns="http://www.opengis.net/wms"@', 'xmlns="http://www.opengis.net/wms" xmlns:sld="http://www.opengis.net/sld"', $data);
             $data = preg_replace('@GetLegendGraphic@', 'sld:GetLegendGraphic', $data);
         }
     }
     // Add response to cache
     $cacheId = $this->repository->getKey() . '_' . $this->project->getKey() . '_' . $this->param('service');
     $newhash = md5_file(realpath($this->repository->getPath()) . '/' . $this->project->getKey() . ".qgs");
     jCache::set($cacheId . '_hash', $newhash);
     jCache::set($cacheId . '_mime', $result->mime);
     jCache::set($cacheId . '_data', $data);
     return (object) array('code' => 200, 'mime' => $result->mime, 'data' => $data, 'cached' => False);
 }
예제 #5
0
 public function testFlush()
 {
     parent::testFlush();
     $this->assertTrue(file_exists(jApp::tempPath() . 'cache/usingfile/jelix_cache___flush1DataKey.cache'));
     $this->assertTrue(file_exists(jApp::tempPath() . 'cache/usingfile/jelix_cache___flush2DataKey.cache'));
     $this->assertTrue(file_exists(jApp::tempPath() . 'cache/usingfile/jelix_cache___flush3DataKey.cache'));
     $this->assertTrue(jCache::flush($this->profile));
     $this->assertFalse(file_exists(jApp::tempPath() . 'cache/usingfile/jelix_cache___flush1DataKey.cache'));
     $this->assertFalse(file_exists(jApp::tempPath() . 'cache/usingfile/jelix_cache___flush2DataKey.cache'));
     $this->assertFalse(file_exists(jApp::tempPath() . 'cache/usingfile/jelix_cache___flush3DataKey.cache'));
 }
예제 #6
0
 public function testFlush()
 {
     parent::testFlush();
     $mmc = memcache_connect($this->mmhost, $this->mmport);
     $this->assertTrue(memcache_get($mmc, 'flush1DataKey'));
     $this->assertTrue(memcache_get($mmc, 'flush2DataKey'));
     $this->assertTrue(memcache_get($mmc, 'flush3DataKey'));
     $this->assertTrue(jCache::flush($this->profile));
     $this->assertFalse(memcache_get($mmc, 'flush1DataKey'));
     $this->assertFalse(memcache_get($mmc, 'flush2DataKey'));
     $this->assertFalse(memcache_get($mmc, 'flush3DataKey'));
 }
예제 #7
0
 public function deljcache()
 {
     $rep = $this->getResponse();
     $redisPlugin = jCache::getDriver($this->param('profile'));
     if (get_class($redisPlugin) != 'redisCacheDriver') {
         $rep->addContent("Error, wrong profile. Not a redis cache.\n");
         $this->setExitCode(1);
         return $rep;
     }
     $rep->addContent("--- Starting worker...\n");
     $redis = $redisPlugin->getRedis();
     while (true) {
         $prefixKey = $redis->lpop('jcacheredisdelkeys');
         if (!$prefixKey) {
             sleep(1);
             continue;
         }
         $rep->addContent("flush {$prefixKey}\n");
         $redis->flushByPrefix($prefixKey);
     }
     return $rep;
 }
예제 #8
0
 /**
  *
  */
 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;
 }
예제 #9
0
 public function testGarbage()
 {
     $this->assertFalse(jCache::garbage());
     jCache::set('remainingDataKey', 'remaining data', 0, $this->profile);
     jCache::set('garbage1DataKey', 'data send to the garbage', 1, $this->profile);
     jCache::set('garbage2DataKey', 'other data send to the garbage', strtotime("-1 day"), $this->profile);
     sleep(2);
     $this->assertTrue(jCache::garbage($this->profile));
 }
예제 #10
0
 public function flushAll()
 {
     jCache::flush('jforms');
     $this->containers = array();
 }
예제 #11
0
 /**
  * clear right cache
  */
 public function clearCache()
 {
     $this->acl = null;
     $this->aclres = array();
     $this->anonacl = null;
     $this->anonaclres = array();
     jCache::flush('acl2db');
 }
예제 #12
0
 public static function clearLayerCache($repository, $project, $layer)
 {
     // Storage type
     $ser = lizmap::getServices();
     $cacheStorageType = $ser->cacheStorageType;
     // Cache root directory
     if ($cacheStorageType != 'redis') {
         $cacheRootDirectory = $ser->cacheRootDirectory;
         if (!is_writable($cacheRootDirectory) or !is_dir($cacheRootDirectory)) {
             $cacheRootDirectory = sys_get_temp_dir();
         }
         // Directory where cached files are stored for the project
         $cacheProjectDir = $cacheRootDirectory . '/' . $repository . '/' . $project . '/';
         $results = array();
         if (file_exists($cacheProjectDir)) {
             // Open the directory and walk through the filenames
             $handle = opendir($cacheProjectDir);
             while (false !== ($entry = readdir($handle))) {
                 if ($entry != "." && $entry != "..") {
                     // Get directories and files corresponding to the layer
                     if (preg_match('#(^|_)' . $layer . '($|_)#', $entry)) {
                         $results[] = $cacheProjectDir . $entry;
                     }
                 }
             }
             closedir($handle);
             foreach ($results as $rem) {
                 if (is_dir($rem)) {
                     jFile::removeDir($rem);
                 } else {
                     unlink($rem);
                 }
             }
         }
     } else {
         // FIXME: removing by layer is not supported for the moment. For the moment, we flush all layers of the project.
         $cacheName = 'lizmapCache_' . $repository . '_' . $project;
         self::declareRedisProfile($ser, $cacheName, $repository, $project);
         jCache::flush($cacheName);
     }
     jEvent::notify('lizmapProxyClearLayerCache', array('repository' => $repository, 'project' => $project, 'layer' => $layer));
 }
 /**
  * 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();
 }
 public function clearCache()
 {
     $file = $this->repository->getPath() . $this->key . '.qgs';
     try {
         jCache::delete($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');
     }
 }