1

I have a map service that contains 6 layers.

I turned one layer into a feature layer. I used this layer in a query and show the result.

I then would like to just show the other 5 layers as a ArcGISDynamicMapServiceLayer, but I didn't set any min/max scale levels for the layers when I published the MXD. I figured it'd be best to do this programmatically, but I can't figure out how.

Can I set the min/max scale levels independently for each layer in the ArcGISDynamicMapServiceLayer? If not, what's the best way to approach this?

Thanks!

EDIT

Can someone explain to me how this question isn't clear? I don't believe it could get any more clear.

  • 2
    Any specific reason why you want to do it from the client side, instead of setting it when publishing the service? Additionally, please let us know the ArcGIS Server version that you are using. – Devdatta Tengshe Jul 28 '14 at 6:49
  • 1
    It just makes more sense. This way I can change the scale levels whenever I want without republishing a map service ever time. It'd be really cool if I could just go var maxScale = []; maxScale[2] = 5000; ArcGISDynamicMapServiceLayer.setMaxScale(maxScale); just like you can do with setLayerDefinitions! – geogeogeo Jul 28 '14 at 8:13
  • 1
    What version of ArcGIS server are you using? that is an important detail on which the answer depends. – Devdatta Tengshe Jul 28 '14 at 9:39
2

What you can do, is to check the expected Visibility at a particular zoomlevel, and change the layer's VisibleLayers appropriately. The map's zoom-end even is one place where you could check it.

Assume that I have a DynamicMapService with 5 Layers in it. I'll define the layervisiblity with something like this:

var layerVisibilityInfo=[
    {id:0, maxScale:25000, minScale:200000},
    {id:1, maxScale:15000, minScale:250000},
    {id:2, maxScale:100000, minScale:6000000},
    {id:3, maxScale:40000, minScale:1000000},
    {id:4, maxScale:4000, minScale:1000000},
    {id:5, maxScale:1, minScale:6000000}
    ];

Note that the maxScale is always less than the minScale.

I'll now listen to the zoom-end event and set the layervisibility, with some code like this:

map.on('zoom-end', function(extent, zoomFactor, anchor){

    var currentScale=map.getScale();
    var l=layerVisibilityInfo.length;
    var visible=[];
    for(var i=0;i<l;i++){
        var layerInfo=layerVisibilityInfo[i];
        if((layerInfo.maxScale<currentScale)&&(layerInfo.minScale>currentScale)){
            visible.push(layerInfo.id);
        }
    }

    //This is my ArcGISDynamicMapService
    adminLayer.setVisibleLayers(visible, false);

});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.