AnsweredAssumed Answered

Legend

Question asked by jay.kapalczynski on Dec 5, 2018
Latest reply on Dec 5, 2018 by jay.kapalczynski

I have a main index.js page

This page defines some Map Services and builds a legend.  This works fine.

 

I have a couple other .js pages that also display Map Services and I am trying to get them in the same Legend unsuccessfully.

 

I don't think I have to create a new LEGEND in the LayerList.js page but rather just push the layers from the LayerListPage back to the Index.js page to be included in the already defined LEGEND?

 

Looking for some thoughts on this....not sure where to go from here...

Notice the unction call to the second .js page  window.LoadLayerList(); in the index.js page

 

Hope this make sense....

 

 

Main Index.js page

//ADD THE LEGEND
window.map.on("layers-add-result", function (evt) {
   // CYCLE through and grab all the layer names to add to the LEGEND PLUS
   // Remove layers not inteneted for the legend.
   var layerInfo = arrayUtils.map(evt.layers, function (layer, index) {
     if (layer.layer.id === "Roads" || layer.layer.id === "Roads1") { return { }; }
   //Hides Layers in the Legend
     else { return { layer: layer.layer, title: layer.layer.name }; } //Else return All others
   });
   // CYCLE through and grab all the layer names to add to the LEGEND
   if (layerInfo.length > 0) {
     var legendDijit = new Legend({
        map: map,
        layerInfos: layerInfo,
     }, "legend");
   legendDijit.startup();
   legendDijit.refresh();
   }
     
});


window.LoadLayerList();     

 

LayerList.js page

 

window.LoadLayerList = function(){

  var District2 = new FeatureLayer("https://vafwisdev.dgif.virginia.gov/arcgis/rest/services/Projects/AVL2/MapServer/4", {
     mode: FeatureLayer.MODE_SNAPSHOT,
     id: "District2",
     opacity: .2,
     visible: true
     });
  legendLayers4.push({ layer: District2, title: 'District Boundary' });

  window.map.on("layers-add-result", function (evt) {
     var layerInfo = arrayUtils.map(evt.layers, function (layer, index) {
     if (layer.layer.id === "Biologist" || layer.layer.id === "District2") { return { }; } //Hides Layers in the Legend
     else { return { layer: layer.layer, title: layer.layer.name }; } //Else return All others
        });
     if (layerInfo.length > 0) {
        var legendDijit = new Legend({
          map: map,
          layerInfos: layerInfo,
        }, "legend");
        legendDijit.startup();
        legendDijit.refresh();
     }
   });     

   // ADD MAP LAYERS

}

Outcomes