X-Git-Url: https://dev.renevier.net/?p=syj.git;a=blobdiff_plain;f=public%2Fjs%2Fsyj.js;fp=public%2Fjs%2Fsyj.js;h=8c48c99e980bc844773f70dbc6af9a8f9d72b16e;hp=8f5f509020fd0f6251055213aa3d050169f963fe;hb=c06c7fd6e6f26d31abb8d7c9a9f9e3f2d5b27d5c;hpb=3728a2a2feb7474ddb2ef90340112bea8fda0574 diff --git a/public/js/syj.js b/public/js/syj.js index 8f5f509..8c48c99 100644 --- a/public/js/syj.js +++ b/public/js/syj.js @@ -276,7 +276,7 @@ var SYJView = { mode: 'view', init: function() { - var externalGraphic, baseURL, baseLayer, layerOptions, hidemessenger; + var externalGraphic, baseURL, mapnikLayer, mapquestLayer, 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; @@ -287,16 +287,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", [ + mapnikLayer = new OpenLayers.Layer.OSM("Mapnik", [ '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'], - { attribution: SyjStrings.osmAttribution }); + { attribution: SyjStrings.osmAttribution, layerCode: 'M' }); + + 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'], + { attribution: SyjStrings.mapquestAttribution, layerCode: 'Q'}); layerOptions = {format: OpenLayers.Format.WKT, projection: WGS84, @@ -304,7 +312,33 @@ var SYJView = { attribution: SyjStrings.geomAttribution }; this.viewLayer = new OpenLayers.Layer.Vector("View Layer", layerOptions); - this.map.addLayers([baseLayer, this.viewLayer]); + this.map.addLayers([mapnikLayer, mapquestLayer, this.viewLayer]); + + this.map.setBaseLayer(mapnikLayer); + 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; + $([mapnikLayer, 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() { @@ -442,6 +476,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;