Discussion:
[mapguide-users] Turn Layers On/Off of The Legend - FusionSF.js - AIMS2017/MapGuide3.1
RenoSun
7 years ago
Permalink
Hi all,

Does anyone facing the issues to turn on/off layers or layer groups by using
FusionSF.js?

I am using turquoiseyellow template, and I wrote following codes in order to
turn on/off the layers or layer groups based on the URL parameters. It was
working with Fusion 2.6 build. The check boxes of the layers
unchecked/checked were successfully.

turquoiseyellow/index.html
var mapWidget = Fusion.getMapById('Map');
if (mapWidget && mapWidget.isMapLoaded()) {
//Turn on/off specific layers/layer groups based on URL
parameters
// ex: getParamFromTop('sl') = 'Roads'
var sllist = decodeURIComponent(getParamFromTop('sl'));
...

mapWidget.aMaps[0].getLayerByName(getParamFromTop('sl')).show(bool);
...

However, I think AIMS 2017 is using new build like Fusion 3.0/3.1.

Then, I got following error message:
<Failed to load image: http://osgeo-org.1560.x6.nabble.com/file/t368332/Error.png>
<Failed to load image: http://osgeo-org.1560.x6.nabble.com/file/t368332/Error2.png>





--
Sent from: http://osgeo-org.1560.x6.nabble.com/MapGuide-Users-f4182607.html
GordonL
7 years ago
Permalink
With MGOS 3.1, I can use the following to toggle layers in Fusion off and on:

Fusion.getMapById('Map').aMaps[0].getLayerByName('mylayername').show();


Fusion.getMapById('Map').aMaps[0].getLayerByName('mylayername').hide();





--
Sent from: http://osgeo-org.1560.x6.nabble.com/MapGuide-Users-f4182607.html
RenoSun
7 years ago
Permalink
Hi Gordon,

Thank you for your help.

I modified following codes in order to make it work:

Fusion.Layers.Group = OpenLayers.Class(Fusion.Lib.EventMgr, {
...
show: function (noDraw) {
if (this.visible) {
return;
}
this.oMap.showGroup(this, noDraw ? true : false);
this.set('visible', true);
if (this.legend && this.legend.treeItem) {
this.legend.treeItem.check(true);
}
},

hide: function (noDraw) {
if (!this.visible) {
return;
}
this.oMap.hideGroup(this, noDraw ? true : false);
this.set('visible', false);
if (this.legend && this.legend.treeItem) {
this.legend.treeItem.check(false);
}
},
...

Fusion.Layers.Layer = OpenLayers.Class(Fusion.Lib.EventMgr, {...
show: function (noDraw) {
console.log('showLY: function (noDraw) ');
if (this.visible) {
return;
}
this.set('visible', true);
this.oMap.showLayer(this, noDraw ? true : false);
if (this.legend && this.legend.treeItem) {
this.legend.treeItem.check(true);
}
},

hide: function (noDraw) {
console.log('hideLY: function (noDraw) ');
if (!this.visible) {
return;
}
this.set('visible', false);
this.oMap.hideLayer(this, noDraw ? true : false);
if (this.legend && this.legend.treeItem) {
this.legend.treeItem.check(false);
}
},
...


initialize: function (legend, widgetTag) {...
layerPropertyChanged: function (eventID, layer) {
console.log('layerPropertyChanged');
if (typeof layer.legend.treeItem != 'undefined') {
layer.legend.treeItem.check(layer.isVisible());
}
},
...







--
Sent from: http://osgeo-org.1560.x6.nabble.com/MapGuide-Users-f4182607.html
Loading...