diff options
author | Dave Arter <davea@mysociety.org> | 2015-02-13 12:43:25 +0000 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2015-10-06 09:09:22 +0100 |
commit | e572afecd7fcd294cb56ce44015ef9112ca8e870 (patch) | |
tree | da1ad238dd796fc4c6100ca46dcd1a1099f6180d | |
parent | 1c4f12860c2aee9e9fa3063969c3d995dda1871f (diff) |
[Zurich] Use new map tiles up to 1:250
- Refactor map tile size into a constant
- Update map tiles to use new Zurich WMTS server directly instead of Apache proxy
-rw-r--r-- | perllib/FixMyStreet/Map/Zurich.pm | 25 | ||||
-rw-r--r-- | web/js/map-wmts-zurich.js | 171 |
2 files changed, 164 insertions, 32 deletions
diff --git a/perllib/FixMyStreet/Map/Zurich.pm b/perllib/FixMyStreet/Map/Zurich.pm index 9b01f2978..04fd596d1 100644 --- a/perllib/FixMyStreet/Map/Zurich.pm +++ b/perllib/FixMyStreet/Map/Zurich.pm @@ -11,10 +11,11 @@ use Geo::Coordinates::CH1903; use Math::Trig; use Utils; -use constant ZOOM_LEVELS => 8; +use constant ZOOM_LEVELS => 9; use constant DEFAULT_ZOOM => 5; use constant MIN_ZOOM_LEVEL => 0; use constant ID_OFFSET => 2; +use constant TILE_SIZE => 256; sub map_tiles { my ( $self, %params ) = @_; @@ -83,13 +84,12 @@ sub latlon_to_tile($$$) { my ($x, $y) = Geo::Coordinates::CH1903::from_latlon($lat, $lon); my $matrix_id = $zoom + ID_OFFSET; - my @scales = ( '250000', '125000', '64000', '32000', '16000', '8000', '4000', '2000', '1000', '500' ); + my @scales = ( '250000', '125000', '64000', '32000', '16000', '8000', '4000', '2000', '1000', '500', '250' ); my $tileOrigin = { lat => 30814423, lon => -29386322 }; - my $tileSize = 256; my $res = $scales[$matrix_id] / (39.3701 * 96); # OpenLayers.INCHES_PER_UNIT[units] * OpenLayers.DOTS_PER_INCH - my $fx = ( $x - $tileOrigin->{lon} ) / ($res * $tileSize); - my $fy = ( $tileOrigin->{lat} - $y ) / ($res * $tileSize); + my $fx = ( $x - $tileOrigin->{lon} ) / ($res * TILE_SIZE); + my $fy = ( $tileOrigin->{lat} - $y ) / ($res * TILE_SIZE); return ( $fx, $fy, $matrix_id ); } @@ -115,13 +115,12 @@ sub tile_to_latlon { my ($fx, $fy, $zoom) = @_; my $matrix_id = $zoom + ID_OFFSET; - my @scales = ( '250000', '125000', '64000', '32000', '16000', '8000', '4000', '2000', '1000', '500' ); + my @scales = ( '250000', '125000', '64000', '32000', '16000', '8000', '4000', '2000', '1000', '500', '250' ); my $tileOrigin = { lat => 30814423, lon => -29386322 }; - my $tileSize = 256; my $res = $scales[$matrix_id] / (39.3701 * 96); # OpenLayers.INCHES_PER_UNIT[units] * OpenLayers.DOTS_PER_INCH - my $x = $fx * $res * $tileSize + $tileOrigin->{lon}; - my $y = $tileOrigin->{lat} - $fy * $res * $tileSize; + my $x = $fx * $res * TILE_SIZE + $tileOrigin->{lon}; + my $y = $tileOrigin->{lat} - $fy * $res * TILE_SIZE; my ($lat, $lon) = Geo::Coordinates::CH1903::to_latlon($x, $y); @@ -141,16 +140,16 @@ sub latlon_to_px($$$$$) { # C is centre tile reference of displayed map sub tile_to_px { my ($p, $c) = @_; - $p = 256 * ($p - $c + 1); + $p = TILE_SIZE * ($p - $c + 1); $p = int($p + .5 * ($p <=> 0)); return $p; } sub click_to_tile { my ($pin_tile, $pin) = @_; - $pin -= 256 while $pin > 256; - $pin += 256 while $pin < 0; - return $pin_tile + $pin / 256; + $pin -= TILE_SIZE while $pin > TILE_SIZE; + $pin += TILE_SIZE while $pin < 0; + return $pin_tile + $pin / TILE_SIZE; } # Given some click co-ords (the tile they were on, and where in the diff --git a/web/js/map-wmts-zurich.js b/web/js/map-wmts-zurich.js index 54b932168..dc81c967f 100644 --- a/web/js/map-wmts-zurich.js +++ b/web/js/map-wmts-zurich.js @@ -81,37 +81,170 @@ $(function(){ OpenLayers.DOTS_PER_INCH = 96; fixmystreet.map_options = { - maxExtent: new OpenLayers.Bounds(676000, 241000, 690000, 255000), + maxExtent: new OpenLayers.Bounds(676000, 241402, 689896, 254596), units: 'm', - scales: [ '64000', '32000', '16000', '8000', '4000', '2000', '1000', '500' ] + scales: [ '64000', '32000', '16000', '8000', '4000', '2000', '1000', '500', '250' ] }; var layer_options = { projection: new OpenLayers.Projection("EPSG:21781"), - name: "Hybrid", - layer: "Hybrid", - matrixSet: "nativeTileMatrixSet", + name: "tiled_LuftbildHybrid", + layer: "tiled_LuftbildHybrid", + matrixSet: "default028mm", requestEncoding: "REST", - url: "/maps/Hybrid/", + url: "http://www.gis.stadt-zuerich.ch/maps/rest/services/tiled/LuftbildHybrid/MapServer/WMTS/tile/", style: "default", matrixIds: [ - //{ identifier: "0", matrixHeight: 2, matrixWidth: 2, scaleDenominator: 250000, supportedCRS: "urn:ogc:def:crs:EPSG::21781", tileHeight: 256, tileWidth: 256, topLeftCorner: { lat: 30814423, lon: -29386322 } }, - //{ identifier: "1", matrixHeight: 3, matrixWidth: 3, scaleDenominator: 125000, supportedCRS: "urn:ogc:def:crs:EPSG::21781", tileHeight: 256, tileWidth: 256, topLeftCorner: { lat: 30814423, lon: -29386322 } }, - { identifier: "2", matrixHeight: 4, matrixWidth: 5, scaleDenominator: 64000, supportedCRS: "urn:ogc:def:crs:EPSG::21781", tileHeight: 256, tileWidth: 256, topLeftCorner: { lat: 30814423, lon: -29386322 } }, - { identifier: "3", matrixHeight: 7, matrixWidth: 8, scaleDenominator: 32000, supportedCRS: "urn:ogc:def:crs:EPSG::21781", tileHeight: 256, tileWidth: 256, topLeftCorner: { lat: 30814423, lon: -29386322 } }, - { identifier: "4", matrixHeight: 14, matrixWidth: 14, scaleDenominator: 16000, supportedCRS: "urn:ogc:def:crs:EPSG::21781", tileHeight: 256, tileWidth: 256, topLeftCorner: { lat: 30814423, lon: -29386322 } }, - { identifier: "5", matrixHeight: 27, matrixWidth: 27, scaleDenominator: 8000, supportedCRS: "urn:ogc:def:crs:EPSG::21781", tileHeight: 256, tileWidth: 256, topLeftCorner: { lat: 30814423, lon: -29386322 } }, - { identifier: "6", matrixHeight: 52, matrixWidth: 53, scaleDenominator: 4000, supportedCRS: "urn:ogc:def:crs:EPSG::21781", tileHeight: 256, tileWidth: 256, topLeftCorner: { lat: 30814423, lon: -29386322 } }, - { identifier: "7", matrixHeight: 104, matrixWidth: 105, scaleDenominator: 2000, supportedCRS: "urn:ogc:def:crs:EPSG::21781", tileHeight: 256, tileWidth: 256, topLeftCorner: { lat: 30814423, lon: -29386322 } }, - { identifier: "8", matrixHeight: 208, matrixWidth: 208, scaleDenominator: 1000, supportedCRS: "urn:ogc:def:crs:EPSG::21781", tileHeight: 256, tileWidth: 256, topLeftCorner: { lat: 30814423, lon: -29386322 } }, - { identifier: "9", matrixHeight: 415, matrixWidth: 414, scaleDenominator: 500, supportedCRS: "urn:ogc:def:crs:EPSG::21781", tileHeight: 256, tileWidth: 256, topLeftCorner: { lat: 30814423, lon: -29386322 } } + // { + // "identifier": "0", + // "matrixHeight": 903, + // "matrixWidth": 889, + // "scaleDenominator": 236235.59151877242, + // "supportedCRS": "urn:ogc:def:crs:EPSG::21781", + // "tileHeight": 512, + // "tileWidth": 512, + // "topLeftCorner": { + // "lat": 30814423, + // "lon": -29386322 + // } + // }, + // { + // "identifier": "1", + // "matrixHeight": 1806, + // "matrixWidth": 1777, + // "scaleDenominator": 118117.79575938621, + // "supportedCRS": "urn:ogc:def:crs:EPSG::21781", + // "tileHeight": 512, + // "tileWidth": 512, + // "topLeftCorner": { + // "lat": 30814423, + // "lon": -29386322 + // } + // }, + { + "identifier": "2", + "matrixHeight": 3527, + "matrixWidth": 3470, + "scaleDenominator": 60476.31142880573, + "supportedCRS": "urn:ogc:def:crs:EPSG::21781", + "tileHeight": 512, + "tileWidth": 512, + "topLeftCorner": { + "lat": 30814423, + "lon": -29386322 + } + }, + { + "identifier": "3", + "matrixHeight": 7053, + "matrixWidth": 6939, + "scaleDenominator": 30238.155714402867, + "supportedCRS": "urn:ogc:def:crs:EPSG::21781", + "tileHeight": 512, + "tileWidth": 512, + "topLeftCorner": { + "lat": 30814423, + "lon": -29386322 + } + }, + { + "identifier": "4", + "matrixHeight": 14106, + "matrixWidth": 13877, + "scaleDenominator": 15119.077857201433, + "supportedCRS": "urn:ogc:def:crs:EPSG::21781", + "tileHeight": 512, + "tileWidth": 512, + "topLeftCorner": { + "lat": 30814423, + "lon": -29386322 + } + }, + { + "identifier": "5", + "matrixHeight": 28211, + "matrixWidth": 27753, + "scaleDenominator": 7559.538928600717, + "supportedCRS": "urn:ogc:def:crs:EPSG::21781", + "tileHeight": 512, + "tileWidth": 512, + "topLeftCorner": { + "lat": 30814423, + "lon": -29386322 + } + }, + { + "identifier": "6", + "matrixHeight": 56422, + "matrixWidth": 55505, + "scaleDenominator": 3779.7694643003583, + "supportedCRS": "urn:ogc:def:crs:EPSG::21781", + "tileHeight": 512, + "tileWidth": 512, + "topLeftCorner": { + "lat": 30814423, + "lon": -29386322 + } + }, + { + "identifier": "7", + "matrixHeight": 112844, + "matrixWidth": 111010, + "scaleDenominator": 1889.8847321501792, + "supportedCRS": "urn:ogc:def:crs:EPSG::21781", + "tileHeight": 512, + "tileWidth": 512, + "topLeftCorner": { + "lat": 30814423, + "lon": -29386322 + } + }, + { + "identifier": "8", + "matrixHeight": 225687, + "matrixWidth": 222020, + "scaleDenominator": 944.9423660750896, + "supportedCRS": "urn:ogc:def:crs:EPSG::21781", + "tileHeight": 512, + "tileWidth": 512, + "topLeftCorner": { + "lat": 30814423, + "lon": -29386322 + } + }, + { + "identifier": "9", + "matrixHeight": 451374, + "matrixWidth": 444039, + "scaleDenominator": 472.4711830375448, + "supportedCRS": "urn:ogc:def:crs:EPSG::21781", + "tileHeight": 512, + "tileWidth": 512, + "topLeftCorner": { + "lat": 30814423, + "lon": -29386322 + } + }, + { + "identifier": "10", + "matrixHeight": 902748, + "matrixWidth": 888078, + "scaleDenominator": 236.2355915187724, + "supportedCRS": "urn:ogc:def:crs:EPSG::21781", + "tileHeight": 512, + "tileWidth": 512, + "topLeftCorner": { + "lat": 30814423, + "lon": -29386322 + } + } ] }; fixmystreet.layer_options = [ layer_options, OpenLayers.Util.applyDefaults({ - name: "Stadtplan", - layer: "Stadtplan", - url: "/maps/Stadtplan/" + name: "Stadtplan3D", + layer: "Stadtplan3D", + url: "http://www.gis.stadt-zuerich.ch/maps/rest/services/tiled/Stadtplan3D/MapServer/WMTS/tile/" }, layer_options) ]; |