diff --git a/Widget.js b/Widget.js index 679e486..e109208 100644 --- a/Widget.js +++ b/Widget.js @@ -47,8 +47,25 @@ define([ } }, + _removeAllLayersExceptBasemap: function(){ + for(var l = this.map.layerIds.length - 1; l>1; l--){ + var lyr = this.map.getLayer(this.map.layerIds[l]); + if(lyr){ + this.map.removeLayer(lyr); + } + } + var f = this.map.graphicsLayerIds.length; + while (f--){ + var fl = this.map.getLayer(this.map.graphicsLayerIds[f]); + if(fl.declaredClass === 'esri.layers.FeatureLayer'){ + this.map.removeLayer(fl); + } + } + }, + startup: function () { this._originalWebMap = this.map.webMapResponse.itemInfo.item.id; + this._removeAllLayersExceptBasemap(); if (this.config.useProxy) { urlUtils.addProxyRule({ urlPrefix: this.config.proxyPrefix, diff --git a/setting/Setting.js b/setting/Setting.js index 5fc0b7e..cc871e4 100644 --- a/setting/Setting.js +++ b/setting/Setting.js @@ -75,8 +75,25 @@ define([ this._initLayersTable(); }, + _removeAllLayersExceptBasemap: function(){ + for(var l = this.map.layerIds.length - 1; l>1; l--){ + var lyr = this.map.getLayer(this.map.layerIds[l]); + if(lyr){ + this.map.removeLayer(lyr); + } + } + var f = this.map.graphicsLayerIds.length; + while (f--){ + var fl = this.map.getLayer(this.map.graphicsLayerIds[f]); + if(fl.declaredClass === 'esri.layers.FeatureLayer'){ + this.map.removeLayer(fl); + } + } + }, + getConfig: function() { this.config.layers.layer = this._getAllLayers(); + this._removeAllLayersExceptBasemap(); console.info(this.config); return this.config; },