Issues trying to remove a feature layer from the map

349
3
04-07-2014 10:26 AM
MarcusBush
New Contributor
Hello,

I searched this forum and did find a vaguely similar post and tried the solution, unfortunately it did not help me though.  I made sure to make the variable for the feature layer global.

I have a JavaScript application in MVC and am trying to remove a feature layer using "map.removeLayer(nameOfFeatureLayerObject)" and it isn't working for me, the graphics from the layer remain on my map.

I had read that there may be an issue if they are associated with an existing editor or any other widget, and they are.  So, just before the .removeLayer() I have tried .destroy() on the editor and template picker dijits that the layer is being used in, and it still remains.

An important note, these feature layers are brought in using a token, as they are secure.  Could this have something to do with my issue?  Also, this particular app is on 3.5 of the jsapi.

Thanks in advance for any advice.
0 Kudos
3 Replies
RobertoPepato
Occasional Contributor II
Hello,

I searched this forum and did find a vaguely similar post and tried the solution, unfortunately it did not help me though.  I made sure to make the variable for the feature layer global.

I have a JavaScript application in MVC and am trying to remove a feature layer using "map.removeLayer(nameOfFeatureLayerObject)" and it isn't working for me, the graphics from the layer remain on my map.

I had read that there may be an issue if they are associated with an existing editor or any other widget, and they are.  So, just before the .removeLayer() I have tried .destroy() on the editor and template picker dijits that the layer is being used in, and it still remains.

An important note, these feature layers are brought in using a token, as they are secure.  Could this have something to do with my issue?  Also, this particular app is on 3.5 of the jsapi.

Thanks in advance for any advice.


You mention nameOfFeatureLayerObject on your message. What does this variable holds? A layer reference or a string with the layer name?
0 Kudos
MarcusBush
New Contributor
Like this:

var fireFeature0 = new esri.layers.FeatureLayer(fireFeatureUrl0 + "?token=" + editToken, {
        mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
        outFields: ['*']
    });


Then I would use:  map.removeLayer(fireFeature0);

Of course, the Url and editToken are defined above but within the same function that is loading the layer, should they be global also maybe?
0 Kudos
RobertoPepato
Occasional Contributor II
Like this:

var fireFeature0 = new esri.layers.FeatureLayer(fireFeatureUrl0 + "?token=" + editToken, {
        mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
        outFields: ['*']
    });


Then I would use:  map.removeLayer(fireFeature0);

Of course, the Url and editToken are defined above but within the same function that is loading the layer, should they be global also maybe?


Humm.. I don't think so. Are you using a public feature layer? It would be possible to post the full source code so I can reproduce the problem from my end and try some debugging?
0 Kudos