aboutsummaryrefslogtreecommitdiffstats
path: root/www/js/map-fms.js
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2016-04-26 14:59:01 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2016-04-26 14:59:01 +0100
commitd623b70d7273ad212074fa1e008c4e3ceb480fdf (patch)
tree9fabfd933c30507b941b0d7c4b6fdea43e02bbd6 /www/js/map-fms.js
parent59d3e77945bc069bd84f55a68adc6b3873baa7ac (diff)
Fix displaying of map tiles.cordova-6-fix-maps
This updates the map tile code to match the website, allowing easier non-UK usage of Bing Maps by not including the map-fms.js file.
Diffstat (limited to 'www/js/map-fms.js')
-rw-r--r--www/js/map-fms.js72
1 files changed, 72 insertions, 0 deletions
diff --git a/www/js/map-fms.js b/www/js/map-fms.js
new file mode 100644
index 0000000..598665b
--- /dev/null
+++ b/www/js/map-fms.js
@@ -0,0 +1,72 @@
+var fms_tile_base = [ [ '', 'a-', 'b-', 'c-' ], 'https://{S}tilma.mysociety.org/sv' ];
+
+function set_map_config(perm) {
+ _set_map_config();
+ 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 &copy; Crown copyright and database right 2014';
+ } else {
+ logo = '<a href="https://www.bing.com/maps/"><img border=0 src="https://dev.virtualearth.net/Branding/logo_powered_by.png"></a>';
+ copyrights = '&copy; 2011 <a href="https://www.bing.com/maps/">Microsoft</a>. &copy; 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&key=' + CONFIG.BING_MAPS_API_KEY;
+ }
+ urls = [
+ "https://ecn.t0.tiles.virtualearth.net/tiles/r${id}.png?g=3467" + type,
+ "https://ecn.t1.tiles.virtualearth.net/tiles/r${id}.png?g=3467" + type,
+ "https://ecn.t2.tiles.virtualearth.net/tiles/r${id}.png?g=3467" + type,
+ "https://ecn.t3.tiles.virtualearth.net/tiles/r${id}.png?g=3467" + type
+ ];
+ }
+ return urls;
+ },
+
+ CLASS_NAME: "OpenLayers.Layer.BingUK"
+});