Single checkbox for large and small scales of same feature

1062
11
11-01-2012 08:03 PM
DavidTreering
New Contributor II
I can't figure out how to have a single checkbox control the visibility of two layers, where one is the large scale version and one is the small scale version.
           var mapservice = "http://147.126.65.155/gis/rest/services/tft/tft_maine/MapServer";

           var superMarket1 = new esri.layers.FeatureLayer(
               mapservice+"/4",
               {
                   id : 'superMarket1',
                   mode : esri.layers.FeatureLayer.MODE_SNAPSHOT,
                   opacity : 1
               });
           var superMarket2 = new esri.layers.FeatureLayer(
               mapservice+"/5",
               {
                   id : 'superMarket2',
                   mode : esri.layers.FeatureLayer.MODE_SNAPSHOT,
                   opacity : 1
               });


[HTML]<li class="TOCThemeItem"><input class="list_item" id="superMarket1" value="superMarket1" onclick="layerVisibility();" type="checkbox">Supermarket</li>[/HTML]
0 Kudos
11 Replies
DavidTreering
New Contributor II
You just need to pass it an array of strings where each string is the Id of a layer in the map.

I've changed all layers to use the layerToggle method, but am having trouble with the DynamicMapServiceLayer.  FeatureLayers work just fine.  I need some FeatureLayers that have infoWindows, and some DynamicMapServiceLayers that have labels. (there may be a way to avoid this that I am overlooking). 

The DynamicMapServiceLayer, called 'boundaries' has an array of layerIDs that are integers from the service REST definition.  These are carried over to the HTML checkbox that uses layerToggle.  So for layerID = 1, I'm just using layerToggle(['1']).

However, when debugging, the layerIDs gets defined, but unlike with the supermarkets that works, the layer does not get defined during the layerToggle method.  I'm stumped.


Anyway, the problem is you are passing, for example, 'supermarket1' and 'supermarket2' to the layerToggle function but in your JS file you're giving those layers Ids of 'superMarket1' and 'superMarket2' respectively - spot the difference?  (clue: JS is case-sensitive)

D'oh!


Layers are drawn in the order that you add them to the map, you can override that by passing a desired layer index to the addLayer method, addLayers doesn't have the specific index argument (it adds the layers in the order of the array that you pass) but you can re-order layers afterwards - probably best to consult the documentation/samples.


The docs have both DynamicMapServiceLayer and FeatureLayer parts well defined, but not the interaction between them. The problem seems to be using both addLayer and addLayers.  I'm using addLayer for the DynamicMapServiceLayer, and it is working fine.  I'm using addLayers for FeatureLayer, and it works fine.  The two seem conflicted however.  All are added in a single JS function, in the order I want, but all the FeatureLayers are drawn above (after) the DynamicMapServiceLayer.  Any thoughts before I try overriding?
0 Kudos
__Rich_
Occasional Contributor III
This thread is getting pretty long and also it looks like it's diverging into separate issues - might soon be time to start new threads for those individual issues.

I think your original question was answered some time ago 🙂

I've changed all layers to use the layerToggle method, but am having trouble with the DynamicMapServiceLayer. FeatureLayers work just fine.

What sort of trouble?

I need some FeatureLayers that have infoWindows, and some DynamicMapServiceLayers that have labels. (there may be a way to avoid this that I am overlooking).

You could use image-based layers (e.g. dynamic or tiled) for everything then use something like the IdentifyTask to retrieve attributes for display in an InfoWindow and there are some samples for this. Involves a round-trip per Identify operation though, depends on your needs etc.

The DynamicMapServiceLayer, called 'boundaries' has an array of layerIDs that are integers from the service REST definition. These are carried over to the HTML checkbox that uses layerToggle. So for layerID = 1, I'm just using layerToggle(['1']). 

However, when debugging, the layerIDs gets defined, but unlike with the supermarkets that works, the layer does not get defined during the layerToggle method. I'm stumped.

'boundaries' is a single layer...and you're not providing it with a layerId upon instantiation so the API auto-assigns one:
var imageParameters = new esri.layers.ImageParameters();
imageParameters.layerIds = [0,1,12,13,14,15,16,17,18,19,20,21,22,23];
//You were also missing a ; from the end of the following line:
imageParameters.layerOption = esri.layers.ImageParameters.LAYER_OPTION_SHOW; //can also be: LAYER_OPTION_EXCLUDE, LAYER_OPTION_SHOW, LAYER_OPTION_INCLUDE

boundaries = new esri.layers.ArcGISDynamicMapServiceLayer(mapservice+"/MapServer", {"imageParameters":imageParameters});

Those layerIds are not any use for client-side referencing, their purpose is to be sent back to the server so that the (single) image generated contains only features from the layers in the service that are in that list.


The docs have both DynamicMapServiceLayer and FeatureLayer parts well defined, but not the interaction between them. The problem seems to be using   both addLayer and addLayers. I'm using   addLayer for the DynamicMapServiceLayer, and it is working fine. I'm using   addLayers for FeatureLayer, and it works fine. The two seem conflicted however. All are added in a single JS function, in the order I want, but   all the FeatureLayers are drawn above (after) the DynamicMapServiceLayer. Any thoughts before I try overriding?


From the docs:

   Also, all graphics layers are always on top of TiledMapServiceLayers and DynamicMapServiceLayers....
0 Kudos