Infrastructure Map Server Developer

Infrastructure Map Server Developer

Reply
Valued Contributor
swimming123
Posts: 87
Registered: ‎04-12-2012
Message 1 of 3 (576 Views)

Programmingly Turn ON/OFF BaseLayerGroup

576 Views, 2 Replies
03-21-2013 02:04 PM

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.

 

 

Active Member
francisco.rojas
Posts: 9
Registered: ‎08-29-2005
Message 2 of 3 (360 Views)

Re: Programmingly Turn ON/OFF BaseLayerGroup

09-06-2013 09:58 AM in reply to: swimming123

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,

Valued Contributor
swimming123
Posts: 87
Registered: ‎04-12-2012
Message 3 of 3 (356 Views)

Re: Programmingly Turn ON/OFF BaseLayerGroup

09-06-2013 12:41 PM in reply to: francisco.rojas

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.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.