[fusion-users] Problem with layer hiding and showing.

David Wilhelmsson david.wilhelmsson at 65nord.se
Mon Oct 29 00:11:22 PDT 2012


For future googlers because the issue is still relevant with MapGuide 2.2
(tested), Paul's code was the basis for the code that resolved the issue for
me. To be clear, here's the full code that I used:

var map = this.getMap().aMaps[0];
// layers is an array of layers to show
for (var i=0; i<layers.length; i++) {
     map.showLayer(layers[i], true);
}
map.drawMap();

Note that map is this.getMap().aMaps[0] and not this.getMap() to get access
to the underlying Fusion.Layers.MapGuide object (instead of the higher-level
Fusion.Widget.Map object) and that the noDraw parameter passed to showLayers
should be true to prevent showLayers from redrawing the map (instead of
Paul's code that used false - this is probably why Tómas was unable to get
Paul's code working).

The above code (tested) allowed me to set the visibility of multiple layers
at one time without redrawing the map after each change in visibility and
manually call drawMap once at the end to correctly display the visibility of
all layers. This code has the additional benefit of not requiring hacking
Fusion to add the sneShowLayers and sneHideLayers functions (although these
functions helped me in understanding the issue).

Please note that by calling the underlying Fusion.Layers.MapGuide.showLayers
function, we miss out on the additional functionality that updates the
legend and visible property of the Fusion.Layers.Layer object when we call
the Fusion.Layers.Layer.show function. If you would like to
Fusion.Layers.Layer.show function instead to get this additional
functionality, use the following code instead:

var map = this.getMap().aMaps[0];
// layers is an array of layers to show
for (var i=0; i<layers.length; i++) {
     layer.show(true);
}
map.drawMap();

Note that even though I'm calling the higher-level Fusion.Layers.Layer.show
function, I still need to call the underlying Fusion.Layers.MapGuide.drawMap
to correctly redraw the map. I found that a call to higher-level
Fusion.Widget.Map.redraw function will not correctly redraw the map (another
source of confusion for me when trying to resolve this issue).

Kind regards,
Dave.



--
View this message in context: http://osgeo-org.1560.n6.nabble.com/Problem-with-layer-hiding-and-showing-tp3783326p5011889.html
Sent from the Fusion Users mailing list archive at Nabble.com.


More information about the fusion-users mailing list