Select to view content in your preferred language

New to scripting - Need help with a basic script with functions

1844
15
Jump to solution
02-26-2014 05:43 AM
SuzanneRoussie
Emerging Contributor
Hi,

I am in the process of putting together a basic map by learning off the tutorials and examples found on the JavaScript examples site and I am trying to use a home button, legend, and scale on the same map.  I had the home button and scale working but when I added the script for the legend it stopped working.  I was wondering if there was a limit on how many functions could be called the way I have it set up or if I am missing something else. I am sure there is a different way to do this but since I have never written anything in JavaScript before I thought this was the best way to learn. I have enclosed the text file of my code.

thanks,
Sue
0 Kudos
15 Replies
MichaelVolz
Esteemed Contributor
Jake:

Here is the section you are talking about in my file:

//add the legend
      map.on("layers-add-result", function (evt) {
        var layerInfo = arrayUtils.map(evt.layers, function (layer, index) {
          return {layer:layer.layer, title:layer.layer.name};
        });
        if (layerInfo.length > 0) {
          var legendDijit = new Legend({
            map: map,
            layerInfos: layerInfo
          }, "legendDiv");
          legendDijit.startup();
        }
      });

I do not see anywhere in this code where layers are being excluded, yet sampleserver3.arcgisonline.com mapservice layers are not being added to the legend.  I do not understand.
0 Kudos
JakeSkinner
Esri Esteemed Contributor
I thought you were referring to ESRI's basemaps. 

If the layers are not drawn, for example, due to a scale dependency they will not show in the legend.  Try adjusting the zoom level of your application.  Ex:

map = new Map("map", {
        basemap:"streets",
        center: [-96.509, 38.367],
        zoom: 14
      });
0 Kudos
MichaelVolz
Esteemed Contributor
Thanks Jake.  I did not realize that you had to zoom that far in for ESRI's river and waterbodies layers to show up.
0 Kudos
KenBuja
MVP Esteemed Contributor
You do have the option of showing the legend for layers that are invisible due to scale dependency. Set the respectCurrentMapScale to false.

          var legendDijit = new Legend({
            map: map,
            layerInfos: layerInfo,
            respectCurrentMapScale: false
          }, "legendDiv");
0 Kudos
MichaelVolz
Esteemed Contributor
I would like to add a dynamic mapservice to the javascript webmap.

I tried the following syntax but the mapservice does not show up.

var bound = new ArcGISDynamicMapServiceLayer("http://arcgis/ArcGIS/rest/services/MapServices/Bound_D/MapServer", {
        useMapImage: true
      });

Can anyone tell me what I am doing wrong?
0 Kudos
KenBuja
MVP Esteemed Contributor
I would like to add a dynamic mapservice to the javascript webmap.

I tried the following syntax but the mapservice does not show up.

var bound = new ArcGISDynamicMapServiceLayer("http://arcgis/ArcGIS/rest/services/MapServices/Bound_D/MapServer", {
        useMapImage: true
      });

Can anyone tell me what I am doing wrong?


You should start a new thread about this.
0 Kudos