2

Is there a way to restrict the rendering of a WMSLayer to a specified extent without restricting map panning and zooming? That is, I need the client to be able to pan outside the limits of the WMSLayer, in which case only the basemap should be displayed.

The WMS Server is external and outside of my control.

I would prefer to find a solution, if possible, that does not hide the WMSLayer completely. The users should be able to see the extent limits of the WMS Service.

1 Answer 1

2

One idea would be to hide the WMSLayer entirely if the map's extent is outside the layers "valid" extent.

Based on this answer, one could listen to the map's extent-change event and check if the map's current extent is acceptable:

map.on("extent-change", function () {
    // Check if map.extent is acceptable, otherwise hide the WMSLayer.
    if ((map.extent.xmin < maxExtent.xmin) ||
        (map.extent.ymin < maxExtent.ymin)  ||
        (map.extent.xmax > maxExtent.xmax) ||
        (map.extent.ymax > maxExtent.ymax)) {
        // Hide the WMSLayer.
    }
}

This would not allow the WMSLayer to cover the map partially though.

The same idea could be applied using a server proxy as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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