Viewer API GetLayers(onlyVisible, onlySelectable)

1 message Options
Embed this post
Permalink
doggybs

Viewer API GetLayers(onlyVisible, onlySelectable)

Reply Threaded More More options
Print post
Permalink
Hi

In the Viewer API documentation for GetLayers(onlyVisible, onlySelectable) it say:

"onlyVisible - set to true to return only the layers visible at the current scale; set to false to ignore layer visibility."

The current scale aspect of this does not work. In that it will always return layers that are turned on in the legend even thought they are not visible due to the layers scale styling.

I have worked around the problem by modifing function DoGetLayers(nodes, layers, onlyVisible, onlySelectable) in the legendui.templ file in the web extensions, by adding a check on the curScale property.

function DoGetLayers(nodes, layers, onlyVisible, onlySelectable)
{
   

       
        for(var i=0; i < nodes.length; i++)
    {        
               
                var node = nodes[i];
        if(node.type == 0)
        {
            if(onlyVisible && (!node.visible || node.curScale == -1))
                continue;
            if(node.children != null && node.children.length > 0)
                DoGetLayers(node.children, layers, onlyVisible, onlySelectable);
        }
        else if(node.type == 1)
        {
            if(onlyVisible && (!node.visible || node.curScale == -1))
                continue;
            if(onlySelectable && !node.selectable)
                continue;
            layers.push(new Layer(node.legend, node.name, node.objectId));
        }
    }
}


Can you please let me know if this is a sensible fix or will it cause any problems.

Many Thanks

James