[mapguide-users] Help

Kenneth Skovhede ks at geograf.dk
Fri Jan 15 16:27:38 EST 2010


There are some code samples here:
http://trac.osgeo.org/mapguide/wiki/CodeSamples

But not much :(


The MgMap object is a runtime map, and only avalible in a session.
That means that you cannot interact with it before the viewer loads, and 
you MUST use the session id
to create the connection, or you cannot use it (calling CreateSession 
creates a new session).

In page1 you both redirect and write a frame setup? That is not 
possible, you will not be writing the html output,
thus the viewer is not started, and the runtime map is not created.

Try to remove the redirect, and add your InformationMap.aspx as a task 
or button instead.

Regards, Kenneth Skovhede, GEOGRAF A/S



Lasly Genoese Puntodoc Srl skrev:
>
>  
>
>  
>
>  
>
> Hello, I am new to MapGuide. I've just started using open source 
> MapGuide 2.1, but I did not even run the examples (C #) of the guide. 
> possible?
> I have too many problems (I do not work nothing) also asking for help.
> For example map.open generates exception: Resource was not found
> Then I used the map.create without exception (with map Sheboygan) and 
> try to do the exercise to change the visibility of layers. The code 
> goes, but video layers do not change.
> Where can I find (or can you given me) a simple example ( or project 
>  for Visual Studio 2008 c#) that works?
>
> Thanks so much! (forgive my English!)
>
>  
>
> Le.
>
> this is my code:
>
>  
>
> Page 1:
>
>  
>
> <%@ Page language="c#" %>
>
> <%@ Import Namespace="System.IO" %>
>
> <%@ Import Namespace="System.Collections.Specialized" %>
>
> <%@ Import Namespace="System.Text" %>
>
> <%@ Import Namespace="System.Globalization" %>
>
> <%@ Import Namespace="OSGeo.MapGuide" %>
>
>  
>
>  
>
>  
>
> <%
>
>         String sessionId = "";
>
>         String webLayout = 
> "Library%3a%2f%2fSamples%2fSheboygan%2fLayouts%2fSheboyganAsp.WebLayout";
>
>     try
>
>     {
>
>        
>
>         // Initialize a session and register a variable to hold the
>
>         // session id, then initialize the Web Extensions, connect
>
>         // to the site, and create a session.
>
>  
>
>         // Initialize Web Server Extensions.
>
>         String realPath = Request.ServerVariables["APPL_PHYSICAL_PATH"];
>
>         String configPath = realPath + "..\\webconfig.ini";
>
>         MapGuideApi.MgInitializeWebTier(configPath);
>
>  
>
>         // Connect to the site.
>
>         MgUserInformation userInfo = new 
> MgUserInformation("Administrator", "admin");
>
>         MgSite site = new MgSite();
>
>         site.Open(userInfo);
>
>  
>
>             // Create a session
>
>         sessionId = site.CreateSession();    
>
>  
>
>     }
>
>     catch (Exception e)
>
>     {
>
>         Response.Write(e.Message);
>
>     }
>
>  
>
>     Response.Redirect("InformationMap.aspx?SESSION=" + sessionId);
>
> %>
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>
> <html xmlns="http://www.w3.org/1999/xhtml" >
>
> <head>
>
>     <title>HelloWorld</title>
>
> </head>
>
>  
>
> <frameset rows="0,*" border="0" framespacing="0">
>
>   <frame />
>
>   <frame src="/mapguide/mapviewernet/ajaxviewer.aspx?SESSION=<%= 
> sessionId %>&WEBLAYOUT=<%= webLayout %>" name="ViewerFrame" />
>
> </frameset>
>
>  
>
> </html> 
>
>  
>
>  
>
> Page 2:
>
> <%@ Page Language="c#" %>
>
>  
>
> <%@ Import Namespace="OSGeo.MapGuide" %>
>
>  
>
> <%
>
>     String MgSessionId = "";
>
>   
>
>     String webLayout = 
> "Library%3a%2f%2fSamples%2fSheboygan%2fLayouts%2fSheboyganAsp.WebLayout";
>
>    
>
>     try
>
>     {
>
>  
>
>      MgSessionId = Request.QueryString["SESSION"]; 
>
>  
>
>       
>
>  
>
>         // Initialize Web Server Extensions.
>
>         String realPath = Request.ServerVariables["APPL_PHYSICAL_PATH"];
>
>         String configPath = realPath + "..\\webconfig.ini";
>
>         MapGuideApi.MgInitializeWebTier(configPath);
>
>  
>
>         MgUserInformation userInfo = new MgUserInformation(MgSessionId);
>
>  
>
>  
>
>         MgSiteConnection siteConnection = new MgSiteConnection();
>
>  
>
>         siteConnection.Open(userInfo);
>
>  
>
>         MgResourceService resourceService = 
> siteConnection.CreateService(MgServiceType.ResourceService) as 
> MgResourceService;
>
>  
>
>         MgResourceIdentifier mapDefid = new 
> MgResourceIdentifier("Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition");
>
>  
>
>         MgMap map = new MgMap();
>
>  
>
>       
>
>  
>
>       map.Create(resourceService, mapDefid, "Sheboygan");
>
>  
>
>  
>
>       // Exception!!! -.-'   
>
>        // map.Open(resourceService, "Sheboygan");
>
>        // map.Open("Sheboygan");
>
>       //  map.Open(resourceService, mapDefid);
>
>  
>
>  
>
>         MgEnvelope envelope = map.GetMapExtent();
>
>  
>
>  
>
>         Double lowerX = envelope.GetLowerLeftCoordinate().GetX();
>
>         Double lowerY = envelope.GetLowerLeftCoordinate().GetY();
>
>  
>
>         String mapname = map.GetName();
>
>  
>
>  
>
>  
>
>         MgLayerCollection layerCol = map.GetLayers();
>
>         MgLayer layer = null;
>
>  
>
>         String layerName = "";
>
>  
>
>  
>
>         for (int i = 0; i < layerCol.GetCount(); i++)
>
>         {
>
>             layer = (MgLayer)layerCol.GetItem(i);
>
>             layerName = layer.GetName();
>
>           
>
>         }
>
>  
>
>  
>
>         layer = (MgLayer)layerCol.GetItem("Districts");
>
>  
>
>    
>
>  
>
>         MgLayerGroup gruppo = layer.GetGroup();
>
>  
>
>  
>
>         gruppo.SetLegendLabel("cambiata");
>
>  
>
>        // gruppo.SetDisplayInLegend(false);
>
>  
>
>  
>
>         //if (layer.IsVisible())
>
>        // {
>
>             layer.SetVisible(false);
>
>            
>
>        // }
>
>       //  else
>
>       //  {
>
>        //     layer.SetVisible(true);
>
>     //    }
>
>  
>
> //try
>
>         layer.ForceRefresh();
>
> //try
>
>  
>
>         layer.NeedsRefresh();
>
>     }
>
>  
>
>     catch (Exception e)
>
>     {
>
>         Response.Write(e.Message);
>
>     }
>
>    
>
>    
>
>  
>
>        
>
> %>
>
>  
>
>  
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" 
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
>
> <html xmlns="http://www.w3.org/1999/xhtml" >
>
> <head>
>
>     <title>MapGuide Developer's Guide ASP.NET Samples</title>
>
> </head>
>
>  
>
> <frameset rows="80,*" frameborder="no" framespacing="0">
>
>       <frame id="titleFrame" frameborder="no" marginwidth="0" 
> marginheight="0" scrolling="no" src="common/title.html">
>
>      
>
> <frame id="viewerFrame" frameborder="no" marginwidth="10" 
> marginheight="10" scrolling="yes" 
> src="../mapviewernet/ajaxviewer.aspx?SESSION=<%=MgSessionId%>&WEBLAYOUT=<%=webLayout%>">
>
>  
>
> </frame>
>
> </frame>
>
>  
>
> </frameset>
>
> <body>
>
>  
>
> <input type="button" value="Point" onclick="DigitizePoint();" />
>
> </body>
>
> </html>
>
>  
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> mapguide-users mailing list
> mapguide-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapguide-users/attachments/20100115/17433ce1/attachment.html


More information about the mapguide-users mailing list