예제 #1
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;
 }
예제 #2
0
 function GetTile()
 {
     jClasses::inc('lizmap~lizmapWMTSRequest');
     $wmsRequest = new lizmapWMTSRequest($this->project, $this->params);
     $result = $wmsRequest->process();
     $rep = $this->getResponse('binary');
     $rep->mimeType = $result->mime;
     $rep->content = $result->data;
     $rep->doDownload = false;
     $rep->outputFileName = 'qgis_server_wmts_tile_' . $this->repository->getKey() . '_' . $this->project->getKey();
     $rep->setHttpStatus($result->code, '');
     if (!preg_match('/^image/', $result->mime)) {
         return $rep;
     }
     // HTTP browser cache expiration time
     $layername = $this->params["layer"];
     $lproj = lizmap::getProject($this->repository->getKey() . '~' . $this->project->getKey());
     $configLayers = $lproj->getLayers();
     if (property_exists($configLayers, $layername)) {
         $configLayer = $configLayers->{$layername};
         if (property_exists($configLayer, 'clientCacheExpiration')) {
             $clientCacheExpiration = (int) $configLayer->clientCacheExpiration;
             $rep->setExpires("+" . $clientCacheExpiration . " seconds");
         }
     }
     return $rep;
 }