Highlighting multiple feature layer geometries

1306
3
Jump to solution
01-06-2012 11:33 PM
EdSaunders
Occasional Contributor
Hi all,

I am displaying multiple feature layers in my app and would like to highlight the geometry onmouseover for whichever layers are visible at any one time.  Does anyone know how to adapt the following code for use with multiple feature layers:

dojo.connect(map,"onClick",function(evt){
  var query = new esri.tasks.Query();
  query.geometry = pointToExtent(map,evt.mapPoint,10);
 
  var deferred = featureLayer.selectFeatures(query,esri.layers.FeatureLayer.SELECTION_NEW);

   map.infoWindow.setFeatures([deferred]);
   map.infoWindow.show(evt.mapPoint);
   
});

I've tried using an array but that doesn't work.  Related question - the above function works when clicking the map but does anyone know how to achieve the same but only clicking on the feature layer?

Thanks in advance for any help.
0 Kudos
1 Solution

Accepted Solutions
StephenLead
Regular Contributor III
when I hide the feature layer the dojo.connect function is no longer available so I don't have to disconnect it.  Either that or I'm propagating memory leaks ; )


That's a question for someone from Esri I guess. I'd say that if you're running code to hide the layer, it's no big deal to switch off the listener at the same time, so you might as well....

Can I use arrays to streamline the code (obviously using more than one feature layer), like the following:

 dojo.connect(wfLayers, "onMouseOver", function(evt) {




As before, I think you'll need to run a for each loop and set this for each layer individually - there's no mechanism to set the onMouseOver listener directly on an array of layers, to my knowledge.

Cheers,
Steve

View solution in original post

0 Kudos
3 Replies
StephenLead
Regular Contributor III
Hi Ed,

highlight the geometry onmouseover for whichever layers are visible at any one time... the above function works when clicking the map but does anyone know how to achieve the same but only clicking on the feature layer?


Set up dojo.connect each time a layer is switched on, at the layer level.

If you save this to a variable, you can use

dojo.disconnect when the layer is switched off.

//When the layer is switched on:
var1 = dojo.connect(layer1, "onClick"....)

//When the layer is switched off:
dojo.disconnect(var1)


Cheers,

Steve
0 Kudos
EdSaunders
Occasional Contributor
Steve, thanks again for the suggestions, much appreciated.  I'm using your suggestion that sets up an onMouseOver when I declare the feature layer.  Happily when I hide the feature layer the dojo.connect function is no longer available so I don't have to disconnect it.  Either that or I'm propagating memory leaks ; )

 
dwfLayer = new esri.layers.FeatureLayer(dwfLayerUrl, {
  mode : esri.layers.FeatureLayer.MODE_ONDEMAND,
  infoTemplate : template,
  outFields : ["*"],
});
dojo.connect(dwfLayer, "onMouseOver", function(evt) {
  map.setMapCursor("pointer");
  highlightPointLayer.clear();
  highlightPointLayer.add(new esri.Graphic(evt.graphic.geometry));
});


Can I use arrays to streamline the code (obviously using more than one feature layer), like the following:

var wfLayers = []; 
dwfLayer = new esri.layers.FeatureLayer(dwfLayerUrl, {
  mode : esri.layers.FeatureLayer.MODE_ONDEMAND,
  infoTemplate : template,
  outFields : ["*"],
});
wfLayers.push(dwfLayer);
dojo.connect(wfLayers, "onMouseOver", function(evt) {
  map.setMapCursor("pointer");
  highlightPointLayer.clear();
  highlightPointLayer.add(new esri.Graphic(evt.graphic.geometry));
});


Thanks heaps.
0 Kudos
StephenLead
Regular Contributor III
when I hide the feature layer the dojo.connect function is no longer available so I don't have to disconnect it.  Either that or I'm propagating memory leaks ; )


That's a question for someone from Esri I guess. I'd say that if you're running code to hide the layer, it's no big deal to switch off the listener at the same time, so you might as well....

Can I use arrays to streamline the code (obviously using more than one feature layer), like the following:

 dojo.connect(wfLayers, "onMouseOver", function(evt) {




As before, I think you'll need to run a for each loop and set this for each layer individually - there's no mechanism to set the onMouseOver listener directly on an array of layers, to my knowledge.

Cheers,
Steve
0 Kudos