Create a gist now

Instantly share code, notes, and snippets.

ArcGIS JSAPI Hack: LayerList fixes
define([
"dojo/_base/declare",
"dojo/_base/array",
"dojo/query",
"put-selector/put",
"esri/dijit/LayerList"
], function (declare, arrayUtils, dojoQuery, put, LayerList) {
return declare([LayerList], {
_baseCheckTemplate: ["<div class='esriTitle'><div class='esriTitleContainer'>",
"<input class='esriCheckbox' type='checkbox' checked='checked' id='adsfkja982djhk2uh2kjhf2df92' />",
"<label class='esriLabel' for='adsfkja982djhk2uh2kjhf2df92'>{{baseLayerTitle}}</label></div></div>"].join(""),
startup: function () {
var baseLayerNode, baseLayer, baseLayerIsShown, baseLayerTitle;
this.inherited(arguments);
baseLayer = this.map.getLayer(this.map.layerIds[0]);
baseLayerIsShown = arrayUtils.some(this.layers, function (layer) {
return layer.id === baseLayer.id;
});
if (!baseLayerIsShown) {
baseLayerTitle = this.params.basemapTitle || baseLayer.name || (baseLayer.arcgisProps && baseLayer.arcgisProps.title) || baseLayer.id.replace(/_+\d+$/, "");
baseLayerNode = put(this._layersNode, "li.esriLayer");
baseLayerNode.innerHTML = this._baseCheckTemplate.replace("{{baseLayerTitle}}", baseLayerTitle);
dojoQuery("input[type=checkbox]", baseLayerNode).on("click", function (evt) {
var checkBox = evt.target;
var layer = this.map.getLayer(this.map.layerIds[0]);
layer.setVisibility(checkBox.checked);
evt.stopPropagation();
}.bind(this));
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment