How can I get the symbol from a FeatureLayer?
I want to use the symbol of a FeatureLayer to symbolize a graphic layer.
2 Answers
in 4.x of our ArcGIS API for JavaScript, its as easy as checking FeatureLayer.renderer.
in 3.x, besides looping through individual graphics, you can also find the renderer documented in the service metadata.
esriRequest({
"url": serviceUrl,
"content": {
"f": "json"
},
"callbackParamName": "callback"
}).
then(function (evt) {
console.log(evt.drawingInfo.renderer);
});
live sample: https://dl.dropboxusercontent.com/u/59331579/js/fl-renderer.html
If your FeatureLayer uses a SimpleRenderer, you may access its symbol with myFeatureLayer.renderer.symbol
.
If not, you have to check the symbol per Graphic. You can either ask its Renderer about the symbol with the getSymbol()
method, or you can iterate over the array of graphics and get the symbol for each one:
var symbols = []
myFeatureLayer.graphics.forEach(function (g) {
symbols.push(g.symbol)
})
If all your graphics have the same symbol, you can grab the first one:
var mySymbol = myFeatureLayer.graphics[0].symbol