ArcGISDynamicMapServiceLayer: unwanted layers included in render

3159
12
Jump to solution
03-06-2017 06:41 AM
YohanBienvenue
Occasional Contributor II

I have an issue where the image render returned by the MapServer does not seem to correspond to the list of visibleLayers specified in the ArcGISDynamicMapServiceLayer. It seems all child layers of a group layer are rendered, whether they are included in the list of visibleLayers or not.

 

ArcGIS API for JavaScript 3.19

ArcGIS Server 10.3.1

Here is an example of a group layer 256 with child layers 257 to 270

 

Screenshot-1

 

Using a layers widget binded to the list of visibleLayers of the ArcGISDynamicMapServiceLayer, if I check one of the child layer, this is export request sent by the API:

 

Screenshot-2

Screenshot-3

You can see that only 256 and 270 are included in the layers parameter of the export request, yet the MapServer will render ALL sublayers 257 to 270.

Is this the default behaviour of the MapServer??

If so, how do I work around this?

I'm thinking maybe I could manually remove group layers in the list of visibleLayers of the ArcGISDynamicMapServiceLayer, but that could create issues with the layers widget, where the group layer would be unchecked too (since it's binded to it), which is not what we want.

I see the export request (Export Map (Operation) ) layers parameter also include an "exclude" option. Is there a way I could exclude all unchecked layers using a setting or option in the ArcGIS JavaScript API? Otherwise how would I do this?

 

Thanks

EDIT:

Here is a more obvious example with an infrastructure group layer:

 


Only child layer 168 is included in the list

But it renders them all:

0 Kudos
1 Solution

Accepted Solutions
YohanBienvenue
Occasional Contributor II

I did and as predicted the group layers I removed became unchecked in the layers widget.

It's alright though, I ended up just unbinding the widget from the ArcGISDynamicMapServiceLayer and give it the list of visibleLayers myself, manually. Not as bad as I thought.

As for the ArcGISDynamicMapServiceLayer, whenever I need to set the visibleLayers I call this function to remove the group layers. For anyone interested:


initGroupLayers: function(){
    this.groupLayers = [];
    array.forEach(this.dynamicMapServiceLayer.layerInfos, lang.hitch(this, function(layerInfo){
        if (layerInfo.subLayerIds){
            this.groupLayers.push(layerInfo.id);
        }
    }));
}

_setVisibleLayers: function (params) {
    // Filter out any group layer from the list of visibleLayers
    var filteredLayers = array.filter(params.visibleLayers, lang.hitch(this, function(layer){
        return this.groupLayers.indexOf(layer) === -1;
    }));

    // Update using the filtered list
    this.dynamicMapServiceLayer.setVisibleLayers(filteredLayers);
}

The initGroupLayers function is called once in the "load" event handler of the dynamicMapServiceLayer

View solution in original post

0 Kudos
12 Replies
thejuskambi
Occasional Contributor III

Are you sure, the layers 257 to 270 are all displayed. As you have shared the request sent but not the response received.

I have seen something similar happen, when I use LayerDrawingOptions. If you are updating a layer drawing option for a particular layer and do not update all the layer properties, i.e just change labelingInfo or transparency of only one or few layers. Then it will get the default properties for other layers, which may be visible = true. But this happens on a very specific condition.

Are you using LayerDrawingOptions?

0 Kudos
YohanBienvenue
Occasional Contributor II

Pretty sure yes. Well the response is just an image but I can see the top child layer 257 is rendered, since it's on top of the other child layers. What I want rendered is only the old 1950 ortho layer:

Screenshot-4

but instead it renders the newest one, here is the response in Chrome:

Screenshot-5

Also this was just an example, I have seen similar results with all the other layers in the service. For instance we have an infrastructure group including stuff like man holes, fire hydrants, etc.. if I check a single child layer in the group, ArcGIS Server will render all the child layers (all the infrastructure layers) in the image.

I'm not using LayerDrawingOptions anywhere in my code, no.

Are you saying that this is not normal? Should the normal behavior of ArcGIS Server be to render ONLY the layers included in the layers parameter of the export request? I can't find any doc that says so specifically.

Thanks

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Yohan,

   If a group layer id is included in the map export layers array then all the layers are exported. All group layers have to be removed when you create your visible layers list. If you remove id 256 from your visibleLayers then you should be fine.

thejuskambi
Occasional Contributor III

Is this documented some where?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Not that I know of it is just a feature that I have been familiar with since my Flex days.

0 Kudos
YohanBienvenue
Occasional Contributor II

Hi Robert,

Thanks for the confirmation. I realise I could just remove the group layer ids for the visibleLayers but that will break the layers widget, which is binded to the list of visibleLayers. If there is no other way I'll try and figure something out but it will really complexify my code. I really wish this was optional through the API, I mean the exclude parameter of the export request is right there, it's available, why not use it..

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Yohan,

   I don't think that it will break the LayerList widget. You should try.

0 Kudos
YohanBienvenue
Occasional Contributor II

I did and as predicted the group layers I removed became unchecked in the layers widget.

It's alright though, I ended up just unbinding the widget from the ArcGISDynamicMapServiceLayer and give it the list of visibleLayers myself, manually. Not as bad as I thought.

As for the ArcGISDynamicMapServiceLayer, whenever I need to set the visibleLayers I call this function to remove the group layers. For anyone interested:


initGroupLayers: function(){
    this.groupLayers = [];
    array.forEach(this.dynamicMapServiceLayer.layerInfos, lang.hitch(this, function(layerInfo){
        if (layerInfo.subLayerIds){
            this.groupLayers.push(layerInfo.id);
        }
    }));
}

_setVisibleLayers: function (params) {
    // Filter out any group layer from the list of visibleLayers
    var filteredLayers = array.filter(params.visibleLayers, lang.hitch(this, function(layer){
        return this.groupLayers.indexOf(layer) === -1;
    }));

    // Update using the filtered list
    this.dynamicMapServiceLayer.setVisibleLayers(filteredLayers);
}

The initGroupLayers function is called once in the "load" event handler of the dynamicMapServiceLayer

0 Kudos
KenBuja
MVP Esteemed Contributor

I had a problem with a group layer in the results from an IdentifyTask. I was able to filter these out when setting up the IdentifyParameters using this code (from this discussion)

var visLayers = layer.visibleLayers;  
if (visLayers !== -1) {  
    var subLayers = [];  
    for (var i = 0; i < layer.layerInfos.length; i++) {  
        if (layer.layerInfos[i].subLayerIds == null)  
            subLayers.push(layer.layerInfos[i].id);  
    }  
    idParams.layerIds = subLayers;  
} else {  
    idParams.layerIds = [];  
}  ‍‍‍‍‍‍‍‍‍‍‍
0 Kudos