Select to view content in your preferred language

How to obtain symbology from a KML file

1327
2
07-13-2012 03:22 AM
StephenLead
Honored Contributor
See the simple sample which I made by modifying an Esri sample, which lloads a KML file onto the basemap.

Where is the symbology being defined? If I break around line 38, I can't see where the symbology is specified.

var kmlUrl = 'http://www.ci.redding.ca.us/KML/SacRiverTrail.kml';
    kml = new esri.layers.KMLLayer(kmlUrl);
    map.addLayer(kml);


    dojo.connect(kml, 'onLoad', function(lyr) {
      // Collect the line features from the KML layer
      kmlGeoms = dojo.map(lyr.getLayers()[0].graphics, function(g) {
       //g.symbol is blank, so where is the symbol coming from?
       return g.geometry;
      });


Thanks,
Steve
0 Kudos
2 Replies
derekswingley1
Deactivated User
As you know, the KMLLayer relies on a utility running on arcgis.com to convert a KML file to JSON. This utility reads the symbology from the KML file and creates renderers that are applied to the resulting feature layers. Once you have a reference to your feature layer(s), look at each layer's renderer property. In your example, the layer has a SimpleRenderer so it has a single symbol. Run this in the console after loading your example:

kml.getLayers()[0].renderer.symbol.width;
kml.getLayers()[0].renderer.symbol.color;
kml.getLayers()[0].renderer.symbol.declaredClass;
0 Kudos
StephenLead
Honored Contributor
As you know, the KMLLayer relies on a utility running on arcgis.com to convert a KML file to JSON. This utility reads the symbology from the KML file and creates renderers that are applied to the resulting feature layers.


I didn't actually know that - thanks, it really helps.

Cheers,
Steve
0 Kudos