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

commits at geoext.org commits at geoext.org
Mon Jan 10 16:35:29 CET 2011


Author: cmoullet
Date: 2011-01-10 16:35:29 +0100 (Mon, 10 Jan 2011)
New Revision: 2549

Added:
   sandbox/cmoullet/ux/GeolocationAPI/
   sandbox/cmoullet/ux/GeolocationAPI/examples/
   sandbox/cmoullet/ux/GeolocationAPI/examples/geolocationapiexample.html
   sandbox/cmoullet/ux/GeolocationAPI/examples/geolocationapiexample.js
   sandbox/cmoullet/ux/GeolocationAPI/lib/
   sandbox/cmoullet/ux/GeolocationAPI/lib/GeoExt.ux/
   sandbox/cmoullet/ux/GeolocationAPI/lib/GeoExt.ux/control/
   sandbox/cmoullet/ux/GeolocationAPI/lib/GeoExt.ux/control/GeolocationAPI.js
Log:
First prototype of GeolocationAPI UX

Added: sandbox/cmoullet/ux/GeolocationAPI/examples/geolocationapiexample.html
===================================================================
--- sandbox/cmoullet/ux/GeolocationAPI/examples/geolocationapiexample.html	                        (rev 0)
+++ sandbox/cmoullet/ux/GeolocationAPI/examples/geolocationapiexample.html	2011-01-10 15:35:29 UTC (rev 2549)
@@ -0,0 +1,26 @@
+<html>
+<head>
+    <title>GeoLocation API Example</title>
+
+    <script type="text/javascript" src="../../../trunk/ext/adapter/ext/ext-base.js"></script>
+    <script type="text/javascript" src="../../../trunk/ext/ext-all.js"></script>
+    <link rel="stylesheet" type="text/css" href="../../../trunk/ext/resources/css/ext-all.css"/>
+    <link rel="stylesheet" type="text/css" href="../../../trunk/ext/examples/shared/examples.css"/>
+
+    <script type="text/javascript" src="../../../trunk/openlayers/lib/OpenLayers.js"></script>
+    <script type="text/javascript" src="../../../trunk/geoext/lib/GeoExt.js"></script>
+
+    <script type="text/javascript" src="../lib/GeoExt.ux/control/GeolocationAPI.js"></script>
+
+    <script type="text/javascript" src="geolocationapiexample.js"></script>
+</head>
+<body>
+<h1>GeoLocation API example</h1>
+
+<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>
+
+<div id="mapppanel"></div>
+</body>
+</html>
\ No newline at end of file

Added: sandbox/cmoullet/ux/GeolocationAPI/examples/geolocationapiexample.js
===================================================================
--- sandbox/cmoullet/ux/GeolocationAPI/examples/geolocationapiexample.js	                        (rev 0)
+++ sandbox/cmoullet/ux/GeolocationAPI/examples/geolocationapiexample.js	2011-01-10 15:35:29 UTC (rev 2549)
@@ -0,0 +1,22 @@
+Ext.onReady(function() {
+
+    // required for tooltips
+    Ext.QuickTips.init();
+
+    var map = new OpenLayers.Map();
+    var GeolocationAPIControl = new OpenLayers.Control.GeolocationAPI({});
+    map.addControl(GeolocationAPIControl);
+
+    var mapPanel = new GeoExt.MapPanel({
+        renderTo: "mapppanel",
+        width: 800,
+        height: 350,
+        map: map,
+        layers: [new OpenLayers.Layer.WMS("Global Imagery",
+                "http://vmap0.tiles.osgeo.org/wms/vmap0",
+        {layers: "basic"})],
+        center: [7.5, 47],
+        zoom: 8
+    });
+    GeolocationAPIControl.activate();
+});
\ No newline at end of file

Added: sandbox/cmoullet/ux/GeolocationAPI/lib/GeoExt.ux/control/GeolocationAPI.js
===================================================================
--- sandbox/cmoullet/ux/GeolocationAPI/lib/GeoExt.ux/control/GeolocationAPI.js	                        (rev 0)
+++ sandbox/cmoullet/ux/GeolocationAPI/lib/GeoExt.ux/control/GeolocationAPI.js	2011-01-10 15:35:29 UTC (rev 2549)
@@ -0,0 +1,57 @@
+/**
+ * @requires OpenLayers/Control.js
+ */
+
+/**
+ * Class: OpenLayers.Control.GeolocationAPI
+ *
+ * Inherits from:
+ *  - <OpenLayers.Control>
+ */
+
+OpenLayers.Control.GeolocationAPI = OpenLayers.Class(OpenLayers.Control, {
+
+    isGeolocationAPISupported: null,
+
+    mode: "position",
+
+    zoom: 12,
+
+    currentPosition: null,
+
+    initialize: function(options) {
+        options = options || {};
+
+        if (navigator.geolocation) {
+            this.isGeolocationAPISupported = true;
+        } else {
+            this.isGeolocationAPISupported = false;
+        }
+        OpenLayers.Control.prototype.initialize.apply(this, [options]);
+    },
+
+    activate: function () {
+
+        if (this.isGeolocationAPISupported && this.mode == "position") {
+            this.activatePosition();
+        }
+        OpenLayers.Control.prototype.activate.apply(this);
+    },
+    deactivate: function () {
+        OpenLayers.Control.prototype.deactivate.apply(this);
+    },
+    activatePosition: function() {
+        navigator.geolocation.getCurrentPosition(this.centerMap.bind(this), this.locationError);
+    },
+    centerMap: function(position) {
+        this.currentPosition = position;
+        var lonLat = new OpenLayers.LonLat(position.coords.longitude, position.coords.latitude);
+        var mapCoordinate = lonLat.transform(new OpenLayers.Projection("EPSG:4326"),
+                this.map.getProjectionObject());
+        this.map.setCenter(mapCoordinate, this.zoom);
+    },
+    locationError: function(error) {
+        alert("Error with GeoLocation API: " + error.code);
+
+    }
+});
\ No newline at end of file



More information about the Commits mailing list