In order to create a customed buttom to turn on/off BaseLayerGroup programmingly (instead of click the ckeckbox in the Legend), I use the following methods:
Fusion.Widget.Image = OpenLayers.Class(Fusion.Widget,
{
uiClass: Jx.Button,
initializeWidget: function(widgetTag)
{
this.enable();
},
activate: function(turn)
{
//var theLegend = Fusion.getWidgetById("Legend");
//var theMap = Fusion.getWidgetById("Map");
var currentGroup = document.getElementsByTagName("input");
var i = currentGroup.length - 1;
alert(i); //it alert total input box 125;
alert(currentGroup[i]); //it shows this is an HTML checkbox object
alert(currentGroup[i].checked); //it alert this checkbox is not checked, false
currentGroup[i].checked = !(currentGroup[i].checked);
alert(currentGroup[i].checked); //it shows this checkbox is now checked, true
}
} );
although above alert information shows my function is working, but I check the "Legend", the final checkbox state not change, still unchecked;
String sessionId = Request.QueryString.Get("session");
String mapName = Request.QueryString.Get("MapName");
Utility utility = new Utility();
utility.InitializeWebTier(Request);
utility.ConnectToServer(sessionId);
MgSiteConnection siteConnection = utility.GetSiteConnection();
if (siteConnection == null)
{
Response.Write("fail to get site connection, exit");
return;
}
MgResourceService resSvc = (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService);
MgMap map = new MgMap();
map.Open(resSvc, mapName);
double scale = map.GetViewScale();
if (scale <= 18000)
{
MgLayerGroup layerGroup = utility.getGroupByName(map, "OrthoImage");
layerGroup.LegendLabel = "Ortho Image";
layerGroup.SetDisplayInLegend(!layerGroup.IsVisible());
layerGroup.SetVisible(!layerGroup.IsVisible());
map.Save(resSvc);
string refreshMap = "<script type='text/javascript'>RefreshMap()</script>";
Page.ClientScript.RegisterStartupScript(this.GetType(), "", refreshMap);
if (layer.IsVisible() == true)
{
Response.Write("<br/>  Artho Photo Image Added.");
}
else
{
Response.Write("<br/>  Artho Photo Image Removed.");
}
}
when the button clicked, above code also shows a message "Artho Photo Image Added." But the reality is not turned on.
Any suggestion for this solution is appreciated.
Hi,
This post explains how to do that:
Hope this helps.
Regards,
It's not helpful due to the group is BaseLayerGroup. I made it work by changing the FusionSF.js, then compress it and replace the original one.