0

I am working on an ArcGIS map. I need to be able to interact with KML layers.

Here is a minimal version of my current code:

map = new Map("map", {
  basemap: "topo",
  center: [-108.663, 42.68],
  zoom: 6
});
parser.parse();

var kmlUrl = "https://dl.dropboxusercontent.com/u/2142726/esrijs-samples/Wyoming.kml";
var kml = new KMLLayer(kmlUrl);
map.addLayer(kml);
kml.on("load", function() {
  console.log("done");
});

Here is a fiddle

I'm looking to achieve something more like this map, which outlines the layer on hover. (This example is from the FeatureLayer class, but my KML is dynamically generated. Is it possible to create a featurelayer dynamically from KML data?)

How can I listen for mouseover on a KML shape?

1 Answer 1

1

I figured it out...

var kmlUrl = "https://dl.dropboxusercontent.com/u/2142726/esrijs-samples/Wyoming.kml";
var kml = new KMLLayer(kmlUrl);
map.addLayer(kml);
kml.on("load", function() {
  var layers = kml.getLayers()  
  layers[0].on("mouse-over", function () {
            alert("mousy bitch");
        });
});

Turns out the KML layer is actually composed of FeatureLayers. The solution is to get the Feature Layers from the KMLLayer wi the getLayers() method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.