Hello,
I have added a few layers (InMemoryFeatureLayer) to the Map.DynamicOverlay collection. How do I turn these layers on/off on the client side?
Hello,
I have added a few layers (InMemoryFeatureLayer) to the Map.DynamicOverlay collection. How do I turn these layers on/off on the client side?
Hi Sindre,
On client side, we just can access the Overlay defined on server side, all the layers added to the Map.DynamicOverlay are rendered as only on layer on client side. If we would like to turn these layers on/off on the client side, I guess there are 2 options:
1. Add these layers into different LayerOverlay, 1 layer per LayerOverlay, and then we can easily turn them on/off on client side using the code below:
var map = Map1.GetOpenLayersMap();
var layer = map.getLayersByName(id)[0];
layer.setVisibility(false/true)
2. Use AjaxCall on client side to request the server side to turn on/off these layers, and then redraw the DynamicOverlay on client side. The pseudocode is:
$Ajax.request(“server”, function(e){
// redraw daynamic Overlay on client side in Callback function
});
Please have a try and any question please let us knows.
Thanks,
Johnny
Hi, I tried option 1 but the performance was terrible compared to adding just one layer to DynamicOverlay.
Hello Sindre,
The performance problem is because using too many Overlays, I recommend you using the second way.
And here are more details about Ajax call, you can find how to use it in this post
Then after you set the layer visibility to false in server side, you can return a value to client side, and if the value is true, you can call
var map = Map1.GetOpenLayersMap();
var layer = map.getLayersByName(id)[0];
layer.redraw(true);
So both server side and client side, the layer disappear.
Let us know if you meet problems.
Regards,
Gary