Infrastructure Map Server Forum
Welcome to Autodesk’s Infrastructure Map Server Forums. Share your knowledge, ask questions, and explore popular Infrastructure Map Server topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Programmingly Turn ON/OFF BaseLayerGroup

2 REPLIES 2
Reply
Message 1 of 3
swimming123
825 Views, 2 Replies

Programmingly Turn ON/OFF BaseLayerGroup

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:

  • create an xml and js file, use invoke script method, here is the js file:

          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;

  • use the server side code to turn the group on

                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/>&nbsp Artho Photo Image Added.");
                     }
                     else
                     {
                         Response.Write("<br/>&nbsp 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.

 

 

2 REPLIES 2
Message 2 of 3

Hi,

 

This post explains how to do that:

http://adndevblog.typepad.com/infrastructure/2012/04/toggle-visibility-of-layer-in-fusion-does-not-w...

 

Hope this helps.

 

Regards,

Tags (2)
Message 3 of 3

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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report