How do you get the renderer from a feature layer?
I want to get the current rendered from a feature layer, and then set the RotationInfo on it so I can rotate my graphics that are in that feature service.
Morgan,
Here is a simple sample.
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"> <title>Feature Layer Only Map</title> <link rel="stylesheet" href="http://js.arcgis.com/3.13/esri/css/esri.css"> <style> html, body, #map { height: 100%; width: 100%; margin: 0; padding: 0; } </style> <script src="http://js.arcgis.com/3.13/"></script> <script> require([ "dojo/dom-construct", "esri/map", "esri/layers/FeatureLayer", "esri/geometry/Extent", "esri/InfoTemplate", "dojo/domReady!" ], function( domConstruct, Map, FeatureLayer, Extent, InfoTemplate ) { var bounds = new Extent({ "xmin":-16045622, "ymin":-811556, "xmax":7297718, "ymax":11142818, "spatialReference":{"wkid":102100} }); var map = new Map("map", { extent: bounds }); var url = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/WorldTimeZones/MapServer/2"; var template = new InfoTemplate("World Regions", "Region: ${REGION}"); var fl = new FeatureLayer(url, { id: "world-regions", infoTemplate: template }); fl.on('load', function(evt){ console.info(evt.target.renderer); }); map.addLayer(fl); } ); </script> </head> <body> <div id="map"></div> </body> </html>
Robert,
does this solution works only with simple symbology?
I tried this with my current code and it returned the same result i have here:
renderer from an existing service fails to return the full symbology
with the symbology as you can see in the pictures not fully operational when its "complicated".
any ideas?
Robert, that worked perfectly.
Thanks.
When are you trying to get the renderer? You're probably trying to access it before it's ready. Try setting that after the FeatureLayer's load event fires.
I've tried that, it is null every time. Or am I looking at it at the wrong time?
The renderer is a property of the featureLayer so:
var theRenderer = theLayer.renderer;
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.