You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@tmcgee Used your new Legend.js code as base and changed the code LayerControl.js a little, now we can have this function: if user adds a layer using DnD widget, the legend should show up in the Legend widget too, if user removes it, the legend is also removed from the Legend widget.
The Change in the LayerControl.js is the following, I am not sure if this is needed or not ( i did not use that this.layerInfos, i am afraid it may break other thing). Please review it.
var layerInfosAdded; //declared a new variable,
in postCreate function I do
layerInfosAdded = this.layerInfos;
// the main code is in the following function
_subscribeToTopics: function () {
this._removeLayerControlsHandler = topic.subscribe('layerControl/removeLayerControls', lang.hitch(this, function (layers) {
this._removeLayerControls(layers);
//console.log(layers);
var index=-1;
for (var i=0; i<layerInfosAdded.length; i++)
{
// console.log(layers[0].id);
// console.log(window.layerInfosAdded[i].layer.id);
if (layers[0].id === layerInfosAdded[i].layer.id)
{
index = i;
break;
}
}
if (index > -1)
{
layerInfosAdded.splice(index, 1);
topic.publish('LayerControl/refreshLegend', {layerInfos:layerInfosAdded});
}
}));
this._addLayerControlsHandler = topic.subscribe('layerControl/addLayerControls', lang.hitch(this, function (layerInfos) {
this._addLayerControls(layerInfos);
layerInfosAdded.push(layerInfos[0]);
topic.publish('LayerControl/refreshLegend', {layerInfos:layerInfosAdded});
}));
},
For the Legend.js, i have to change it otherwise the topic call throws scoping error for the legend object.
define([
'dojo/_base/declare',
'dijit/_WidgetBase',
'dojo/_base/lang',
'esri/dijit/Legend',
'dojo/topic'
], function (
declare,
_WidgetBase,
lang,
Legend,
topic
) {
var legend;
return declare([_WidgetBase], {
startup: function () {
this.inherited(arguments);
@tmcgee Used your new Legend.js code as base and changed the code LayerControl.js a little, now we can have this function: if user adds a layer using DnD widget, the legend should show up in the Legend widget too, if user removes it, the legend is also removed from the Legend widget.
The Change in the LayerControl.js is the following, I am not sure if this is needed or not ( i did not use that this.layerInfos, i am afraid it may break other thing). Please review it.
var layerInfosAdded; //declared a new variable,
in postCreate function I do
// the main code is in the following function
For the Legend.js, i have to change it otherwise the topic call throws scoping error for the legend object.
define([
'dojo/_base/declare',
'dijit/_WidgetBase',
'dojo/_base/lang',
'esri/dijit/Legend',
'dojo/topic'
], function (
declare,
_WidgetBase,
lang,
Legend,
topic
) {
var legend;
return declare([_WidgetBase], {
startup: function () {
this.inherited(arguments);
});
Very last change is in the config file, we use the gis instead of esri.
Please review the logic and refine it.
My test works just fine.
Thanks.
The text was updated successfully, but these errors were encountered: