diff options
author | Matthew Somerville <matthew@mysociety.org> | 2012-07-19 13:56:44 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2012-07-20 14:01:18 +0100 |
commit | 6286c0a7b148f3758488b354764aeb6efcbea22b (patch) | |
tree | acd02e7f8cb929dcacc461b332a1afc757ff5588 /web/js/map-bing-ol.js | |
parent | de0ecd612977259c721621917044357796a670d7 (diff) |
Improve map tile handling outside Great Britain.
Diffstat (limited to 'web/js/map-bing-ol.js')
-rw-r--r-- | web/js/map-bing-ol.js | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/web/js/map-bing-ol.js b/web/js/map-bing-ol.js index 7d40f8afc..6f9916229 100644 --- a/web/js/map-bing-ol.js +++ b/web/js/map-bing-ol.js @@ -22,12 +22,30 @@ function set_map_config(perm) { if (fixmystreet.map_type) { tile_base = fixmystreet.map_type; } - fixmystreet.map_type = OpenLayers.Layer.Bing; + fixmystreet.map_type = OpenLayers.Layer.BingUK; } -OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, { +OpenLayers.Layer.BingUK = OpenLayers.Class(OpenLayers.Layer.XYZ, { attributionTemplate: '${logo}${copyrights}', + 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.XYZ.prototype.setMap.apply(this, arguments); this.updateAttribution(); @@ -98,14 +116,15 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, { this.map.getZoom() + this.zoomOffset; var url; - if (z >= 16) { + var in_uk = this.in_uk(bounds.getCenterLonLat()); + if (z >= 16 && in_uk) { url = []; for (var i=0; i< tile_base[0].length; i++) { url.push( tile_base[1].replace('{S}', tile_base[0][i]) + "/${z}/${x}/${y}.png" ); } } else { var type = ''; - if (z > 10) { type = '&productSet=mmOS'; } + if (z > 10 && in_uk) { type = '&productSet=mmOS'; } url = [ "//ecn.t0.tiles.virtualearth.net/tiles/r${id}.png?g=701" + type, "//ecn.t1.tiles.virtualearth.net/tiles/r${id}.png?g=701" + type, @@ -121,5 +140,5 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, { return path; }, - CLASS_NAME: "OpenLayers.Layer.Bing" + CLASS_NAME: "OpenLayers.Layer.BingUK" }); |