[fusion-commits] r2742 - in trunk/widgets: . widgetinfo

svn_fusion at osgeo.org svn_fusion at osgeo.org
Tue Jul 2 22:19:48 PDT 2013


Author: jng
Date: 2013-07-02 22:19:48 -0700 (Tue, 02 Jul 2013)
New Revision: 2742

Added:
   trunk/widgets/Geolocation.js
   trunk/widgets/widgetinfo/geolocation.xml
Log:
#579: Add new Geolocation widget

Added: trunk/widgets/Geolocation.js
===================================================================
--- trunk/widgets/Geolocation.js	                        (rev 0)
+++ trunk/widgets/Geolocation.js	2013-07-03 05:19:48 UTC (rev 2742)
@@ -0,0 +1,109 @@
+/**
+ * Fusion.Widget.Geolocation
+ *
+ * $Id: About.js 2585 2012-09-07 14:01:25Z jng $
+ *
+ * Copyright (c) 2007, DM Solutions Group Inc.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/********************************************************************
+* Class: Fusion.Widget.Geolocation
+*
+* A widget that pans (and optionally zoom) to the user's current geographic location
+*
+* Inherits from:
+*  - <Fusion.Widget>
+* **********************************************************************/
+
+Fusion.Widget.Geolocation = OpenLayers.Class(Fusion.Widget, {
+    uiClass: Jx.Button,
+    
+    nZoom: null,
+    bEnableHighAccuracy: false,
+    nTimeout: 5000,
+    nMaximumAge: 0,
+
+    initializeWidget: function(widgetTag) {
+        var json = widgetTag.extension;
+        
+        var geoOptions = {};
+        if (json.ZoomLevel)
+            this.nZoom = parseInt(json.ZoomLevel[0]);
+        if (json.EnableHighAccuracy)
+            geoOptions.enableHighAccuracy = (json.EnableHighAccuracy[0] == "true");
+        if (json.Timeout)
+            geoOptions.timeout = parseInt(json.Timeout[0]);
+        if (json.MaximumAge)
+            geoOptions.maximumAge = parseInt(json.MaximumAge[0]);
+            
+        this.geoOptions = geoOptions;
+        
+        this.enable();
+    },
+    
+    onPositionError: function(error) {
+        //Maybe use MapMessage for non-intrusive error display?
+        switch(error.code) {
+            case 1: //Permission denied
+                alert(error.message);
+            case 2: //Position unavailable
+                alert(error.message);
+            case 3: //Timeout
+                alert(error.message);
+            default:
+                console.error("Error with geolocation: (" + error.code + ") " + error.message);
+        }
+    },
+    
+    onPositionRetrieved: function(pos) {
+        var mapWidget = this.getMap();
+        var olMap = mapWidget.oMapOL;
+        
+        var geoProj = new OpenLayers.Projection("EPSG:4326");
+        var mapProj = olMap.projection;
+        
+        var lonlat = new OpenLayers.LonLat(pos.coords.longitude, pos.coords.latitude);
+        lonlat.transform(geoProj, mapProj);
+        
+        if (this.nZoom == null) {
+            olMap.moveTo(lonlat);
+        } else {
+            var extent = mapWidget.getExtentFromPoint(lonlat.lon, lonlat.lat, this.nZoom);
+            mapWidget.setExtents(extent);
+        }
+    },
+
+    /**
+     * Function: activate
+     *
+     * Pan (and optionally zoom) to the user's current geographic location
+     * 
+     */
+    activate: function() {
+        if (typeof(navigator.geolocation) == 'undefined') {
+            alert(OpenLayers.i18n("geolocation_unsupported"));
+        } else {
+            navigator.geolocation.getCurrentPosition(
+                OpenLayers.Function.bind(this.onPositionRetrieved, this),
+                OpenLayers.Function.bind(this.onPositionError, this),
+                this.geoOptions);
+        }
+    }
+});

Added: trunk/widgets/widgetinfo/geolocation.xml
===================================================================
--- trunk/widgets/widgetinfo/geolocation.xml	                        (rev 0)
+++ trunk/widgets/widgetinfo/geolocation.xml	2013-07-03 05:19:48 UTC (rev 2742)
@@ -0,0 +1,45 @@
+<WidgetInfo>
+  <Type>Geolocation</Type>
+  <LocalizedType>Geolocation</LocalizedType>
+  <Description>This widget zooms to your current geographic location</Description>
+  <Location></Location>
+  <Label>My Location</Label>
+  <Tooltip>Click to zoom to your current geographic location</Tooltip>
+  <StatusText></StatusText>
+  <ImageUrl>images/icons.png</ImageUrl>
+  <ImageClass>geolocation</ImageClass>
+  <StandardUi>true</StandardUi>
+  <ContainableBy>Any</ContainableBy>
+  <Parameter>
+    <Name>ZoomLevel</Name>
+    <Description>The zoom to apply in addition to panning to your current geographic location</Description>
+    <Type>integer</Type>
+    <Label>Zoom Level</Label>
+    <DefaultValue></DefaultValue>
+    <IsMandatory>false</IsMandatory>
+  </Parameter>
+  <Parameter>
+    <Name>EnableHighAccuracy</Name>
+    <Description>A Boolean that indicates the application would like to receive the best possible results. If true and if the device is able to provide a more accurate position, it will do so. Note that this can result in slower response times or increased power consumption (with a GPS chip on a mobile device for example). On the other hand, if false (the default value), the device can take the liberty to save resources by responding more quickly and/or using less power</Description>
+    <Type>boolean</Type>
+    <Label>Enable High Accuracy</Label>
+    <DefaultValue>false</DefaultValue>
+    <IsMandatory>false</IsMandatory>
+  </Parameter>
+  <Parameter>
+    <Name>Timeout</Name>
+    <Description>A positive number representing the maximum length of time (in milliseconds) the device is allowed to take in order to return a position.</Description>
+    <Type>integer</Type>
+    <Label>Timeout</Label>
+    <DefaultValue>5000</DefaultValue>
+    <IsMandatory>false</IsMandatory>
+  </Parameter>
+  <Parameter>
+    <Name>MaximumAge</Name>
+    <Description>A positive number indicating the maximum age in milliseconds of a possible cached position that is acceptable to return. If set to 0, it means that the device cannot use a cached position and must attempt to retrieve the real current position. If set to Infinity the device must return a cached position regardless of its age.</Description>
+    <Type>integer</Type>
+    <Label>Maximum Age</Label>
+    <DefaultValue>0</DefaultValue>
+    <IsMandatory>false</IsMandatory>
+  </Parameter>
+</WidgetInfo>



More information about the fusion-commits mailing list