From 032db2fbb6bd2bf0cf0cf2daa379610ab319a6a8 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Mon, 6 Oct 2014 15:47:21 +0000 Subject: Support Stamen toner-lite and Bing Maps tiles. --- web/js/map-fms.js | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 web/js/map-fms.js (limited to 'web/js/map-fms.js') diff --git a/web/js/map-fms.js b/web/js/map-fms.js new file mode 100644 index 000000000..1c08bd251 --- /dev/null +++ b/web/js/map-fms.js @@ -0,0 +1,74 @@ +var fms_tile_base = [ [ '', 'a-', 'b-', 'c-' ], '//{S}tilma.mysociety.org/sv' ]; + +function set_map_config(perm) { + _set_map_config(); + + if (fixmystreet.map_type) { + fms_tile_base = fixmystreet.map_type; + } + fixmystreet.map_type = OpenLayers.Layer.BingUK; +} + +OpenLayers.Layer.BingUK = OpenLayers.Class(OpenLayers.Layer.Bing, { + uk_bounds: [ + new OpenLayers.Bounds(-6.6, 49.8, 1.102680, 51), + new OpenLayers.Bounds(-5.4, 51, 2.28, 54.94), + new OpenLayers.Bounds(-5.85, 54.94, -1.15, 55.33), + new OpenLayers.Bounds(-9.35, 55.33, -0.7, 60.98) + ], + + in_uk: function(c) { + c = c.clone(); + c.transform( + fixmystreet.map.getProjectionObject(), + new OpenLayers.Projection("EPSG:4326") + ); + if ( this.uk_bounds[0].contains(c.lon, c.lat) || this.uk_bounds[1].contains(c.lon, c.lat) || this.uk_bounds[2].contains(c.lon, c.lat) || this.uk_bounds[3].contains(c.lon, c.lat) ) { + return true; + } + return false; + }, + + setMap: function() { + OpenLayers.Layer.Bing.prototype.setMap.apply(this, arguments); + this.map.events.register("moveend", this, this.updateAttribution); + }, + + updateAttribution: function() { + var z = this.map.getZoom() + this.zoomOffset; + var copyrights; + var logo = ''; + var c = this.map.getCenter(); + var in_uk = c ? this.in_uk(c) : true; + if (z >= 16 && in_uk) { + copyrights = 'Contains Ordnance Survey data © Crown copyright and database right 2014'; + } else { + logo = ''; + copyrights = '© 2011 Microsoft. © AND, Navteq, Ordnance Survey'; + } + this._updateAttribution(copyrights, logo); + }, + + get_urls: function(bounds, z) { + var urls; + var in_uk = this.in_uk(bounds.getCenterLonLat()); + if (z >= 16 && in_uk) { + urls = []; + for (var i=0; i< fms_tile_base[0].length; i++) { + urls.push( fms_tile_base[1].replace('{S}', fms_tile_base[0][i]) + "/${z}/${x}/${y}.png" ); + } + } else { + var type = ''; + if (z > 10 && in_uk) { type = '&productSet=mmOS'; } + urls = [ + "//ecn.t0.tiles.virtualearth.net/tiles/r${id}.png?g=3293" + type, + "//ecn.t1.tiles.virtualearth.net/tiles/r${id}.png?g=3293" + type, + "//ecn.t2.tiles.virtualearth.net/tiles/r${id}.png?g=3293" + type, + "//ecn.t3.tiles.virtualearth.net/tiles/r${id}.png?g=3293" + type + ]; + } + return urls; + }, + + CLASS_NAME: "OpenLayers.Layer.BingUK" +}); -- cgit v1.2.3