is it possible to remove a map service (or single layer) from the layer list?
It seems to me that in the WAB previous version this option was avaiable in the layer list widget.
Thank you
Enrico
Solved! Go to Solution.
Robert, we need to distinguish the mapservice element (father) from its single layers because the remove option seems to work only on the entire map service element.
The only way that we found to distinguish form these two cases was to count the options shown in layer list if the elementi is a map service (5 options) or a single layer (only 3).
Maybe there is a cleaver way but we haven't found it...
Here the images from previous post.
Options in layerlist:
ERROR
Enrico,
OK to add the remove layer option to only root layers you need to make these changes:
PopupMenuInfo.js (i.e. lines 24- 28, 51 - 55, 66 - 70):
clazz.create = function(layerInfo, layerListWidget) {
var retDef = new Deferred();
var isRootLayer = layerInfo.isRootLayer();
var defaultItemInfos = [{
key: 'url',
onClick: null
}];
var itemInfoCategoreList = {
'RootLayer': [{
key: 'zoomto'
}, {
key: 'transparency'
}, {
key: 'separator'
}, {
key: 'moveup'
}, {
key: 'movedown'
}, {
key: 'separator'
}, {
key: 'url'
}, {
key: 'separator'
}, {
key: 'removelayer'
}],
'RootLayerAndFeatureLayer': [{
key: 'zoomto'
}, {
key: 'transparency'
}, {
key: 'separator'
}, {
key: 'controlPopup'
}, {
key: 'separator'
}, {
key: 'moveup'
}, {
key: 'movedown'
}, {
key: 'separator'
}, {
key: 'table'
}, {
key: 'separator'
}, {
key: 'url'
}, {
key: 'separator'
}, {
key: 'removelayer'
}],
'FeatureLayer': [{
key: 'controlPopup'
}, {
key: 'separator'
}, {
key: 'table'
}, {
key: 'separator'
}, {
key: 'url'
}, {
key: 'separator'
}, {
key: 'removelayer'
}],
'GroupLayer': [{
key: 'url'
}],
'Table': [{
key: 'table'
}, {
key: 'separator'
}, {
key: 'url'
}],
'default': defaultItemInfos
};
PopupMenuInfo.js (lines 25 - 30):
getDeniedItems: function() {
// summary:
// the items that will be denied.
// description:
// return Object = [{
// key: String, popupMenuInfo key,
// denyType: String, "disable" or "hidden"
// }]
var defRet = new Deferred();
var dynamicDeniedItems = [];
if (this.layerListWidget.layerListView.isFirstDisplayedLayerInfo(this._layerInfo)) {
dynamicDeniedItems.push({
'key': 'moveup',
'denyType': 'disable'
});
}
if (this.layerListWidget.layerListView.isLastDisplayedLayerInfo(this._layerInfo)) {
dynamicDeniedItems.push({
'key': 'movedown',
'denyType': 'disable'
});
}
if(this._layerInfo.isLeaf()) {
dynamicDeniedItems.push({
'key': 'removelayer',
'denyType': 'hidden'
});
}
Then remove your addition to the constructor method:
if (l > 5) {
displayItemInfos[l] = { key: 'removelayer' }; //
}
Robert, great!
thank you very much.
We substitute the code and everything works fine .
The error, fotunately visible only looking with firebug (seeprevious image) persists: do you know what it means?
Enrico,
In the PopupMenu.js edit the closeDropMenu method to this:
closeDropMenu: function() {
this.inherited(arguments);
if(this.transparencyDiv){
this.hideTransNode();
}
},
Great! error disappeared
Thank you Robert!
Robert, I'd like to give to the users the option to remove other types of layers, like a csv type.
I make some changes below. Do you see any reasons not to follow this path that are not apparent to me? Thanks.
Removed the "var" on line 3 to make the IsRootLayer a global variable.
clazz.create = function(layerInfo, layerListWidget) {
var retDef = new Deferred();
isRootLayer = layerInfo.isRootLayer();
var defaultItemInfos = [{
key: 'url',
onClick: null
}];
Add the "&& (!isRootLayer) to check if the layer is at the root.
if(this._layerInfo.isLeaf() && (!isRootLayer)) {
dynamicDeniedItems.push({
'key': 'removelayer',
'denyType': 'hidden'
});
}
Nice work and thanks for sharing the code, however, there is a small query that might be a typo, see image below:
Yes It was an error due to cut&paste...Thank you
Enrico & Manuela