[fusion-commits] r2771 - in trunk: text widgets

svn_fusion at osgeo.org svn_fusion at osgeo.org
Tue Aug 27 05:22:40 PDT 2013


Author: jng
Date: 2013-08-27 05:22:39 -0700 (Tue, 27 Aug 2013)
New Revision: 2771

Modified:
   trunk/text/en.json
   trunk/widgets/Geolocation.js
Log:
#579: Geolocation widget improvements:
 - Use the MapMessage for relaying geolocation errors
 - Cache the OpenLayers.Projection for the geolocation position
 - MapMessage warn when the resolved location falls outside the extents or initial view of the map

Modified: trunk/text/en.json
===================================================================
--- trunk/text/en.json	2013-08-27 11:40:25 UTC (rev 2770)
+++ trunk/text/en.json	2013-08-27 12:22:39 UTC (rev 2771)
@@ -82,6 +82,8 @@
 'openStreetMapTransportMap':'Open Street Map (TransportMap)',
 'openStreetMapCycleMap':'Open Street Map (CycleMap)',
 'end': '',
+'currentPositionOutsideInitialView': 'Your position is outside of the initial view of the map',
+'currentPositionOutsideMaxExtent': 'Your position is outside of the maximum extent of the map',
 'measureInProgress':'Measurement is currently in progress',
 'selectPolygonPrompt':'Click to add a vertex to the selection polygon. Double click to complete the polygon and select all features with it',
 'selectRadiusPrompt':'Click and drag to the desired radius to select'

Modified: trunk/widgets/Geolocation.js
===================================================================
--- trunk/widgets/Geolocation.js	2013-08-27 11:40:25 UTC (rev 2770)
+++ trunk/widgets/Geolocation.js	2013-08-27 12:22:39 UTC (rev 2771)
@@ -39,6 +39,7 @@
     bEnableHighAccuracy: false,
     nTimeout: 5000,
     nMaximumAge: 0,
+    geoProj: null,
 
     initializeWidget: function(widgetTag) {
         var json = widgetTag.extension;
@@ -62,11 +63,11 @@
         //Maybe use MapMessage for non-intrusive error display?
         switch(error.code) {
             case 1: //Permission denied
-                alert(error.message);
+                this.getMap().message.error(error.message);
             case 2: //Position unavailable
-                alert(error.message);
+                this.getMap().message.error(error.message);
             case 3: //Timeout
-                alert(error.message);
+                this.getMap().message.error(error.message);
             default:
                 console.error("Error with geolocation: (" + error.code + ") " + error.message);
         }
@@ -76,12 +77,25 @@
         var mapWidget = this.getMap();
         var olMap = mapWidget.oMapOL;
         
-        var geoProj = new OpenLayers.Projection("EPSG:4326");
+        if (this.geoProj == null)
+            this.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);
+        lonlat.transform(this.geoProj, mapProj);
         
+        var msg = null;
+        if (!mapWidget.initialExtents.contains(lonlat)) {
+            msg = OpenLayers.i18n("currentPositionOutsideInitialView");
+        } else if (!olMap.maxExtent.contains(lonlat)) {
+            msg = OpenLayers.i18n("currentPositionOutsideMaxExtent");
+        }
+        if (msg != null) {
+            var msgbar = this.getMap().message;
+            msgbar.warn(msg);
+            setTimeout(function() { msgbar.hideDesignatedMessage(msg); }, 5000);
+        }
+
         if (this.nZoom == null) {
             olMap.moveTo(lonlat);
         } else {



More information about the fusion-commits mailing list