aboutsummaryrefslogtreecommitdiffstats
path: root/web/js
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2014-10-06 15:47:21 +0000
committerMatthew Somerville <matthew@mysociety.org>2015-02-23 17:10:05 +0000
commit032db2fbb6bd2bf0cf0cf2daa379610ab319a6a8 (patch)
tree7c23e16a551d80ebc2b3ebf05cbc5dac16e1be6e /web/js
parentc763a5e8e78849d736f9c0cec92ee2687ac9e75d (diff)
Support Stamen toner-lite and Bing Maps tiles.
Diffstat (limited to 'web/js')
-rw-r--r--web/js/map-OpenLayers.js5
-rw-r--r--web/js/map-bing-ol.js82
-rw-r--r--web/js/map-fms.js74
-rw-r--r--web/js/map-toner-lite.js19
4 files changed, 121 insertions, 59 deletions
diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js
index baa8d7810..3088cc764 100644
--- a/web/js/map-OpenLayers.js
+++ b/web/js/map-OpenLayers.js
@@ -288,6 +288,9 @@ $(function(){
if (!fixmystreet.layer_options) {
fixmystreet.layer_options = [ {} ];
}
+ if (!fixmystreet.layer_name) {
+ fixmystreet.layer_name = "";
+ }
for (var i=0; i<fixmystreet.layer_options.length; i++) {
fixmystreet.layer_options[i] = OpenLayers.Util.extend({
// This option is used by XYZ-based layers
@@ -300,7 +303,7 @@ $(function(){
if (fixmystreet.layer_options[i].matrixIds) {
layer = new fixmystreet.map_type(fixmystreet.layer_options[i]);
} else {
- layer = new fixmystreet.map_type("", fixmystreet.layer_options[i]);
+ layer = new fixmystreet.map_type(fixmystreet.layer_name, fixmystreet.layer_options[i]);
}
fixmystreet.map.addLayer(layer);
}
diff --git a/web/js/map-bing-ol.js b/web/js/map-bing-ol.js
index 059a5e67e..9406997f9 100644
--- a/web/js/map-bing-ol.js
+++ b/web/js/map-bing-ol.js
@@ -1,6 +1,4 @@
-var tile_base = [ [ '', 'a-', 'b-', 'c-' ], '//{S}tilma.mysociety.org/sv' ];
-
-function set_map_config(perm) {
+function _set_map_config() {
var permalink_id;
if ($('#map_permalink').length) {
permalink_id = 'map_permalink';
@@ -23,52 +21,22 @@ function set_map_config(perm) {
if ( fixmystreet.page == 'report' ) {
fixmystreet.controls.push( new OpenLayers.Control.PermalinkFMS('key-tool-problems-nearby', '/around') );
}
+}
- if (fixmystreet.map_type) {
- tile_base = fixmystreet.map_type;
- }
- fixmystreet.map_type = OpenLayers.Layer.BingUK;
+function set_map_config(perm) {
+ _set_map_config();
+ fixmystreet.map_type = OpenLayers.Layer.Bing;
}
-OpenLayers.Layer.BingUK = OpenLayers.Class(OpenLayers.Layer.XYZ, {
+OpenLayers.Layer.Bing = 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();
- 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 2010';
- } else {
- logo = '<a href="https://www.bing.com/maps/"><img border=0 src="//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';
- }
+ _updateAttribution: function(copyrights, logo) {
this.attribution = OpenLayers.String.format(this.attributionTemplate, {
logo: logo,
copyrights: copyrights
@@ -81,6 +49,12 @@ OpenLayers.Layer.BingUK = OpenLayers.Class(OpenLayers.Layer.XYZ, {
}
},
+ updateAttribution: function() {
+ var copyrights = '&copy; 2011 <a href="https://www.bing.com/maps/">Microsoft</a>. &copy; AND, Navteq';
+ var logo = '<a href="https://www.bing.com/maps/"><img border=0 src="//dev.virtualearth.net/Branding/logo_powered_by.png"></a>';
+ this._updateAttribution(copyrights, logo);
+ },
+
initialize: function(name, options) {
var url = [];
options = OpenLayers.Util.extend({
@@ -89,7 +63,6 @@ OpenLayers.Layer.BingUK = OpenLayers.Class(OpenLayers.Layer.XYZ, {
numZoomLevels: 19,
sphericalMercator: true,
buffer: 0
- //attribution: "© Microsoft / OS 2010"
}, options);
var newArguments = [name, url, options];
OpenLayers.Layer.XYZ.prototype.initialize.apply(this, newArguments);
@@ -121,23 +94,7 @@ OpenLayers.Layer.BingUK = OpenLayers.Class(OpenLayers.Layer.XYZ, {
OpenLayers.Util.indexOf(this.serverResolutions, res) :
this.map.getZoom() + this.zoomOffset;
- var url;
- 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 && 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,
- "//ecn.t2.tiles.virtualearth.net/tiles/r${id}.png?g=701" + type,
- "//ecn.t3.tiles.virtualearth.net/tiles/r${id}.png?g=701" + type
- ];
- }
+ var url = this.get_urls(bounds, z);
var s = '' + x + y + z;
url = this.selectUrl(s, url);
@@ -146,5 +103,14 @@ OpenLayers.Layer.BingUK = OpenLayers.Class(OpenLayers.Layer.XYZ, {
return path;
},
- CLASS_NAME: "OpenLayers.Layer.BingUK"
+ get_urls: function(bounds, z) {
+ return [
+ "//ecn.t0.tiles.virtualearth.net/tiles/r${id}.png?g=3293",
+ "//ecn.t1.tiles.virtualearth.net/tiles/r${id}.png?g=3293",
+ "//ecn.t2.tiles.virtualearth.net/tiles/r${id}.png?g=3293",
+ "//ecn.t3.tiles.virtualearth.net/tiles/r${id}.png?g=3293"
+ ];
+ },
+
+ CLASS_NAME: "OpenLayers.Layer.Bing"
});
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 &copy; Crown copyright and database right 2014';
+ } else {
+ logo = '<a href="https://www.bing.com/maps/"><img border=0 src="//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'; }
+ 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"
+});
diff --git a/web/js/map-toner-lite.js b/web/js/map-toner-lite.js
new file mode 100644
index 000000000..5291d0254
--- /dev/null
+++ b/web/js/map-toner-lite.js
@@ -0,0 +1,19 @@
+function set_map_config(perm) {
+ var permalink_id;
+ if ($('#map_permalink').length) {
+ permalink_id = 'map_permalink';
+ }
+ fixmystreet.controls = [
+ new OpenLayers.Control.ArgParser(),
+ new OpenLayers.Control.Navigation(),
+ new OpenLayers.Control.PermalinkFMS(permalink_id),
+ new OpenLayers.Control.PanZoomFMS({id: 'fms_pan_zoom' })
+ ];
+ fixmystreet.layer_options = [ {
+ maxResolution: 156543.03390625/Math.pow(2, fixmystreet.zoomOffset)
+ } ];
+ fixmystreet.layer_name = 'toner-lite';
+
+ // The Stamen JS returns HTTP urls, fix that
+ stamen.tile.getProvider('toner-lite').url = 'https://stamen-tiles-{S}a.ssl.fastly.net/toner-lite/{Z}/{X}/{Y}.png';
+}