Select to view content in your preferred language

How to allow updating attributes automatically and manually with editor widget?

1109
2
Jump to solution
08-30-2018 01:59 PM
ChristinaWong
Occasional Contributor

Hello, I'm trying to create an editing web map that will automatically update the coordinates of an added/moved point and also allow manual edits to other attributes. I was able to get the coordinates to update, based on this code I found on stack exchange.

Below is what I have in my HTML and seems to work whenever I add or move a point.

dojo.forEach(featLayers, function(feature) {
 feature.on("before-apply-edits", updateCoordinates);
 });‍‍‍‍‍‍‍‍‍

function updateCoordinates(evt) {
 var toAdd = evt.adds;
 dojo.forEach(toAdd, function(add) {
 add.attributes.point_y = add.geometry.getLatitude();
 add.attributes.point_x = add.geometry.getLongitude();
 });
 
 var toUpdate = evt.updates;
 dojo.forEach(toUpdate, function(update) {
 update.attributes.point_y = update.geometry.getLatitude();
 update.attributes.point_x = update.geometry.getLongitude();
 }); 
 }‍‍‍‍‍‍‍‍‍‍‍‍‍

However, when I manually type in text for another attribute that is entered during the editing, I get these error messages in the console as shown in the attached graphic. Line #305 in the console refers to the above code line #10 update.attributes.point_y = update.geometry.getLatitude();

The attributes I manually update are not saved most of the time.

Any help is much appreciated!

Tags (1)
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Christina,

   You just simply need to check if the update has geometry before you try and get the lat and lon.

function updateCoordinates(evt) {
 var toAdd = evt.adds;
 dojo.forEach(toAdd, function(add) {
   add.attributes.point_y = add.geometry.getLatitude();
   add.attributes.point_x = add.geometry.getLongitude();
 });
 
 var toUpdate = evt.updates;
 dojo.forEach(toUpdate, function(update) {
   if(update.geometry){
     update.attributes.point_y = update.geometry.getLatitude();
     update.attributes.point_x = update.geometry.getLongitude();
   }
 }); 
}

View solution in original post

2 Replies
RobertScheitlin__GISP
MVP Emeritus

Christina,

   You just simply need to check if the update has geometry before you try and get the lat and lon.

function updateCoordinates(evt) {
 var toAdd = evt.adds;
 dojo.forEach(toAdd, function(add) {
   add.attributes.point_y = add.geometry.getLatitude();
   add.attributes.point_x = add.geometry.getLongitude();
 });
 
 var toUpdate = evt.updates;
 dojo.forEach(toUpdate, function(update) {
   if(update.geometry){
     update.attributes.point_y = update.geometry.getLatitude();
     update.attributes.point_x = update.geometry.getLongitude();
   }
 }); 
}
ChristinaWong
Occasional Contributor

Hi Robert,

Wow! I did what you suggested and everything's working out great now.

Thank you so much!

0 Kudos