I'm having an issue with the legend widget updating. I have an application that is a floorplan for the courthouse I work in. The user clicks a select box and chooses the Basement floor and the legend is populated correctly. Then if the user clicks the first floor, the legend widget doesn't update with this code and still contains the information from the Basement floor. What is wrong with this code? How do I disconnect the listener from one "If" statement, and listen instead to the other "If" statement? I've tried dojo.disconnect. I've tried to destroy the widget and re-create it. Plus other things to no avail. Thanksfunction floorSearch() {
if (searchEngine == 1 && mechBox.checked == false) {
map.removeAllLayers();
if (map.graphics != null) {map.graphics.clear();}
if (floorclickCounter == 1) { dojo.disconnect(floorClick); }
map.infoWindow.resize(300, 160);
basementService = new esri.layers.ArcGISDynamicMapServiceLayer("http://gisv/ArcGIS/rest/services/CourtHouseFloorPlan/Basement/MapServer", {
id: "basementService"
});
map.addLayer(basementService);
//define a popup template
var popupTemplate = new esri.dijit.PopupTemplate({
title: "{Room_Name}",
fieldInfos: [
{ fieldName: "Room_Name", visible: true, label: "Room Name" },
{ fieldName: "Room_Num", visible: true, label: "Room Number" }
],
showAttachments: true
});
floorLayer = new esri.layers.FeatureLayer("http://gisv/ArcGIS/rest/services/CourtHouseFloorPlan/Basement/MapServer/0", {
id: "basement",
infoTemplate: popupTemplate,
opacity: .2,
mode: esri.layers.FeatureLayer.MODE_SELECTION,
outFields: ["Room_Name", "Room_Num", "Plan_Num"]
});
floorClick = dojo.connect(floorLayer, "onClick", function (evt) {
map.infoWindow.setFeatures([evt.graphic]);
map.infoWindow.show(evt.mapPoint);
floorclickCounter = 1;
});
legendLayers.push({ layer: floorLayer, title: 'BASEMENT' });
legendConnect = dojo.connect(map, 'onLayersAddResult', function (results) {
legend = new esri.dijit.Legend({
map: map,
layerInfos: legendLayers
}, "legendDiv");
legend.startup();
});
var selectionSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol("solid", new dojo.Color("red"), 5), new dojo.Color([255, 0, 0, 1.0]));
floorLayer.setSelectionSymbol(selectionSymbol);
map.extent = new esri.geometry.Extent({ xmin: -12935175, ymin: 5405420, xmax: -12935006, ymax: 5405390, spatialReference: { wkid: 102113} });
map.addLayers([floorLayer]);
var resizeTimer;
dojo.connect(map, 'onLoad', function (theMap) {
dojo.connect(dijit.byId('map'), 'resize', function () { //resize the map if the div is resized
clearTimeout(resizeTimer);
resizeTimer = setTimeout(function () {
map.resize();
map.reposition();
}, 500);
});
});
}
if (searchEngine == 2 && mechBox.checked == false) {
map.removeAllLayers();
if (map.graphics != null) {map.graphics.clear();}
if (floorclickCounter == 1) { dojo.disconnect(floorClick); }
map.infoWindow.resize(300, 160);
firstService = new esri.layers.ArcGISDynamicMapServiceLayer("http://gisv/ArcGIS/rest/services/CourtHouseFloorPlan/First/MapServer", {
id: "firstService"
});
map.addLayer(firstService);
//define a popup template
var popupTemplate = new esri.dijit.PopupTemplate({
title: "{Room_Name}",
fieldInfos: [
{ fieldName: "Room_Name", visible: true, label: "Room Name" },
{ fieldName: "Room_Num", visible: true, label: "Room Number" }
],
showAttachments: true
});
floorLayer = new esri.layers.FeatureLayer("http://gisv/ArcGIS/rest/services/CourtHouseFloorPlan/First/MapServer/0", {
id: "first",
infoTemplate: popupTemplate,
opacity: .2,
mode: esri.layers.FeatureLayer.MODE_SELECTION,
outFields: ["Room_Name", "Room_Num", "Plan_Num"]
});
floorClick = dojo.connect(floorLayer, "onClick", function (evt) {
map.infoWindow.setFeatures([evt.graphic]);
map.infoWindow.show(evt.mapPoint);
floorclickCounter = 1;
});
legendLayers.push({ layer: floorLayer, title: 'FIRST FLOOR' });
legendConnect = dojo.connect(map, 'onLayersAddResult', function (results) {
legend = new esri.dijit.Legend({
map: map,
layerInfos: legendLayers
}, "legendDiv");
legend.startup();
});
var selectionSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol("solid", new dojo.Color("red"), 5), new dojo.Color([255, 0, 0, 1.0]));
floorLayer.setSelectionSymbol(selectionSymbol);
map.extent = new esri.geometry.Extent({ xmin: -12935175, ymin: 5405300, xmax: -12935006, ymax: 5405440, spatialReference: { wkid: 102113} });
map.addLayers([floorLayer]);
var resizeTimer;
dojo.connect(map, 'onLoad', function (theMap) {
dojo.connect(dijit.byId('map'), 'resize', function () { //resize the map if the div is resized
clearTimeout(resizeTimer);
resizeTimer = setTimeout(function () {
map.resize();
map.reposition();
}, 500);
});
});
}
}