diff options
Diffstat (limited to 'web/js')
-rw-r--r-- | web/js/OpenLayers.Projection.CH1903Plus.js (renamed from web/js/OpenLayers.Projection.CH1903.js) | 42 | ||||
-rw-r--r-- | web/js/map-wmts-base.js | 56 | ||||
-rw-r--r-- | web/js/map-wmts-bristol.js | 47 | ||||
-rw-r--r-- | web/js/map-wmts-zurich.js | 313 |
4 files changed, 203 insertions, 255 deletions
diff --git a/web/js/OpenLayers.Projection.CH1903.js b/web/js/OpenLayers.Projection.CH1903Plus.js index 34a0500fa..6cb888bf5 100644 --- a/web/js/OpenLayers.Projection.CH1903.js +++ b/web/js/OpenLayers.Projection.CH1903Plus.js @@ -1,14 +1,20 @@ /** - * OpenLayers Swiss (CH1903) grid projection transformations + * OpenLayers Swiss (CH1903+/LV95) grid projection transformations * - * Provides transform functions for WGS84<->CH1903 projections. + * Provides transform functions for WGS84<->CH1903+ projections. * * Maths courtesy of the Swiss Federal Office of Topography: * http://www.swisstopo.admin.ch/internet/swisstopo/en/home/products/software/products/skripts.html * Simplifed a bit, and with x/y swapped the normal way round. */ -OpenLayers.Projection.CH1903 = { +// Use the same calcs as CH1903 but with offset. +// Maximum distortion is 3M which should be sufficient for our purposes. +var LV95_X_OFFSET = 2000000; +var LV95_Y_OFFSET = 1000000; + + +OpenLayers.Projection.CH1903Plus = { // Convert WGS lat/long (° dec) to CH x WGStoCHx: function(lat, lng) { @@ -22,7 +28,7 @@ OpenLayers.Projection.CH1903 = { var lng_aux = (lng - 26782.5) / 10000; // Process X - var x = 600072.37; + var x = 600072.37 + LV95_X_OFFSET; x = x + (211455.93 * lng_aux); x = x - (10938.51 * lng_aux * lat_aux); x = x - (0.36 * lng_aux * Math.pow(lat_aux, 2)); @@ -43,7 +49,7 @@ OpenLayers.Projection.CH1903 = { var lng_aux = (lng - 26782.5)/10000; // Process Y - var y = 200147.07; + var y = 200147.07 + LV95_Y_OFFSET; y = y + (308807.95 * lat_aux); y = y + (3745.25 * Math.pow(lng_aux, 2)); y = y + (76.63 * Math.pow(lat_aux, 2)); @@ -59,8 +65,8 @@ OpenLayers.Projection.CH1903 = { // Converts militar to civil and to unit = 1000km // Axiliary values (% Bern) - var x_aux = (x - 600000) / 1000000; - var y_aux = (y - 200000) / 1000000; + var x_aux = (x - 600000 - LV95_X_OFFSET) / 1000000; + var y_aux = (y - 200000 - LV95_Y_OFFSET) / 1000000; // Process lat var lat = 16.9023892; @@ -82,8 +88,8 @@ OpenLayers.Projection.CH1903 = { // Converts militar to civil and to unit = 1000km // Axiliary values (% Bern) - var x_aux = (x - 600000) / 1000000; - var y_aux = (y - 200000) / 1000000; + var x_aux = (x - 600000 - LV95_X_OFFSET) / 1000000; + var y_aux = (y - 200000 - LV95_Y_OFFSET) / 1000000; // Process long var lng = 2.6779094; @@ -101,8 +107,8 @@ OpenLayers.Projection.CH1903 = { // Function to convert a WGS84 coordinate to a Swiss coordinate. projectForwardSwiss: function(point) { - var x = OpenLayers.Projection.CH1903.WGStoCHx(point.y, point.x), - y = OpenLayers.Projection.CH1903.WGStoCHy(point.y, point.x); + var x = OpenLayers.Projection.CH1903Plus.WGStoCHx(point.y, point.x), + y = OpenLayers.Projection.CH1903Plus.WGStoCHy(point.y, point.x); point.x = x; point.y = y; return point; @@ -110,8 +116,8 @@ OpenLayers.Projection.CH1903 = { // Function to convert a Swiss coordinate to a WGS84 coordinate. projectInverseSwiss: function(point) { - var lon = OpenLayers.Projection.CH1903.chToWGSlng(point.x, point.y); - var lat = OpenLayers.Projection.CH1903.chToWGSlat(point.x, point.y); + var lon = OpenLayers.Projection.CH1903Plus.chToWGSlng(point.x, point.y); + var lat = OpenLayers.Projection.CH1903Plus.chToWGSlat(point.x, point.y); point.x = lon; point.y = lat; return point; @@ -120,9 +126,9 @@ OpenLayers.Projection.CH1903 = { /** * Note: One transform declared - * Transforms from EPSG:4326 to EPSG:21781 + * Transforms from EPSG:4326 to EPSG:2056 */ - OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:21781", - OpenLayers.Projection.CH1903.projectForwardSwiss); - OpenLayers.Projection.addTransform("EPSG:21781", "EPSG:4326", - OpenLayers.Projection.CH1903.projectInverseSwiss); + OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:2056", + OpenLayers.Projection.CH1903Plus.projectForwardSwiss); + OpenLayers.Projection.addTransform("EPSG:2056", "EPSG:4326", + OpenLayers.Projection.CH1903Plus.projectInverseSwiss); diff --git a/web/js/map-wmts-base.js b/web/js/map-wmts-base.js new file mode 100644 index 000000000..c60afe4e1 --- /dev/null +++ b/web/js/map-wmts-base.js @@ -0,0 +1,56 @@ +// Functionality required by all OpenLayers WMTS base maps + +function setup_wmts_base_map() { + fixmystreet.map_type = OpenLayers.Layer.WMTS; + + // Set DPI - default is 72 + OpenLayers.DOTS_PER_INCH = fixmystreet.wmts_config.tile_dpi; + + fixmystreet.map_options = { + maxExtent: layer_bounds, + units: 'm', + scales: fixmystreet.wmts_config.scales + }; + + fixmystreet.layer_options = []; + fixmystreet.wmts_config.layer_names.forEach(function(v, i) { + fixmystreet.layer_options.push({ + projection: new OpenLayers.Projection(fixmystreet.wmts_config.map_projection), + name: fixmystreet.wmts_config.layer_names[i], + layer: fixmystreet.wmts_config.layer_names[i], + formatSuffix: fixmystreet.wmts_config.tile_suffix.replace(".", ""), + matrixSet: fixmystreet.wmts_config.matrix_set, + requestEncoding: "REST", + url: fixmystreet.wmts_config.tile_urls[i], + style: fixmystreet.wmts_config.layer_style, + matrixIds: matrix_ids, + tileOrigin: new OpenLayers.LonLat(fixmystreet.wmts_config.origin_x, fixmystreet.wmts_config.origin_y) + }); + }); + + // Give main code a new bbox_strategy that translates between + // lat/lon and our WMTS layer's coordinates + fixmystreet.bbox_strategy = new OpenLayers.Strategy.ReprojectBBOX({ + ratio: 1 + }); +} + +OpenLayers.Strategy.ReprojectBBOX = OpenLayers.Class(OpenLayers.Strategy.BBOX, { + getMapBounds: function() { + // Get the map bounds but return them in lat/lon, not + // local coordinates + if (this.layer.map === null) { + return null; + } + + var localBounds = this.layer.map.getExtent(); + // Transform bound corners into WGS84 + localBounds.transform( new OpenLayers.Projection(fixmystreet.wmts_config.map_projection), new OpenLayers.Projection("EPSG:4326") ); + return localBounds; + }, + + CLASS_NAME: "OpenLayers.Strategy.ReprojectBBOX" +}); + + +//
\ No newline at end of file diff --git a/web/js/map-wmts-bristol.js b/web/js/map-wmts-bristol.js index a1889beed..0fb664d76 100644 --- a/web/js/map-wmts-bristol.js +++ b/web/js/map-wmts-bristol.js @@ -118,53 +118,10 @@ var matrix_ids = [ if ( fixmystreet.page == 'report' ) { fixmystreet.controls.push( new OpenLayers.Control.PermalinkFMS('key-tool-problems-nearby', '/around') ); } - - fixmystreet.map_type = OpenLayers.Layer.WMTS; - - // Set DPI - default is 72 - OpenLayers.DOTS_PER_INCH = fixmystreet.wmts_config.tile_dpi; - - fixmystreet.map_options = { - maxExtent: layer_bounds, - units: 'm', - scales: fixmystreet.wmts_config.scales - }; - - fixmystreet.layer_options = [{ - projection: new OpenLayers.Projection(fixmystreet.wmts_config.map_projection), - name: fixmystreet.wmts_config.layer_name, - layer: fixmystreet.wmts_config.layer_name, - formatSuffix: fixmystreet.wmts_config.tile_suffix.replace(".", ""), - matrixSet: fixmystreet.wmts_config.matrix_set, - requestEncoding: "REST", - url: fixmystreet.wmts_config.tile_url, - style: fixmystreet.wmts_config.layer_style, - matrixIds: matrix_ids, - tileOrigin: new OpenLayers.LonLat(fixmystreet.wmts_config.origin_x, fixmystreet.wmts_config.origin_y) - }]; - - // Give main code a new bbox_strategy that translates between - // lat/lon and our WMTS layer's coordinates - fixmystreet.bbox_strategy = new OpenLayers.Strategy.ReprojectBBOX({ratio: 1}); + + setup_wmts_base_map(); } -OpenLayers.Strategy.ReprojectBBOX = OpenLayers.Class(OpenLayers.Strategy.BBOX, { - getMapBounds: function() { - // Get the map bounds but return them in lat/lon, not - // local coordinates - if (this.layer.map === null) { - return null; - } - - var localBounds = this.layer.map.getExtent(); - // Transform bound corners into WGS84 - localBounds.transform( new OpenLayers.Projection(fixmystreet.wmts_config.map_projection), new OpenLayers.Projection("EPSG:4326") ); - return localBounds; - }, - - CLASS_NAME: "OpenLayers.Strategy.ReprojectBBOX" -}); - function fms_marker_size_for_zoom(zoom) { if (zoom >= 7) { return 'normal'; diff --git a/web/js/map-wmts-zurich.js b/web/js/map-wmts-zurich.js index 9e0555079..aa673f52d 100644 --- a/web/js/map-wmts-zurich.js +++ b/web/js/map-wmts-zurich.js @@ -2,6 +2,117 @@ * Maps for FMZ using Zurich council's WMTS tile server */ +// From 'fullExtent' from http://www.gis.stadt-zuerich.ch/maps/rest/services/tiled95/LuftbildHybrid/MapServer?f=pjson +var layer_bounds = new OpenLayers.Bounds( + 2676000.9069999997, // W + 1241399.842, // S + 2689900.9069999997, // E + 1254599.842); // N + +var matrix_ids = [ + // The two highest zoom levels are pretty much useless so they're disabled. + // { + // "matrixHeight": 882, + // "scaleDenominator": 241905.24571522293, + // "identifier": "0", + // "tileWidth": 512, + // "supportedCRS": "urn:ogc:def:crs:EPSG::2056", + // "tileHeight": 512, + // "matrixWidth": 868 + // }, + // { + // "matrixHeight": 1764, + // "scaleDenominator": 120952.62285761147, + // "identifier": "1", + // "tileWidth": 512, + // "supportedCRS": "urn:ogc:def:crs:EPSG::2056", + // "tileHeight": 512, + // "matrixWidth": 1735 + // }, + + { + "matrixHeight": 3527, + "scaleDenominator": 60476.31142880573, + "identifier": "2", + "tileWidth": 512, + "supportedCRS": "urn:ogc:def:crs:EPSG::2056", + "tileHeight": 512, + "matrixWidth": 3470 + }, + { + "matrixHeight": 7053, + "scaleDenominator": 30238.155714402867, + "identifier": "3", + "tileWidth": 512, + "supportedCRS": "urn:ogc:def:crs:EPSG::2056", + "tileHeight": 512, + "matrixWidth": 6939 + }, + { + "matrixHeight": 14106, + "scaleDenominator": 15119.077857201433, + "identifier": "4", + "tileWidth": 512, + "supportedCRS": "urn:ogc:def:crs:EPSG::2056", + "tileHeight": 512, + "matrixWidth": 13877 + }, + { + "matrixHeight": 28211, + "scaleDenominator": 7559.538928600717, + "identifier": "5", + "tileWidth": 512, + "supportedCRS": "urn:ogc:def:crs:EPSG::2056", + "tileHeight": 512, + "matrixWidth": 27753 + }, + { + "matrixHeight": 56422, + "scaleDenominator": 3779.7694643003583, + "identifier": "6", + "tileWidth": 512, + "supportedCRS": "urn:ogc:def:crs:EPSG::2056", + "tileHeight": 512, + "matrixWidth": 55505 + }, + { + "matrixHeight": 112844, + "scaleDenominator": 1889.8847321501792, + "identifier": "7", + "tileWidth": 512, + "supportedCRS": "urn:ogc:def:crs:EPSG::2056", + "tileHeight": 512, + "matrixWidth": 111010 + }, + { + "matrixHeight": 225687, + "scaleDenominator": 944.9423660750896, + "identifier": "8", + "tileWidth": 512, + "supportedCRS": "urn:ogc:def:crs:EPSG::2056", + "tileHeight": 512, + "matrixWidth": 222020 + }, + { + "matrixHeight": 451374, + "scaleDenominator": 472.4711830375448, + "identifier": "9", + "tileWidth": 512, + "supportedCRS": "urn:ogc:def:crs:EPSG::2056", + "tileHeight": 512, + "matrixWidth": 444039 + }, + { + "matrixHeight": 902748, + "scaleDenominator": 236.2355915187724, + "identifier": "10", + "tileWidth": 512, + "supportedCRS": "urn:ogc:def:crs:EPSG::2056", + "tileHeight": 512, + "matrixWidth": 888078 + } +]; + function fixmystreet_zurich_admin_drag() { var admin_drag = new OpenLayers.Control.DragFeature( fixmystreet.markers, { onComplete: function(feature, e) { @@ -69,199 +180,17 @@ $(function(){ fixmystreet.controls.push( new OpenLayers.Control.PermalinkFMS('key-tool-problems-nearby', '/around') ); } - fixmystreet.map_type = OpenLayers.Layer.WMTS; - - // Set DPI - default is 72 - OpenLayers.DOTS_PER_INCH = 96; - - fixmystreet.map_options = { - maxExtent: new OpenLayers.Bounds(676000, 241402, 689896, 254596), - units: 'm', - scales: [ '64000', '32000', '16000', '8000', '4000', '2000', '1000', '500', '250' ] - }; - - var layer_options = { - projection: new OpenLayers.Projection("EPSG:21781"), - name: "tiled_LuftbildHybrid", - layer: "tiled_LuftbildHybrid", - matrixSet: "default028mm", - requestEncoding: "REST", - url: "//www.gis.stadt-zuerich.ch/maps/rest/services/tiled/LuftbildHybrid/MapServer/WMTS/tile/", - style: "default", - matrixIds: [ - // { - // "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: "Stadtplan3D", - layer: "Stadtplan3D", - url: "//www.gis.stadt-zuerich.ch/maps/rest/services/tiled/Stadtplan3D/MapServer/WMTS/tile/" - }, layer_options) - ]; - - // Give main code a new bbox_strategy that translates between - // lat/lon and our swiss coordinates - fixmystreet.bbox_strategy = new OpenLayers.Strategy.ZurichBBOX({ratio: 1}); + setup_wmts_base_map(); fixmystreet.area_format = { fillColor: 'none', strokeWidth: 4, strokeColor: 'black' }; } -OpenLayers.Strategy.ZurichBBOX = OpenLayers.Class(OpenLayers.Strategy.BBOX, { - getMapBounds: function() { - // Get the map bounds but return them in lat/lon, not - // Swiss coordinates - if (this.layer.map === null) { - return null; - } - - var swissBounds = this.layer.map.getExtent(); - // Transform bound corners into WGS84 - swissBounds.transform( new OpenLayers.Projection("EPSG:21781"), new OpenLayers.Projection("EPSG:4326") ); - return swissBounds; - }, - - CLASS_NAME: "OpenLayers.Strategy.ZurichBBOX" -}); +function fms_marker_size_for_zoom(zoom) { + if (zoom >= 6) { + return 'normal'; + } else if (zoom >= 3) { + return 'small'; + } else { + return 'mini'; + } +} |