]> dev.renevier.net Git - syj.git/commitdiff
allow setting initial position with get params
authorarno <arno@renevier.net>
Mon, 14 Mar 2011 17:37:14 +0000 (18:37 +0100)
committerarno <arno@renevier.net>
Mon, 14 Mar 2011 17:37:14 +0000 (18:37 +0100)
application/controllers/IdxController.php
public/js/syj.js

index c53b11b2146320b626aec2bc67e4e7314f1970f0..790c8c766348edd0f88205b23670ee96db772c3d 100644 (file)
@@ -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";
         }
 
index 05e2134189075747764255a1461d4204b65096ea..de3333f5c41d0028b60313604ea9ff0582bfaebc 100644 (file)
@@ -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();