-/* This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
+/* This file is part of Syj, Copyright (c) 2010-2011 Arnaud Renevier,
and is published under the AGPL license. */
// avoid openlayers alerts
if (!infotoggler) {
infotoggler = new Toggler('path-infos-content');
$("path-infos-toggler").insert({bottom: infotoggler.element});
- $("path-infos-anchor").observe('click', function(evt) {
+ var anchor = $("path-infos-anchor");
+ var parent = anchor.up('.menu-item');
+ if (parent) {
+ anchor = parent;
+ }
+ anchor.observe('click', function(evt) {
evt.stop();
infotoggler.toggle(evt);
});
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;
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,
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() {
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;
if (aPos.hasOwnProperty('lon') && aPos.hasOwnProperty('lat') && aPos.hasOwnProperty('zoom')) {
center = new OpenLayers.LonLat(parseFloat(aPos.lon), parseFloat(aPos.lat)).transform(WGS84, Mercator);
- zoom = parseInt(aPos.zoom);
+ zoom = parseInt(aPos.zoom, 10);
} else if (aPos.hasOwnProperty('minlon') && aPos.hasOwnProperty('minlat')
&& aPos.hasOwnProperty('maxlon') && aPos.hasOwnProperty('maxlat')) {
extent = new OpenLayers.Bounds(aPos.minlon, aPos.minlat, aPos.maxlon, aPos.maxlat)
} 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) {
case 400:
case 404:
message = SyjStrings.requestError;
- if (transport.responseJSON) {
- switch (transport.responseJSON.message) {
- case "uniquepath":
- message = SyjStrings.uniquePathError;
- break;
- default:
- break;
- }
- }
break;
case 403:
message = "";
closeMethods: ["onescapekey", "onouterclick", "onbutton"]
});
- $(this.type + "_control_anchor").observe("click", function(evt) {
+ var anchor = $(this.type + '_control_anchor');
+ var parent = anchor.up('.menu-item');
+ if (parent) {
+ anchor = parent;
+ }
+ anchor.observe("click", function(evt) {
this.modalbox.show();
evt.stop();
}.bindAsEventListener(this));
input = this.area.select('input[type="text"]')[0];
(function () {
input.activate();
- }).defer();
+ }.defer());
} else {
this.modalbox.hide();
}
return undefined;
}
};
+
+window.onresize = function() {
+ SYJView.resizeMap();
+};