[Commits] r2558 - in sandbox/cmoullet/ux/GeolocationAPI: examples lib/GeoExt.ux/control

commits at geoext.org commits at geoext.org
Thu Jan 13 06:06:42 CET 2011


Author: cmoullet
Date: 2011-01-13 06:06:42 +0100 (Thu, 13 Jan 2011)
New Revision: 2558

Added:
   sandbox/cmoullet/ux/GeolocationAPI/examples/geolocationapimobileexample.html
   sandbox/cmoullet/ux/GeolocationAPI/examples/geolocationapimobileexample.js
Modified:
   sandbox/cmoullet/ux/GeolocationAPI/examples/geolocationapiexample.html
   sandbox/cmoullet/ux/GeolocationAPI/lib/GeoExt.ux/control/GeolocationAPI.js
Log:
Add a mobile Geolocation API example

Modified: sandbox/cmoullet/ux/GeolocationAPI/examples/geolocationapiexample.html
===================================================================
--- sandbox/cmoullet/ux/GeolocationAPI/examples/geolocationapiexample.html	2011-01-12 07:32:11 UTC (rev 2557)
+++ sandbox/cmoullet/ux/GeolocationAPI/examples/geolocationapiexample.html	2011-01-13 05:06:42 UTC (rev 2558)
@@ -17,7 +17,7 @@
 <body>
 <h1>GeoLocation API example</h1>
 
-<p style="margin-bottom:15px;">Example using a geolocation API control</p>
+<p style="margin-bottom:15px;">Example using a Geolocation API control</p>
 
 <p style="margin-bottom:15px;">See <a href="geolocationapiexample.js">geolocationapiexample.js</a> for the source code.</p>
 

Added: sandbox/cmoullet/ux/GeolocationAPI/examples/geolocationapimobileexample.html
===================================================================
--- sandbox/cmoullet/ux/GeolocationAPI/examples/geolocationapimobileexample.html	                        (rev 0)
+++ sandbox/cmoullet/ux/GeolocationAPI/examples/geolocationapimobileexample.html	2011-01-13 05:06:42 UTC (rev 2558)
@@ -0,0 +1,49 @@
+<html>
+<head>
+    <title>Geolocation API Mobile</title>
+
+    <!-- IPhone Meta Tags -->
+    <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
+    <meta name="apple-mobile-web-app-capable" content="yes"/>
+    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/>
+
+    <style type="text/css">
+        * {
+            margin: 0;
+            padding: 0;
+        }
+        #map {
+            width: 100%;
+            height: 100%;
+        }
+        #positionInfo {
+            position:absolute;
+            right:10px;
+            top:10px;
+            width: 200px;
+            z-index: 1000;
+        }
+    </style>
+
+
+
+    <script type="text/javascript"
+            src="http://c2c-rd-geospatial.demo-camptocamp.com/lib/openlayers/OpenLayers.mobile.min.js"></script>
+    <script type="text/javascript"
+            src="http://c2c-rd-geospatial.demo-camptocamp.com/lib/openlayers/lib/OpenLayers/Control/TouchNavigation.js"></script>
+    <script type="text/javascript"
+            src="http://c2c-rd-geospatial.demo-camptocamp.com/lib/openlayers/lib/OpenLayers/Handler/Click.js"></script>
+    <script type="text/javascript"
+            src="http://c2c-rd-geospatial.demo-camptocamp.com/lib/openlayers/lib/OpenLayers/Layer/WMS.js"></script>
+    <script type="text/javascript"
+            src="http://c2c-rd-geospatial.demo-camptocamp.com/lib/openlayers/lib/OpenLayers/BaseTypes.js"></script>
+    <script type="text/javascript" src="../lib/GeoExt.ux/control/GeolocationAPI.js"></script>
+
+    <script type="text/javascript" src="geolocationapimobileexample.js"></script>
+
+</head>
+<body onload='init();'>
+<div id="map"></div>
+<div id="positionInfo"></div>
+</body>
+</html>

Added: sandbox/cmoullet/ux/GeolocationAPI/examples/geolocationapimobileexample.js
===================================================================
--- sandbox/cmoullet/ux/GeolocationAPI/examples/geolocationapimobileexample.js	                        (rev 0)
+++ sandbox/cmoullet/ux/GeolocationAPI/examples/geolocationapimobileexample.js	2011-01-13 05:06:42 UTC (rev 2558)
@@ -0,0 +1,35 @@
+function init() {
+
+    var map = new OpenLayers.Map('map', {controls: [
+        new OpenLayers.Control.TouchNavigation({
+            dragPanOptions: {
+                kineticDragging: true,
+                autoActivate: true,
+                interval: 0 // non-zero kills performance on some mobile phones
+            }
+        })
+    ]});
+    var GeolocationAPIControl = new OpenLayers.Control.GeolocationAPI({mode: 'tracking', zoom: 11, geolocationOptions: {timeout:3000}});
+    map.addControl(GeolocationAPIControl);
+
+    var layer = new OpenLayers.Layer.WMS("Global Imagery",
+            "http://vmap0.tiles.osgeo.org/wms/vmap0",
+    {layers: "basic"});
+
+    map.addLayers([layer]);
+
+    map.zoomToMaxExtent();
+
+    GeolocationAPIControl.events.register("positioncomputed", GeolocationAPIControl, function(position) {
+        document.getElementById("positionInfo").innerHTML = this.getPositionInformation("<BR>");
+    });
+    GeolocationAPIControl.events.register("positionerror", GeolocationAPIControl, function(errorEvent) {
+        switch (errorEvent.error.code) {
+            case 0: document.getElementById("positionInfo").innerHTML = "There was an error while retrieving your location."; break;
+            case 1: document.getElementById("positionInfo").innerHTML = "The user didn't accept to provide a location"; break;
+            case 2: document.getElementById("positionInfo").innerHTML = "The browser was unable to determine your location"; break;
+            case 3: document.getElementById("positionInfo").innerHTML = "The browser timed out before retrieving the location."; break;
+        }
+    });
+    GeolocationAPIControl.activate();
+}
\ No newline at end of file

Modified: sandbox/cmoullet/ux/GeolocationAPI/lib/GeoExt.ux/control/GeolocationAPI.js
===================================================================
--- sandbox/cmoullet/ux/GeolocationAPI/lib/GeoExt.ux/control/GeolocationAPI.js	2011-01-12 07:32:11 UTC (rev 2557)
+++ sandbox/cmoullet/ux/GeolocationAPI/lib/GeoExt.ux/control/GeolocationAPI.js	2011-01-13 05:06:42 UTC (rev 2558)
@@ -69,10 +69,10 @@
         OpenLayers.Control.prototype.deactivate.apply(this);
     },
     activatePosition: function() {
-        navigator.geolocation.getCurrentPosition(this.centerMap.bind(this), this.locationError.bind(this), this.geolocationOptions);
+        navigator.geolocation.getCurrentPosition(OpenLayers.Function.bind(this.centerMap,this), OpenLayers.Function.bind(this.locationError,this), this.geolocationOptions);
     },
     activateTracking: function() {
-        this.trackingId = navigator.geolocation.watchPosition(this.centerMap.bind(this), this.locationError.bind(this), this.geolocationOptions);
+        this.trackingId = navigator.geolocation.watchPosition(OpenLayers.Function.bind(this.centerMap,this), OpenLayers.Function.bind(this.locationError,this), this.geolocationOptions);
     },
     centerMap: function(position) {
         this.currentPosition = position;



More information about the Commits mailing list