X-Git-Url: https://dev.renevier.net/?a=blobdiff_plain;f=public%2Fjs%2Fsyj.js;h=ed68bcf7a43b383751b66bfee28fee785079075f;hb=a73fb9125bf059e16ae583f82d67bcc59efb69b4;hp=78d7606afe2276634e0db2b6227bb40cf591f22e;hpb=6633e95b89c1d1eba9b7b0e612becaf11b085d69;p=syj.git diff --git a/public/js/syj.js b/public/js/syj.js index 78d7606..ed68bcf 100644 --- a/public/js/syj.js +++ b/public/js/syj.js @@ -272,7 +272,7 @@ var SYJView = { mode: 'view', init: function() { - var externalGraphic, baseURL, baseLayer, layerOptions, hidemessenger; + var externalGraphic, baseURL, osmLayer, layerOptions, hidemessenger, layerCode, parameters; // is svg context, opera does not resolve links with base element is svg context externalGraphic = styleMap.edit.styles.select.defaultStyle.externalGraphic; @@ -283,12 +283,24 @@ var SYJView = { controls: [ new OpenLayers.Control.Navigation(), new OpenLayers.Control.PanZoom(), + this.createLayerSwitcher(), new OpenLayers.Control.Attribution() ], theme: null }); - baseLayer = new OpenLayers.Layer.OSM("OSM", null, { wrapDateLine: true , attribution: SyjStrings.osmAttribution }); + osmLayer = new OpenLayers.Layer.OSM("OSM", [ + 'http://a.tile.openstreetmap.org/${z}/${x}/${y}.png', + 'http://b.tile.openstreetmap.org/${z}/${x}/${y}.png', + 'http://c.tile.openstreetmap.org/${z}/${x}/${y}.png'], + { wrapDateLine: true , attribution: SyjStrings.osmAttribution, layerCode: 'O'}); + + mapquestLayer = new OpenLayers.Layer.OSM("Mapquest", [ + 'http://otile1.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png', + 'http://otile2.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png', + 'http://otile3.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png', + 'http://otile4.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png'], + { wrapDateLine: true , attribution: SyjStrings.mapquestAttribution, layerCode: 'M'}); layerOptions = {format: OpenLayers.Format.WKT, projection: WGS84, @@ -296,7 +308,34 @@ var SYJView = { attribution: SyjStrings.geomAttribution }; this.viewLayer = new OpenLayers.Layer.Vector("View Layer", layerOptions); - this.map.addLayers([baseLayer, this.viewLayer]); + this.map.addLayers([osmLayer, mapquestLayer, this.viewLayer]); + + this.map.setBaseLayer(mapquestLayer); + layerCode = null; + parameters = OpenLayers.Util.getParameters(window.location.href); + if (parameters.layer) { + layerCode = parameters.layer; + try { + store.remove('baselayer'); + } catch(e) {} + } else { + try { + layerCode = store.get('baselayer'); + } catch(e) {} + } + + if (layerCode) { + layerCode = layerCode.toUpperCase(); + var self = this; + $([osmLayer, mapquestLayer]).each(function(layer) { + if (layer.layerCode === layerCode) { + self.map.setBaseLayer(layer); + } + }); + } + + + this.map.events.register("changebaselayer", this, this.saveBaseLayer); if ($("edit-btn")) { $("edit-btn").observe('click', function() { @@ -427,6 +466,33 @@ var SYJView = { SYJPathLength.update(); }, + saveBaseLayer: function(data) { + try { + store.set('baselayer', data.layer.layerCode); + } catch(e) {} + }, + + createLayerSwitcher: function() { + var control = new OpenLayers.Control.LayerSwitcher({roundedCorner: false}); + // XXX: we need to "live-patch" LayerSwitcher to use our icons. We use + // a regexp instead of a string in case OpenLayers is modified and in + // case browsers modify the function representation + control.loadContents = eval('(function() { return (' + control.loadContents.toString().replace( + /\s*=\s*imgLocation\s*\+\s*['"]layer-switcher-maximize\.png['"]\s*;/, + " = 'icons/layer-switcher-maximize-flipped.png';" + ) + ')}())'); + var oldMaximizeControl = control.maximizeControl; + var self = this; + control.maximizeControl = (function(oldfunc) { + return function() { + oldfunc.apply(control, arguments); + self.messenger.hide(); + }; + }(control.maximizeControl)); + + return control; + }, + initMaPos: function (aPos) { var extent = null, center = null, zoom = 0; @@ -446,13 +512,6 @@ var SYJView = { } else { this.map.setCenter(center, zoom); } - this.resizeMap(); - }, - - resizeMap: function() { - var map = $('map'); - map.style.width = map.offsetWidth.toString() + 'px'; - map.style.height = map.offsetHeight.toString() + 'px'; }, observer: function(evt) { @@ -1289,7 +1348,3 @@ window.onbeforeunload = function() { return undefined; } }; - -window.onresize = function() { - SYJView.resizeMap(); -};