Equivalent of "Select Features" and "Map Graphics" in Javascript 4

5186
16
Jump to solution
05-03-2017 11:22 AM
SamuelAbati
New Contributor III

I'm trying to migrate a webapp that was under development in the 3.7 API to use the 4.3 API

The base functionality of the app was that when the user would hold CTRL to click a point feature, it would make a SELECTION_ADD, selecting multiple features.

Also another functionality I can't find is changing the renderer/color of specific features, before I would go into the map graphics and change them directly (although I've found that wasn't the best way), now I'm not sure anymore

Everything gets even harder because I'm not working with FeatureLayer anymore, but instead a WebMap (which is a MapImageLayer)

In the end, my questions sum up to:

1) How to "select features" in a MapImageLayer/SubLayer, or any equivalent to getting the OBJECTID of a clicked feature.

2) How to change the renderer/color of specific features only, in this case would be the clicked features, but there is another case that is through a list of OBJECTIDs, (I believe this could be done by adding graphics on top of the features too, that would be no problem since my app is only for display purposes)

In 3.7 I used the layers events "click" and "selection-complete" to handle the logic, are these events no longer part of the flow of 4.X apps?

Any help as to where start or links to examples would be appreciated.

0 Kudos
16 Replies
JayHill
Occasional Contributor II

Robert

I am getting lyrView.queryFeatures is not a function error.

app.view.whenLayerView(layer)
    .then(function(lyrView) {

app.view.on("click", function(event){
  console.log(event);
  var query = new Query();
  query.geometry = event.mapPoint;
  query.spatialRelationship = "intersects";
  lyrView.queryFeatures(query).then(function(results){
 console.log(results);
   var graphic = new Graphic({
     //gotta set a defined geometry for the symbol to draw
     geometry: results,
     symbol: new SimpleMarkerSymbol({
        //color: [0,255,255],
        style: "circle",
        //size: "18px",
        outline: {
             color: [255,255,0],
             width: 3
        }
   })
 })
});
app.view.graphics.add(graphic);
console.log(graphic);
})
});

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jay,

   What is your layer type?

0 Kudos
JayHill
Occasional Contributor II

MapImageLayer

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jay,

   That is the reason. MapImageLayer view does not have a queryFeatures function.

0 Kudos
JayHill
Occasional Contributor II

Ah ok. I thought this was a solution for using MapImageLayer

Thanks Robert

0 Kudos
NathanielRindlaub
New Contributor III

Jay, did you ever figure out a solution to this for MapImageLayer? I also would like to simulate a click on a mapImageLayer feature...

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

For that you just add a view click event handler and execute an identifytask or a query task for certain layers in th MapImageLayer using the mapPoint as the geometry

0 Kudos