AnsweredAssumed Answered

Right to Graphic Layer Return Results

Question asked by jay.kapalczynski on Apr 18, 2020
Latest reply on Apr 20, 2020 by rscheitlin

I am trying to write to a graphic layer with a user map click.  

Using a hit test and allowing the user to click counties in the map and writing them to a graphic layer

these are then seen displayed in the map as the user clicks on them

this seems to work fine

 

 

viewright.on("click", function (evt) {
    viewright.hitTest(evt.screenPoint).then(function (response) {
        var result = response.results[0];                 
        var symbol = {
            type: "simple-fill",  // autocasts as new SimpleFillSymbol()
            color: [51, 51, 204, 0.9],
            style: "solid",
            outline: {
               color: "white",
               width: 1
            }
        };
        var selectionGraphic = result.graphic;
        selectionGraphic.symbol = symbol;
        resultsLayer4.add(selectionGraphic);
    });
});

 

I then have a button that reads the Graphics Layer and tries to return the results.

 

var selectButton1 = document.getElementById("select-by-polygon");

selectButton1.addEventListener("click", function () {
   viewright.whenLayerView(resultsLayer4).then(function (lyrView) {
       lyrView.watch("updating", function (val) {
          if (!val) {
             lyrView.queryFeatures().then(function (results) {
                console.log(results);
             });
          }
       });
   });
});

 

 

 

I am unsure if I am tackling this the right way....

 

I want the user to click the map and select counties and write them to a graphics layer. 

I then need to read this graphics layer and get the unique id of each feature in the graphics layer.

 

 

QUESTIONS:

  1. Am I correctly writing to the Graphics Layer?  Is there a better way to do this?
  2. Is there a better way to query the Graphics Layer to get a list of unique IDs from a Field value?
  3. Is there a way to click on a County that is already in the Graphics Layer and then remove it and have the blue graphic removed?

Outcomes