How do I get a Graphic
from the Graphic Layer
like the way one can implement in OpenLayers using getFeatureById()
?
Presently, I am attaching attributes to graphic and then by getting graphic layer by layerId, I loop through all the graphics in that layer until the loop satisfy the condition and returns me the correct Graphic
I am looking for.
So it works in following way,
`//This returns graphics layer from the list of graphics layer
var graphicsLayer = map.getLayer(layerId);
//Not supported by API
//var graphic = graphicsLayer.getGraphic(graphicId);`
`//Current approach
for(i=0;i<graphisLayer.graphics.length;i++){
if(graphisLayer.graphics[i].attribute.fid == myFid){
//Do something with this graphic
break;
}
}`
However, I am seeking another approach.
graphicsLayer.graphics.filter(g=>{g.attributes.fid===myFid})
. Not necessarily better, or faster, but at least shorter. BTW, I wonder if speed is really an issue here. If you have, say, 1000 graphics, looping over that array shouldn't take very long. If you have (much) more graphics, you'll probably experience other issues, such as the actual drawing of those graphics.