X-Git-Url: https://dev.renevier.net/?p=syj.git;a=blobdiff_plain;f=public%2Fjs%2Fsyj.js;h=de3333f5c41d0028b60313604ea9ff0582bfaebc;hp=05e2134189075747764255a1461d4204b65096ea;hb=ab004bfb8716d3d3a5def0404447a1b0236e3e61;hpb=e6d781eb4614d9bb8f87133e16c62a1a5a564e77 diff --git a/public/js/syj.js b/public/js/syj.js index 05e2134..de3333f 100644 --- a/public/js/syj.js +++ b/public/js/syj.js @@ -267,7 +267,7 @@ var SYJView = { mode: 'view', init: function() { - var externalGraphic, baseURL, baseLayer, layerOptions, extent, hidemessenger; + var externalGraphic, baseURL, baseLayer, layerOptions, hidemessenger; // is svg context, opera does not resolve links with base element is svg context externalGraphic = styleMap.edit.styles.select.defaultStyle.externalGraphic; @@ -341,15 +341,14 @@ var SYJView = { if (typeof gInitialGeom !== "undefined" && typeof gInitialGeom.data !== "undefined") { this.viewLayer.addFeatures([this.wkt.read(gInitialGeom.data)]); - extent = this.viewLayer.getDataExtent(); // XXX: ie has not guessed height of map main div yet during map // initialisation. Now, it will read it correctly. this.map.updateSize(); + this.map.zoomToExtent(this.viewLayer.getDataExtent()); } else { - extent = new OpenLayers.Bounds(gMaxExtent.minlon, gMaxExtent.minlat, gMaxExtent.maxlon, gMaxExtent.maxlat) - .transform(WGS84, Mercator); + this.initMaPos(gInitialPos); } - this.map.zoomToExtent(extent); + document.observe('simplebox:shown', this.observer.bindAsEventListener(this)); SYJPathLength.update(); @@ -427,6 +426,27 @@ var SYJView = { } }, + 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); + } 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) + .transform(WGS84, Mercator); + } else { + extent = new OpenLayers.Bounds(-160, -70, 160, 70).transform(WGS84, Mercator); + } + + if (extent) { + this.map.zoomToExtent(extent); + } else { + this.map.setCenter(center, zoom); + } + }, + observer: function(evt) { if (evt.eventName === "simplebox:shown" && evt.memo.element !== $("termsofusearea")) { this.messenger.hide();