FeatureLayer bug when removing from map and adding back

703
3
05-04-2012 08:00 AM
ChristianMorin
New Contributor III
I have an application that removes a FeatureLayer from the map using map.removeLayer. Later on I add it back to the map. It shows up on the map, but if I call the featureLayer.selectFeatures on the layer it fails (never calls the callbacks).

Stepping through the API I can see that the private variable _mode on the featureLayer is set to null when the layer is removed from the map, but never re-assigned when put back in the map. The selectFeatures code expects the _mode variable to be set. I believe this is a bug in the API.

Cheers,
Christian.
0 Kudos
3 Replies
derekswingley1
Frequent Contributor
Hi Christian,

Can you provide code to reproduce this?
0 Kudos
JeffPace
MVP Alum
Do you have an Editor dijit associated with this Feature Layer ? I ran into alot troubles with removing and readding a Feature Layer when it was a child of a dijit.

I found that after removing the layer, if i destroyed dijit as well, all my problems went away

so

editorWidget = new esri.dijit.editing.Editor(params,'editorDiv');

//on remove
map.removeLayer(layer);
editorWidget.destroy();

0 Kudos
ChristianMorin
New Contributor III
Hi Derek,
    I've taken the On Demand sample from your site and added 2 buttons. One that will perform a query on the feature layer. The other will remove then add back the layer to the map.

    If you run the query first it will work. Then, if you remove/add the layer from the map, the query will not return at all (not success or failure).

    I've also put some alerts to show what the problem is (the internal _mode property gets cleared in the process of remove/add) and this code fails silently in your API when queryFeatures is called on the feature layer.

Cheers,
Christian.
0 Kudos