Select to view content in your preferred language

Accessing Graphics on a Map in 4.0Beta

2345
3
02-26-2016 07:02 AM
lanceweaver
Occasional Contributor

I can't seem to access the graphics on the Map in 4.0Beta.

In the documentation, it says graphics are no longer stored in 'map' or 'featureLayer', but "as graphics inside a LayerView"

But I can't seem to get View.getLayerView() or any other construct to work in order to access the graphics in my featureLayer loaded from Arc Server.

I don't even see them in the console under console.log(view.layerViews.item[]...)

Can someone show me just a simple example of how to access the graphics on a map?

Tags (3)
0 Kudos
3 Replies
lanceweaver
Occasional Contributor

Just to clarify, I'm hoping to loop through the graphics to modify them (like the old API did with "map.graphics", perhaps with something like this....

var mapgraphics = view.getLayerView(myFeatureLayer);

dojo.forEach(mapgraphics, function(g){

       //console.log(g);

      if (g.attributes.pub_title == var"){ change style };

});

Right now I can't even find a way to access graphics when clicking them ---like the old

view.on("click", function(evt) {

  graphic = evt.graphic

});

help please...

0 Kudos
ReneRubalcava
Esri Frequent Contributor

Here is a sample showing how to get the graphics with a LayerView.

JS Bin - Collaborative JavaScript Debugging

I don't think you can style the graphic in place though, you may need to use graphic.clone() and apply a new symbol and add it to the map.graphics layer.

0 Kudos
lanceweaver
Occasional Contributor

That example returns graphics properties only in MapView  (and even then only .length is available... the geometry and attributes seem to be private and inaccessible)

I need to access map graphics in SceneView.  Is there ANY native way to do this?  Will a getter function be available in the official release?

using getCanvas3DGraphics() or something?

I'd rather not hit the server with a query/identifyTask when the info from the featureclass is already on the map.

Something like,

var fLayerView;

view.on("layer-view-create", function(evt) { //unlike view.then, this fires as EACH layer is converted to a layerview

  if (evt.layer.id === "myFeatureClassId") {

    var fLayerView = evt.layerView;

    var graphics = fLayerView.getCanvas3DGraphics();

    graphics.forEach(function(item, i){

         console.log(item+", "+i);

        //get attributes for custom mouse-over events or custom search

    });

  }

});

0 Kudos