1

I am trying to remove a layer from the mapView.

var LayertoRemove=map.findLayerById(layerID);
map.remove(LayertoRemove);

The layer is found and is actually removed, but after it's removed it continues to throw TypeError: this.controller.destroy is not a function, and the rest of the script is not run. when I remove these two lines of code, the script works fine.

the error in the console is pointing to MapView.js of the API and not to any line in my script. Any suggestions on what is going wrong here?

Update1: The FeatureLayers that I am trying to remove are not hosted layers, but generated from client-side geometries (graphics are created from two csv files taken from the client); I suspect that the error is happening because the setting of one of the properties of the layer -- which I need to set when the layer is created.

Update2: the full error log is:

 Uncaught TypeError: this.controller.destroy is not a function   MapView.js:510 
    at Object.d.detach (MapView.js:510)
    at Object.update (MapView.js:25)
    at k._animationFrame (init.js:329)

Update3: I am now almost sure that the issue is related to my featurelayer properties, as when I try map.remove with a hosted featurelayer, it works fine. The featurelayers are generated as follows:

function createLayer(graphics,renderer,type,fields,title){
          lyr = new FeatureLayer({
            source: graphics, //an array of esri/Graphic
            fields:fields,
            objectIdField: "ObjectID", 
            renderer:renderer,
            spatialReference: {wkid: 4326},
            geometryType: type, 
            title:title,
            id:title
          });
          map.add(lyr);
    } 
4
  • What type of object is "map"?
    – TJBara
    May 5, 2017 at 20:54
  • it's a MapView instance May 5, 2017 at 22:13
  • show here the whole error
    – Spring
    May 7, 2017 at 14:32
  • I updated my post and included the whole error May 7, 2017 at 15:21

1 Answer 1

1

Are you sure your "map" variable is a MapView and not a Map class? The add, remove and findLayerById properties are properties on the Map class (not MapView). https://developers.arcgis.com/javascript/latest/api-reference/esri-Map.html#methods-summary https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#methods-summary

The 4.x and 3.x versions are different in this aspect. https://developers.arcgis.com/javascript/latest/guide/migrating/index.html#views

2
  • you are right. it's an instance of the Map class. I am contemplating between deleting this question or edit it significantly. Because after doing further debugging, I realized although the error is somehow related to the map.remove, it doesn't occur when map.remove is executed. And I am not able to point exactly where the error is occurring (in the console, the error is not pointed to any line of my code, an it's in API codes, and I wasn't able to trace that back). May 22, 2017 at 0:36
  • Probably better to create a new question... May 22, 2017 at 1:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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