1
0
mirror of https://github.com/klokantech/tileserver-php.git synced 2025-08-05 14:18:13 +02:00

Refactoring of tilematrixsets creation

This commit is contained in:
Dalibor Janák
2016-02-17 20:29:39 +01:00
parent ce485c6713
commit 0609b25905

View File

@@ -789,47 +789,82 @@ class Wmts extends Server {
* @return string TileMatrixSet xml * @return string TileMatrixSet xml
*/ */
public function getMercatorTileMatrixSet(){ public function getMercatorTileMatrixSet(){
$name = 'GoogleMapsCompatible'; $denominatorBase = 559082264.0287178;
$extent = array(-20037508.34,-20037508.34,20037508.34,20037508.34); $extent = array(-20037508.34,-20037508.34,20037508.34,20037508.34);
$scalesBase = 559082264.0287178; $tileMatrixSet = array();
$scales = array();
for($i = 0; $i <= 18; $i++){ for($i = 0; $i <= 18; $i++){
$scales[] = $scalesBase / pow(2, $i); $level = new stdClass();
$level->extent = $extent;
$level->id = (string) $i;
$matrixSize = pow(2, $i);
$level->matrix_size = array($matrixSize, $matrixSize);
$level->origin = array($extent[0], $extent[1]);
$level->scale_denominator = $denominatorBase / pow(2, $i);
$level->tile_size = array(256, 256);
$tileMatrixSet[] = (array) $level;
} }
return $this->getTileMatrixSet($name, $scales, $extent); return $this->getTileMatrixSet('GoogleMapsCompatible', $tileMatrixSet, 'EPSG:3857');
} }
/** /**
* Prints WMTS tilematrixset * Default TileMetrixSet for WGS84 projection 4326
* @return string Xml
*/
public function getWGS84TileMatrixSet(){
$extent = array(-180.000000, -90.000000, 180.000000, 90.000000);
$scaleDenominators = array(279541132.01435887813568115234, 139770566.00717943906784057617,
69885283.00358971953392028809, 34942641.50179485976696014404, 17471320.75089742988348007202,
8735660.37544871494174003601, 4367830.18772435747087001801, 2183915.09386217873543500900,
1091957.54693108936771750450, 545978.77346554468385875225, 272989.38673277234192937613,
136494.69336638617096468806, 68247.34668319308548234403, 34123.67334159654274117202,
17061.83667079825318069197, 8530.91833539912659034599, 4265.45916769956329517299,
2132.72958384978574031265);
$tileMatrixSet = array();
for($i = 0; $i <= count($scaleDenominators); $i++){
$level = new stdClass();
$level->extent = $extent;
$level->id = (string) $i;
$matrixSize = pow(2, $i);
$level->matrix_size = array($matrixSize * 2, $matrixSize);
$level->origin = array($extent[0], $extent[1]);
$level->scale_denominator = $scaleDenominators[$i];
$level->tile_size = array(256, 256);
$tileMatrixSet[] = (array) $level;
}
return $this->getTileMatrixSet('WGS84', $tileMatrixSet, 'EPSG:4326');
}
/**
* Prints WMTS TileMatrixSet
* @param string $name * @param string $name
* @param array $scales Array of scales * @param array $tileMatrixSet Array of levels
* @param array $extent Boundingbox of matrix
* @param string $crs Code of crs eg: EPSG:3857 * @param string $crs Code of crs eg: EPSG:3857
* @param array $matrixRatio Ratio of matrix sides
* @param array $tilesize Size of tile in pixels
* @return string TileMatrixSet xml * @return string TileMatrixSet xml
*/ */
public function getTileMatrixSet($name, $scales, $extent, $crs = 'EPSG:3857', $matrixRatio = array(1, 1), $tilesize = array(256, 256)){ public function getTileMatrixSet($name, $tileMatrixSet, $crs = 'EPSG:3857'){
$srs = explode(':', $crs); $srs = explode(':', $crs);
$TileMatrixSet = '<TileMatrixSet> $TileMatrixSet = '<TileMatrixSet>
<ows:Title>' . $name . '</ows:Title> <ows:Title>' . $name . '</ows:Title>
<ows:Abstract>' . $name . ' '. $crs .'</ows:Abstract> <ows:Abstract>' . $name . ' '. $crs .'</ows:Abstract>
<ows:Identifier>' . $name . '</ows:Identifier> <ows:Identifier>' . $name . '</ows:Identifier>
<ows:SupportedCRS>urn:ogc:def:crs:'.$srs[0].'::'.$srs[1].'</ows:SupportedCRS>'; <ows:SupportedCRS>urn:ogc:def:crs:'.$srs[0].'::'.$srs[1].'</ows:SupportedCRS>';
// $TileMatrixSet .= '<WellKnownScaleSet>urn:ogc:def:wkss:OGC:1.0:GoogleMapsCompatible</WellKnownScaleSet>'; // <WellKnownScaleSet>urn:ogc:def:wkss:OGC:1.0:GoogleMapsCompatible</WellKnownScaleSet>;
for($i = 0; $i <= sizeof($scales); $i++){ foreach($tileMatrixSet as $level){
$matrixWidth = pow(2, $i);
$TileMatrixSet .= ' $TileMatrixSet .= '
<TileMatrix> <TileMatrix>
<ows:Identifier>' . $i . '</ows:Identifier> <ows:Identifier>' . $level['id'] . '</ows:Identifier>
<ScaleDenominator>' . $scales[$i] . '</ScaleDenominator> <ScaleDenominator>' . $level['scale_denominator'] . '</ScaleDenominator>
<TopLeftCorner>'. $extent[0] . ' ' . $extent[3] .'</TopLeftCorner> <TopLeftCorner>'. $level['origin'][0] . ' ' . $level['origin'][1] .'</TopLeftCorner>
<TileWidth>' . $tilesize[0] . '</TileWidth> <TileWidth>' . $level['tile_size'][0] . '</TileWidth>
<TileHeight>' . $tilesize[1] . '</TileHeight> <TileHeight>' . $level['tile_size'][1] . '</TileHeight>
<MatrixWidth>' . $matrixWidth * $matrixRatio[0] . '</MatrixWidth> <MatrixWidth>' . $level['matrix_size'][0] . '</MatrixWidth>
<MatrixHeight>' . $matrixWidth * $matrixRatio[1] . '</MatrixHeight> <MatrixHeight>' . $level['matrix_size'][1] . '</MatrixHeight>
</TileMatrix>'; </TileMatrix>';
} }
$TileMatrixSet .= '</TileMatrixSet>'; $TileMatrixSet .= '</TileMatrixSet>';
@@ -916,11 +951,14 @@ class Wmts extends Server {
if ($profile == 'geodetic') { if ($profile == 'geodetic') {
$tileMatrixSet = "WGS84"; $tileMatrixSet = "WGS84";
}elseif ($m['profile'] == 'custom') { }elseif ($m['profile'] == 'custom') {
//TODO: Each custom neads each tileset BUG!!
$crs = explode(':', $m['crs']); $crs = explode(':', $m['crs']);
$tileMatrixSet = 'custom' . $crs[1]; $tileMatrixSet = 'custom' . $crs[1];
$customtileMatrixSets .= $this->getTileMatrixSet($tileMatrixSet, $m['scales'], $m['bounds'], $m['crs']); $customtileMatrixSets .= $this->getTileMatrixSet(
$tileMatrixSet,
$m['tile_matrix'],
$m['crs']
);
} else { } else {
$tileMatrixSet = "GoogleMapsCompatible"; $tileMatrixSet = "GoogleMapsCompatible";
@@ -952,29 +990,18 @@ class Wmts extends Server {
<ResourceURL format="' . $mime . '" resourceType="tile" template="' . $resourceUrlTemplate . '"/> <ResourceURL format="' . $mime . '" resourceType="tile" template="' . $resourceUrlTemplate . '"/>
</Layer>'; </Layer>';
} }
// Print PseudoMercator TileMatrixSet // Print PseudoMercator TileMatrixSet
echo $this->getMercatorTileMatrixSet(); echo $this->getMercatorTileMatrixSet();
//Print wgs84 TileMatrixSet // Print WGS84 TileMatrixSet
$matrixExtent = array(-180.000000, -90.000000, 180.000000, 90.000000); echo $this->getWGS84TileMatrixSet();
$scales = array(279541132.01435887813568115234, 139770566.00717943906784057617,
69885283.00358971953392028809, 34942641.50179485976696014404, 17471320.75089742988348007202,
8735660.37544871494174003601, 4367830.18772435747087001801, 2183915.09386217873543500900,
1091957.54693108936771750450, 545978.77346554468385875225, 272989.38673277234192937613,
136494.69336638617096468806, 68247.34668319308548234403, 34123.67334159654274117202,
17061.83667079825318069197, 8530.91833539912659034599, 4265.45916769956329517299,
2132.72958384978574031265);
$crs = 'EPSG::4326';
$matrixRatio = array(2, 1);
echo $this->getTileMatrixSet($tileMatrixSet, $scales, $matrixExtent, $crs, $matrixRatio); // Print custom TileMatrixSets
//Print custom TileMatrixSet
if (strlen($customtileMatrixSets) > 0) { if (strlen($customtileMatrixSets) > 0) {
echo $customtileMatrixSets; echo $customtileMatrixSets;
} }
echo '</Contents> echo '</Contents>
<ServiceMetadataURL xlink:href="' . $this->config['protocol'] . '://' . $this->config['baseUrls'][0] . '/wmts/1.0.0/WMTSCapabilities.xml"/> <ServiceMetadataURL xlink:href="' . $this->config['protocol'] . '://' . $this->config['baseUrls'][0] . '/wmts/1.0.0/WMTSCapabilities.xml"/>
</Capabilities>'; </Capabilities>';