Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Grouped layers w/ layers reversed
startup: function() {
this.inherited(arguments);
NlsStrings.value = this.nls;
// summary:
// this function will be called when widget is started.
// description:
// according to webmap or basemap to create LayerInfos instance
// and initialize operLayerInfos;
// show layers list;
// bind events for layerLis;
if (this.map.itemId) {
LayerInfos.getInstance(this.map, this.map.itemInfo)
.then(lang.hitch(this, function(operLayerInfos) {
this.operLayerInfos = operLayerInfos;
//begin grouping feature layers for rooms and labels
var firstFloorLayers = [], secondFloorLayers = [], thirdFloorLayers = [];
array.forEach(this.operLayerInfos.getLayerInfoArray(), function(layerInfo) {
//get the original layer title and add it to the new sublayer title
layerInfo.layerObject.title = layerInfo.title;
if(layerInfo && layerInfo.title.substr(0, 5) === "First"){
firstFloorLayers.push(layerInfo.layerObject);
this.map.removeLayer(layerInfo.layerObject);
}
if(layerInfo && layerInfo.title.substr(0, 5) === "Secon"){
secondFloorLayers.push(layerInfo.layerObject);
this.map.removeLayer(layerInfo.layerObject);
}
if(layerInfo && layerInfo.title.substr(0, 5) === "Third"){
thirdFloorLayers.push(layerInfo.layerObject);
this.map.removeLayer(layerInfo.layerObject);
}
}, this);
firstFloorLayers.reverse();
secondFloorLayers.reverse();
thirdFloorLayers.reverse();
this.operLayerInfos.addFeatureCollection(firstFloorLayers, "1st Floor");
this.operLayerInfos.addFeatureCollection(secondFloorLayers, "2nd Floor");
this.operLayerInfos.addFeatureCollection(thirdFloorLayers, "3rd Floor");
// end of code to group layers
this.showLayers();
this.bindEvents();
dom.setSelectable(this.layersSection, false);
}));
} else {
var itemInfo = this._obtainMapLayers();
LayerInfos.getInstance(this.map, itemInfo)
.then(lang.hitch(this, function(operLayerInfos) {
this.operLayerInfos = operLayerInfos;
this.showLayers();
this.bindEvents();
dom.setSelectable(this.layersSection, true);
}));
};
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment