aboutsummaryrefslogtreecommitdiffstats
path: root/web/js
diff options
context:
space:
mode:
authorSteven Day <steve@mysociety.org>2012-11-19 11:00:05 +0000
committerMatthew Somerville <matthew@mysociety.org>2012-11-26 12:47:10 +0000
commit86b8dab75f74fed9297fc689b3f2964425be61fd (patch)
tree052500302628cc4458eb0d4970fac90bc48bc6e7 /web/js
parenta423e85eeae90c3a3f586e177e51f916ad9eeabd (diff)
Convert bounds from swiss to lat/lon so ajax doesn't break
Diffstat (limited to 'web/js')
-rw-r--r--web/js/map-OpenLayers.js2
-rw-r--r--web/js/map-wmts-zurich.js79
2 files changed, 80 insertions, 1 deletions
diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js
index d4bf7800c..8506f8076 100644
--- a/web/js/map-OpenLayers.js
+++ b/web/js/map-OpenLayers.js
@@ -137,7 +137,7 @@ function fixmystreet_onload() {
styleMap: pin_layer_style_map
};
if (fixmystreet.page == 'around') {
- fixmystreet.bbox_strategy = new OpenLayers.Strategy.BBOX({ ratio: 1 });
+ fixmystreet.bbox_strategy = fixmystreet.bbox_strategy || new OpenLayers.Strategy.BBOX({ ratio: 1 });
pin_layer_options.strategies = [ fixmystreet.bbox_strategy ];
pin_layer_options.protocol = new OpenLayers.Protocol.HTTP({
url: '/ajax',
diff --git a/web/js/map-wmts-zurich.js b/web/js/map-wmts-zurich.js
index 0244ad73e..441df91eb 100644
--- a/web/js/map-wmts-zurich.js
+++ b/web/js/map-wmts-zurich.js
@@ -12,6 +12,9 @@ function init_zurich_map(after) {
projection: new OpenLayers.Projection("EPSG:21781"),
displayProjection: new OpenLayers.Projection("EPSG:21781"),
maxExtent: new OpenLayers.Bounds(676000,241000,690000,255000),
+ //projection: new OpenLayers.Projection("EPSG:4326"),
+ //displayProjection: new OpenLayers.Projection("EPSG:4326"),
+ //maxExtent: new OpenLayers.Bounds(8.444933818976226,47.31509040172551,8.632922236617937,47.442777990747416),
units: 'm',
scales: [ '250000', '125000', '64000', '32000', '16000', '8000', '4000', '2000', '1000', '500'],
controls: fixmystreet.controls
@@ -62,6 +65,59 @@ function init_zurich_map(after) {
'xml');
}
+// These next two functions come from the Swiss Federal Office of Topography
+// http://www.swisstopo.admin.ch/internet/swisstopo/en/home/products/software/products/skripts.html
+
+// Convert CH y/x to WGS lat
+function chToWGSlat(y, x) {
+
+ // Converts militar to civil and to unit = 1000km
+ // Axiliary values (% Bern)
+ var y_aux = (y - 600000) / 1000000;
+ var x_aux = (x - 200000) / 1000000;
+
+ // Process lat
+ var lat = 16.9023892;
+ lat = lat + (3.238272 * x_aux);
+ lat = lat - (0.270978 * Math.pow(y_aux, 2));
+ lat = lat - (0.002528 * Math.pow(x_aux, 2));
+ lat = lat - (0.0447 * Math.pow(y_aux, 2) * x_aux);
+ lat = lat - (0.0140 * Math.pow(x_aux, 3));
+
+ // Unit 10000" to 1 " and converts seconds to degrees (dec)
+ lat = lat * 100 / 36;
+
+ return lat;
+
+}
+
+// Convert CH y/x to WGS long
+function chToWGSlng(y, x) {
+
+ // Converts militar to civil and to unit = 1000km
+ // Axiliary values (% Bern)
+ var y_aux = (y - 600000) / 1000000;
+ var x_aux = (x - 200000) / 1000000;
+
+ // Process long
+ var lng = 2.6779094;
+ lng = lng + (4.728982 * y_aux);
+ lng = lng + (0.791484 * y_aux * x_aux);
+ lng = lng + (0.1306 * y_aux * Math.pow(x_aux, 2));
+ lng = lng - (0.0436 * Math.pow(y_aux, 3));
+
+ // Unit 10000" to 1 " and converts seconds to degrees (dec)
+ lng = lng * 100 / 36;
+
+ return lng;
+
+}
+
+// Function to convert a Swiss coordinate to a WGS84 coordinate.
+function getOLLatLonFromSwiss(y, x) {
+ return new OpenLayers.LonLat(chToWGSlng(y, x), chToWGSlat(y, x));
+}
+
/*
* set_map_config() is called on dom ready in map-OpenLayers.js
* to setup the way the map should operate.
@@ -95,4 +151,27 @@ function init_zurich_map(after) {
// tell the main code to run our function instead
// of setting the map up itself
fixmystreet.map_setup = init_zurich_map;
+
+ // Give main code a new bbox_strategy that translates between
+ // lat/lon and our swiss coordinates
+ fixmystreet.bbox_strategy = new OpenLayers.Strategy.ZurichBBOX({ratio: 1});
}
+
+OpenLayers.Strategy.ZurichBBOX = OpenLayers.Class(OpenLayers.Strategy.BBOX, {
+ getMapBounds: function() {
+ // Get the map bounds but return them in lat/lon, not
+ // Swiss coordinates
+ if (this.layer.map === null) {
+ return null;
+ }
+ var swissBounds = this.layer.map.getExtent();
+ var topLeft = getOLLatLonFromSwiss(swissBounds.left,swissBounds.top);
+ var bottomRight = getOLLatLonFromSwiss(swissBounds.right,swissBounds.bottom);
+ var bounds = new OpenLayers.Bounds();
+ bounds.extend(topLeft);
+ bounds.extend(bottomRight);
+ return bounds;
+ },
+
+ CLASS_NAME: "OpenLayers.Strategy.ZurichBBOX"
+});