Show dynamically selected polygons editable when click on map and save all of them

180
12
Jump to solution
03-12-2020 06:08 AM
Highlighted
Occasional Contributor II

Currently, I am showing dynamic polygon on click of map by getting its lat long but  i  also want to show them editable.

Query: do reshape stop method get geometry of all polygons appeared dynamically or is their any other way to store ring coordinates of all dynamically appeared polygons.

Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
MVP Esteemed Contributor

Rajni,

   So do you get anything in the console for this portion of your code above?

Also notice that I added gra.geometry in case that is the simple issue you are having.

          graphicsLayer.graphics.map(function(gra){
//do something with the gra (graphic)
console.log("====>");
console.log(gra.geometry);
});

View solution in original post

12 Replies
Highlighted
MVP Esteemed Contributor

Rajni,

do reshape stop method get geometry of all polygons appeared dynamically or is their any other way to store ring coordinates of all dynamically appeared polygons.

No, the reshape stop is only for the One graphic that is being updated. 

To get the rings of all the graphics in a GraphicsLayer you have to loop through the graphics property of the GraphicsLayer to get all the Graphics.

graphicsLayer.graphics.map(function(gra){
//do something with the gra (graphic)
});
Highlighted
Occasional Contributor II

==>I couldn't find the path of rings in the object returned in console like i have been getting in object reshape event below.

=======>

//listen to reshape-stop event get updated geometry pylgon vertics and pass through ajax         
              /*const eventInfo = event.toolEventInfo;
                  if (eventInfo && eventInfo.type.includes("reshape")) {
                    if(eventInfo.type=='reshape-stop'){
                       var updatedGeometry= webMercatorUtils.webMercatorToGeographic(event.graphics[0].geometry);
                       rings = updatedGeometry.__accessor__.store._values.rings;
                    }
                  }*/

When i go to accessor->store->values-> . It have more geometry attributes and have no ring coordinates.  Whereever i find the ring parameter in console, it contains different value.

==>Whenever a new polygon appeared on click or when i click on screen it after clear all do not return any object and before click on clearall return objects which do not have any rings value

Kindly help me to get latest rings(either reshape or updated) of all polygons that appear on screen.

Also how to make them editable.

I have been trying to console rings here:

======>

function onGraphicUpdate(event) {
          // get the graphic as it is being updated
          const graphic = event.graphics[0]; //Do i need to perform loop over

          // check if the update event's the toolEventInfo.type is move then stop move event
          if (event.toolEventInfo && event.toolEventInfo.type.includes("move")){
          sketchViewModel.cancel();
            }
            // If toolEventInfo.type is reshape-stop then it means user finished moving or reshaping the graphic, call complete method. This will change update event state to complete and we will check the validity of the graphic location.
          if (
            event.toolEventInfo &&
            (event.toolEventInfo.type === "move-stop" ||
              event.toolEventInfo.type === "reshape-stop")
          ) {
              sketchViewModel.complete();
          } else if (event.state === "cancel" || event.state === "complete") {
            //check if the graphics are done being reshaped, printout updated graphic's geometry and reshape stage.           
            // graphic  reshaping has been completed or cancelled
              sketchViewModel.update([graphic], { tool: "reshape" });
          }else {
          graphic.symbol = validSymbol;
        }

          graphicsLayer.graphics.map(function(gra){
             //do something with the gra (graphic)
             console.log("====>");
             console.log(gra);
          });
 
        }

Reply
0 Kudos
Highlighted
MVP Esteemed Contributor

Rajni,

   So do you get anything in the console for this portion of your code above?

Also notice that I added gra.geometry in case that is the simple issue you are having.

          graphicsLayer.graphics.map(function(gra){
//do something with the gra (graphic)
console.log("====>");
console.log(gra.geometry);
});

View solution in original post

Highlighted
MVP Esteemed Contributor

Rajni,

Which makes perfect sense based on your code. Your are looping through the graphics (this is what graphicsLayer.graphics.map(function(gra){ means, map is a looping function on an array) and setting the var rings to the graphics rings (though I am not sure why you are using internal properties like .__accessor__.store._values.rings instead of just updatedGeometry.rings). But each loop through overwrites the rings variable so by the time you get to your ajax call you only have the last ring data.

Highlighted
Occasional Contributor II

Hi rob finally i able to save and display all rings but they do not appear editable when they first appear, i have to click them to make them editable.

Reply
0 Kudos
Highlighted
Occasional Contributor II

Hi Rob,

Can you please tell me how to make it editable when it first appear, IT IS THE LAST TASK OF POLYGONS, JUST TO MAKE THEM EDITABLE WHEN THEY APPEAR AUTOMATICALLY.

Reply
0 Kudos
Highlighted
MVP Esteemed Contributor

Rajni,

  Did I not show you how to start editing a graphic in one of your previous threads? It is simply sketchViewModel.update([your graphic], {tool: "reshape"});

Highlighted
MVP Esteemed Contributor

Rajni,

   This is by design. You can only have ONE polygon editing in the reshape mode.

Highlighted
Occasional Contributor II

Is their any other way to make all polygons appear editable everytime, even when i automatically appear on map on click first time

Reply
0 Kudos