diff options
author | Matthew Somerville <matthew@mysociety.org> | 2012-11-26 17:06:17 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2012-11-26 17:06:17 +0000 |
commit | 31667efeb9957169ffd5ecf27333dc680bab379c (patch) | |
tree | 5825ed495bea9be1cf37b2d6097aed58d83b136c /web/js | |
parent | 84d6ec9717c8e737dfdee0f04272a4cd955daae2 (diff) |
Write out layer explicitly so no AJAX request necessary and deal with all OL options the same.
Diffstat (limited to 'web/js')
-rw-r--r-- | web/js/map-OpenLayers.js | 76 | ||||
-rw-r--r-- | web/js/map-wmts-zurich.js | 88 |
2 files changed, 57 insertions, 107 deletions
diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index 8506f8076..85ab09889 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -254,56 +254,42 @@ $(function(){ // template should define this set_map_config(); - // If the aforementioned js defined it's own setup method - // call that instead of setting the map up ourselves - if(typeof fixmystreet.map_setup !== "undefined") { - fixmystreet.map_setup(function () { - // TODO - can this go inside afterMapInit() so it's not duped? - if ($('html').hasClass('mobile') && fixmystreet.page == 'around') { - $('#fms_pan_zoom').css({ top: '2.75em !important' }); - } - afterMapInit(); - }); + // Create the basics of the map + fixmystreet.map = new OpenLayers.Map( + "map", OpenLayers.Util.extend({ + controls: fixmystreet.controls, + displayProjection: new OpenLayers.Projection("EPSG:4326") + }, fixmystreet.map_options) + ); + + if ($('html').hasClass('mobile') && fixmystreet.page == 'around') { + $('#fms_pan_zoom').css({ top: '2.75em !important' }); } - else { - // TODO - can this go inside afterMapInit() so it's not duped? - if ($('html').hasClass('mobile') && fixmystreet.page == 'around') { - $('#fms_pan_zoom').css({ top: '2.75em !important' }); - } - // Create the basics of the map - fixmystreet.map = new OpenLayers.Map("map", { - controls: fixmystreet.controls, - displayProjection: new OpenLayers.Projection("EPSG:4326") - } - ); + // Set it up our way + fixmystreet.layer_options = OpenLayers.Util.extend({ + zoomOffset: fixmystreet.zoomOffset, + transitionEffect: 'resize', + numZoomLevels: fixmystreet.numZoomLevels + }, fixmystreet.layer_options); - // Set it up our way - fixmystreet.layer_options = OpenLayers.Util.extend({ - zoomOffset: fixmystreet.zoomOffset, - transitionEffect: 'resize', - numZoomLevels: fixmystreet.numZoomLevels - }, fixmystreet.layer_options); - var layer = new fixmystreet.map_type("", fixmystreet.layer_options); - fixmystreet.map.addLayer(layer); - - if (!fixmystreet.map.getCenter()) { - var centre = new OpenLayers.LonLat( fixmystreet.longitude, fixmystreet.latitude ); - centre.transform( - new OpenLayers.Projection("EPSG:4326"), - fixmystreet.map.getProjectionObject() - ); - fixmystreet.map.setCenter(centre, fixmystreet.zoom || 3); - } + var layer; + if (fixmystreet.layer_options.matrixIds) { + layer = new fixmystreet.map_type(fixmystreet.layer_options); + } else { + layer = new fixmystreet.map_type("", fixmystreet.layer_options); + } + fixmystreet.map.addLayer(layer); - // Do the stuff we need to do after the map has - // been created - afterMapInit(); + if (!fixmystreet.map.getCenter()) { + var centre = new OpenLayers.LonLat( fixmystreet.longitude, fixmystreet.latitude ); + centre.transform( + new OpenLayers.Projection("EPSG:4326"), + fixmystreet.map.getProjectionObject() + ); + fixmystreet.map.setCenter(centre, fixmystreet.zoom || 3); } -}); -// Stuff to do after the map has been created -function afterMapInit() { if (fixmystreet.state_map && fixmystreet.state_map == 'full') { // TODO Work better with window resizing, this is pretty 'set up' only at present var $content = $('.content'), mb = $('#map_box'), @@ -373,7 +359,7 @@ function afterMapInit() { } else { fixmystreet_onload(); } -} +}); /* Overridding the buttonDown function of PanZoom so that it does zoomTo(0) rather than zoomToMaxExtent() diff --git a/web/js/map-wmts-zurich.js b/web/js/map-wmts-zurich.js index 55f6f9dd2..2e132ba0e 100644 --- a/web/js/map-wmts-zurich.js +++ b/web/js/map-wmts-zurich.js @@ -2,65 +2,6 @@ * Maps for FMZ using Zurich council's WMTS tile server */ - /* - * Copied from Mark/Matthew's demo of using Zurich's layers - * and merged with things that js/map-OpenLayers.js does - */ -function init_zurich_map(after) { - - fixmystreet.map = new OpenLayers.Map('map', { - projection: new OpenLayers.Projection("EPSG:21781"), - displayProjection: new OpenLayers.Projection("EPSG:4326"), - maxExtent: new OpenLayers.Bounds(676000,241000,690000,255000), - units: 'm', - scales: [ '250000', '125000', '64000', '32000', '16000', '8000', '4000', '2000', '1000', '500'], - controls: fixmystreet.controls - }); - - var format = new OpenLayers.Format.WMTSCapabilities(); - - jQuery.support.cors = true; - - jQuery.get("cobrands/zurich/Zurich-WMTSCapabilities.xml", - '', - function (data, textStatus, jqXHR) { - - var layer, centre; - var capabilities = format.read(data); - - layer = format.createLayer(capabilities, { - // Mark/Matthew's - layer: "Luftbild", - matrixSet: "default028mm", - //matrixSet: "nativeTileMatrixSet", - requestEncoding: "REST", - isBaseLayer: true, - // Things from the original map-OpenLayers.js - zoomOffset: fixmystreet.zoomOffset, - transitionEffect: 'resize', - numZoomLevels: fixmystreet.numZoomLevels - - }); - // For some reason with OpenLayers 2.11 the format - // returns a KVP url not a REST one, despite the settings - // we have above, so for now I'm hardcoding the right one - layer.url = "http://www.wmts.stadt-zuerich.ch/Luftbild/MapServer/WMTS/tile/"; - - fixmystreet.map.addLayer(layer); - - centre = new OpenLayers.LonLat( fixmystreet.longitude, fixmystreet.latitude ); - centre.transform( - new OpenLayers.Projection("EPSG:4326"), - fixmystreet.map.getProjectionObject() - ); - fixmystreet.map.setCenter(centre, fixmystreet.zoom || 3); - - // Call the after callback - after(); - }, - 'xml'); -} - /* * set_map_config() is called on dom ready in map-OpenLayers.js * to setup the way the map should operate. @@ -91,9 +32,32 @@ function init_zurich_map(after) { // Set DPI - default is 72 OpenLayers.DOTS_PER_INCH = 96; - // tell the main code to run our function instead - // of setting the map up itself - fixmystreet.map_setup = init_zurich_map; + fixmystreet.map_options = { + projection: new OpenLayers.Projection("EPSG:21781"), + maxExtent: new OpenLayers.Bounds(676000, 241000, 690000, 255000), + units: 'm', + scales: [ '250000', '125000', '64000', '32000', '16000', '8000', '4000', '2000', '1000', '500'], + }; + + fixmystreet.layer_options = { + name: "Luftbild", + layer: "Luftbild", + matrixSet: "nativeTileMatrixSet", + requestEncoding: "REST", + url: "http://www.wmts.stadt-zuerich.ch/Luftbild/MapServer/WMTS/tile/", + style: "default", + matrixIds: [ + { identifier: "0", matrixHeight: 3, matrixWidth: 3, scaleDenominator: 125000, supportedCRS: "urn:ogc:def:crs:EPSG::21781", tileHeight: 256, tileWidth: 256, topLeftCorner: { lat: 30814500, lon: -29386400 } }, + { identifier: "1", matrixHeight: 4, matrixWidth: 5, scaleDenominator: 64000, supportedCRS: "urn:ogc:def:crs:EPSG::21781", tileHeight: 256, tileWidth: 256, topLeftCorner: { lat: 30814500, lon: -29386400 } }, + { identifier: "2", matrixHeight: 7, matrixWidth: 8, scaleDenominator: 32000, supportedCRS: "urn:ogc:def:crs:EPSG::21781", tileHeight: 256, tileWidth: 256, topLeftCorner: { lat: 30814500, lon: -29386400 } }, + { identifier: "3", matrixHeight: 14, matrixWidth: 14, scaleDenominator: 16000, supportedCRS: "urn:ogc:def:crs:EPSG::21781", tileHeight: 256, tileWidth: 256, topLeftCorner: { lat: 30814500, lon: -29386400 } }, + { identifier: "4", matrixHeight: 27, matrixWidth: 27, scaleDenominator: 8000, supportedCRS: "urn:ogc:def:crs:EPSG::21781", tileHeight: 256, tileWidth: 256, topLeftCorner: { lat: 30814500, lon: -29386400 } }, + { identifier: "5", matrixHeight: 52, matrixWidth: 53, scaleDenominator: 4000, supportedCRS: "urn:ogc:def:crs:EPSG::21781", tileHeight: 256, tileWidth: 256, topLeftCorner: { lat: 30814500, lon: -29386400 } }, + { identifier: "6", matrixHeight: 104, matrixWidth: 105, scaleDenominator: 2000, supportedCRS: "urn:ogc:def:crs:EPSG::21781", tileHeight: 256, tileWidth: 256, topLeftCorner: { lat: 30814500, lon: -29386400 } }, + { identifier: "7", matrixHeight: 208, matrixWidth: 208, scaleDenominator: 1000, supportedCRS: "urn:ogc:def:crs:EPSG::21781", tileHeight: 256, tileWidth: 256, topLeftCorner: { lat: 30814500, lon: -29386400 } }, + { identifier: "8", matrixHeight: 415, matrixWidth: 414, scaleDenominator: 500, supportedCRS: "urn:ogc:def:crs:EPSG::21781", tileHeight: 256, tileWidth: 256, topLeftCorner: { lat: 30814500, lon: -29386400 } } + ] + }; // Give main code a new bbox_strategy that translates between // lat/lon and our swiss coordinates |