From ab004bfb8716d3d3a5def0404447a1b0236e3e61 Mon Sep 17 00:00:00 2001 From: arno Date: Mon, 14 Mar 2011 18:37:14 +0100 Subject: [PATCH] allow setting initial position with get params --- application/controllers/IdxController.php | 13 ++++++++-- public/js/syj.js | 30 +++++++++++++++++++---- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/application/controllers/IdxController.php b/application/controllers/IdxController.php index c53b11b..790c8c7 100644 --- a/application/controllers/IdxController.php +++ b/application/controllers/IdxController.php @@ -66,8 +66,17 @@ class IdxController extends Zend_Controller_Action $geomform->geom_title->setValue($path->title); } else { $geomform->setAction('path'); - $extent = new phptojs\JsObject('gMaxExtent', $this->_helper->syjGeoip($this->getRequest()->getClientIp(true))); - $this->view->headScript()->prependScript((string) $extent); + + $lat = $this->getRequest()->getQuery('lat'); + $lon = $this->getRequest()->getQuery('lon'); + $zoom = $this->getRequest()->getQuery('zoom'); + if (is_numeric ($lat) and is_numeric ($lon) and is_numeric ($zoom)) { + $initialpos = array('lat' => (float)$lat, 'lon' => (float)$lon, 'zoom' => (int)$zoom); + } else { + $initialpos = $this->_helper->syjGeoip($this->getRequest()->getClientIp(true)); + } + + $this->view->headScript()->prependScript((string) new phptojs\JsObject('gInitialPos', $initialpos)); $title = "Show your journey"; } 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(); -- 2.39.2