diff options
Diffstat (limited to 'www/js')
-rw-r--r-- | www/js/locate.js | 20 | ||||
-rw-r--r-- | www/js/map-OpenLayers.js | 3 | ||||
-rw-r--r-- | www/js/views/around.js | 30 |
3 files changed, 53 insertions, 0 deletions
diff --git a/www/js/locate.js b/www/js/locate.js index 25853be..7d4c713 100644 --- a/www/js/locate.js +++ b/www/js/locate.js @@ -70,6 +70,26 @@ ); }, + updatePosition: function() { + console.log('updatePosition'); + var that = this; + this.update_watch_id = navigator.geolocation.watchPosition( + function(location) { + if ( that.update_watch_id === undefined ) { console.log( 'no update watch id' ); return; } + + that.trigger('gps_current_position', { coordinates: location.coords } ); + }, + function() {}, + { timeout: 20000, enableHighAccuracy: true } + ); + }, + + stopUpdating: function() { + if ( this.update_watch_id ) { + navigator.geolocation.clearupdate_watch( this.watch_id ); + delete this.update_watch_id; + } + }, check_location: function(coords) { console.log('check_location'); diff --git a/www/js/map-OpenLayers.js b/www/js/map-OpenLayers.js index c4a6d68..34a75a4 100644 --- a/www/js/map-OpenLayers.js +++ b/www/js/map-OpenLayers.js @@ -147,6 +147,9 @@ function fixmystreet_onload() { } fixmystreet.map.addLayer(fixmystreet.markers); + fixmystreet.location = new OpenLayers.Layer.Vector('location'); + fixmystreet.map.addLayer(fixmystreet.location); + if ( fixmystreet.zoomToBounds ) { var bounds = fixmystreet.markers.getDataExtent(); if (bounds) { fixmystreet.map.zoomToExtent( bounds ); } diff --git a/www/js/views/around.js b/www/js/views/around.js index df2c1da..0aa3618 100644 --- a/www/js/views/around.js +++ b/www/js/views/around.js @@ -20,6 +20,7 @@ FMS.locator.on('gps_located', this.showMap, this ); FMS.locator.on('gps_failed', this.noMap, this ); FMS.locator.on('gps_locating', this.locationUpdate, this); + FMS.locator.on('gps_current_position', this.positionUpdate, this); FMS.locator.geolocate(100); this.startLocateProgress(); @@ -72,6 +73,35 @@ ); fixmystreet.map.panTo(centre); } + FMS.locator.updatePosition(); + }, + + positionUpdate: function( info ) { + var coords = info.coordinates; + var centre = new OpenLayers.LonLat( coords.longitude, coords.latitude ); + + centre.transform( + new OpenLayers.Projection("EPSG:4326"), + fixmystreet.map.getProjectionObject() + ); + + var point = new OpenLayers.Geometry.Point( centre.lon, centre.lat ); + + fixmystreet.location.removeAllFeatures(); + var x = new OpenLayers.Feature.Vector( + point, + {}, + { + graphicZIndex: 3000, + graphicName: 'circle', + strokeColor: '#00f', + strokeWidth: 1, + fillOpacity: 1, + fillColor: '#00f', + pointRadius: 10 + } + ); + fixmystreet.location.addFeatures([ x ]); }, noMap: function( details ) { |