update point location (geometry) in code

794
2
02-13-2012 08:24 AM
JaredAllen
New Contributor
i would like to enable an "easy button" which will enable field users the ability to move an existing point feature to their device gps location.

essentially, there is a button, "update location" which will update the selected feature's location/geometry and set it's x,y to the user's device x,y.

code is as follows... (however, this does not actually update the selected features geometry, any suggestions?)

var moveButton = new dijit.form.Button({
label : "Update Location",
"class" : "saveButton"
});

dojo.place(moveButton.domNode, attInspector.deleteBtn.domNode, "after");

dojo.connect(moveButton, "onClick", function() {
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
myGPS = esri.geometry.geographicToWebMercator(new esri.geometry.Point(position.coords.longitude, position.coords.latitude));
var newGraphic = new esri.Graphic(myGPS, null, null);
updateFeature.geometry = newGraphic.geometry; <<---- the money code line here
}, function(error) {
HideProgressIndicator();
switch (error.code) {
case error.TIMEOUT:
alert('Timeout');
break;
case error.POSITION_UNAVAILABLE:
alert('Position unavailable');
break;
case error.PERMISSION_DENIED:
alert('Permission denied');
break;
case error.UNKNOWN_ERROR:
alert('Unknown error');
break;
}
});
} else {
alert('Browser does not support GeoLocation');
}
updateFeature.getLayer().applyEdits(null, [updateFeature], null);
HideServiceRequestContainer();
reloadLayers(); //to remove/reload layers to overcome the iPad graphics cache issue
});
0 Kudos
2 Replies
derekswingley1
Frequent Contributor
Where is updateFeature defined?

Rather than setting the feature's geometry directly, try calling update and passing in the new X and Y.
0 Kudos
JaredAllen
New Contributor
i would like to enable an "easy button" which will enable field users the ability to move an existing point feature to their device gps location. 

essentially, there is a button, "update location" which will update the selected feature's location/geometry and set it's x,y to the user's device x,y. 

code is as follows... (however, this does not actually update the selected features geometry, any suggestions?) 

var moveButton = new dijit.form.Button({ 
label : "Update Location", 
"class" : "saveButton" 
}); 

dojo.place(moveButton.domNode, attInspector.deleteBtn.domNode, "after"); 

dojo.connect(moveButton, "onClick", function() {  
if(navigator.geolocation) { 
navigator.geolocation.getCurrentPosition(function(position) { 
myGPS = esri.geometry.geographicToWebMercator(new esri.geometry.Point(position.coords.longitude, position.coords.latitude)); 
var newGraphic = new esri.Graphic(myGPS, null, null); 
   updateFeature.geometry = newGraphic.geometry; <<---- the money code line here 
}, function(error) { 
HideProgressIndicator(); 
switch (error.code) { 
case error.TIMEOUT: 
alert('Timeout'); 
break; 
case error.POSITION_UNAVAILABLE: 
alert('Position unavailable'); 
break; 
case error.PERMISSION_DENIED: 
alert('Permission denied'); 
break; 
case error.UNKNOWN_ERROR: 
alert('Unknown error'); 
break; 

}); 
} else { 
alert('Browser does not support GeoLocation'); 

updateFeature.getLayer().applyEdits(null, [updateFeature], null); 
HideServiceRequestContainer(); 
reloadLayers(); //to remove/reload layers to overcome the iPad graphics cache issue 
});


updateFeature is set to each currently selected feature.

i've attempted the .update() method but the result gives no errors and no visible adjustment of actual feature geometry.
0 Kudos