KMLLayer - override click behavior

948
1
04-26-2013 12:21 PM
DanielWalton
Occasional Contributor
I would like to implement custom behavior when clicking on KML features. I can do this for non-KML feature layers and raster layers, but for some reason KML is giving me fits. The desired click behavior is: 1) I don't want to show a popup (I have accomplished this in a very hacky way with CSS), 2) I would like to query the layer with a buffered point and hand the resulting features to a sidebar component for analysis and display. (I can only accomplish this by clicking near enough to the features to grab them, but if I click on a graphic icon, the event is routed to the invisible infoWindow or whatever.) Is there a way to disconnect the KMLLayer's (and nested layers') onClick event and supply my own event handler?

Thanks,
Dan
0 Kudos
1 Reply
derekswingley1
Frequent Contributor
The easiest way I can think of to do this is to set each feature layer's info template to null. Something like this:

dojo.connect(kml, 'onLoad', function(lyr) {
  // set up event listeners on each layer that makes up the kml layer
  var layers = lyr.getLayers();
  dojo.forEach(layers, function(lyr) {
    lyr.setInfoTemplate(null);
    dojo.connect(lyr, "onClick", function(e) {
      // do your on click stuff here
    });
  });


This works because the map popup (or info window) is driven by whether or not a feature has an info template. if a graphic (or a graphics layer, or a feature layer) doesn't have an info template then no popup will be shown when a graphic (feature) is clicked.
0 Kudos