| function initFunc(map) { | |
| |
| var startPos; |
| |
| if( navigator.geolocation ) { |
| navigator.geolocation.getCurrentPosition(zoomToLocation, locationError); |
| watchId = navigator.geolocation.watchPosition(showLocation, locationError); |
| } else { |
| alert("Browser doesn't support Geolocation. Visit http://caniuse.com to see browser support for the Geolocation API."); |
| } |
| } |
| |
| function locationError(error) { |
| //error occurred so stop watchPosition |
| if( navigator.geolocation ) { |
| navigator.geolocation.clearWatch(watchId); |
| } |
| switch (error.code) { |
| case error.PERMISSION_DENIED: |
| alert("Location not provided"); |
| break; |
| |
| case error.POSITION_UNAVAILABLE: |
| alert("Current location not available"); |
| break; |
| |
| case error.TIMEOUT: |
| alert("Timeout"); |
| break; |
| |
| default: |
| alert("unknown error"); |
| break; |
| } |
| } |
| var positionLayerURL = "http://services1.arcgis.com/i9MtZ1vtgD3gTnyL/arcgis/rest/services/OMLETH_Trackers_20150505/FeatureServer/0"; |
| |
| var positionLayer = new FeatureLayer(positionLayerURL, |
| {mode: FeatureLayer.MODE_ONDEMAND, |
| outFields: ["*"] |
| } |
| ); |
| |
| |
| |
| |
| |
| function zoomToLocation(location) { |
| |
| startPos = location; |
| var pt = new Point(location.coords.longitude, location.coords.latitude); |
| dojo.byId("startLat").innerHTML = location.coords.latitude; |
| dojo.byId("startLon").innerHTML = location.coords.longitude; |
| addGraphic(pt); |
| map.centerAndZoom(pt, 12); |
| } |
| |
| function showLocation(location) { |
| //zoom to the users location and add a graphic |
| var pt = new Point([location.coords.longitude, location.coords.latitude],new SpatialReference({ wkid:4326 })); |
| var graphic = new Graphic(pt); |
| |
| if ( !graphic ) { |
| addGraphic(pt); |
| |
| |
| |
| |
| } else { // move the graphic if it already exists |
| graphic.setGeometry(pt); |
| |
| console.log(positionLayer); |
| console.log(graphic); |
| console.log(positionLayerURL); |
| |
| //applyEdits |
| positionLayer.applyEdits([graphic],null, null, function(){ |
| console.log("updateXY"); |
| |
| }, function(){ |
| alert("An error occured during update."); |
| }); |
| |
| |
| } |
| map.centerAt(pt); |