Skip to content

Commit

Permalink
new LayerToggle widget
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcgee committed Dec 12, 2016
1 parent e492bf6 commit c62f162
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions widgets/LayerToggle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
define([
'dojo/_base/declare',
'dijit/_WidgetBase',
'dojo/topic',
'dojo/_base/array',
'dojo/_base/lang'
], function (
declare,
_WidgetBase,
topic,
array,
lang
) {
return declare([_WidgetBase], {
map: true,

// array of IDs for layers that can be toggled
layerGroup: [],

// ID of labels layer (if any)
labelsID: null,

postCreate: function () {
this.inherited(arguments);
topic.subscribe('layerControl/layerToggle', lang.hitch(this, function (r) {
if (array.indexOf(this.layerGroup, r.id) >= 0) {
array.forEach(this.layerGroup, lang.hitch(this, function (id) {
if (id !== r.id) {
var lyr = this.map.getLayer(id);
if (lyr) {
lyr.setVisibility(false);
}
}
}));
}
}));
}
});
});

0 comments on commit c62f162

Please sign in to comment.