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: 

How to get the MgMap Object

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
878 Views, 4 Replies

How to get the MgMap Object

Hello ,

I am trying to create a session and open a Map.

At the same time I need to get the MgMap object of the Map I just opened.

Since I have the MapGuide URL I am going to redirect my response.

But at the same time I need the MgMap object.

Any thoughts please ?

Thanks
Anand

Here is my code

Session["SiteID"] = "221";
string MapGuideGISINI = ConfigurationManager.AppSettings["MapGuideGISINI"].ToString();
MapGuideApi.MgInitializeWebTier(MapGuideGISINI);
MgUserInformation userInfo = new MgUserInformation("Anonymous", "");
MgSiteConnection TheMgSiteConnection = new MgSiteConnection();
TheMgSiteConnection.Open(userInfo);
MgSite site = TheMgSiteConnection.GetSite();
string sessionId = site.CreateSession();
userInfo.SetMgSessionId(sessionId);
string WebLayoutResourceString = "Library://" + Session["SiteID"].ToString() + "/Layouts/" + Session["SiteID"].ToString() + ".WebLayout";
string MapGuideGISURL = ConfigurationManager.AppSettings["MapGuideGISURL"].ToString();
string ajaxsrc = MapGuideGISURL + "?SESSION=" + sessionId + "&WEBLAYOUT=" + WebLayoutResourceString + "&LOCALE=en";


Response.Redirect(Response, ajaxsrc, "GIS", "resizable=yes,toolbar=no,location=no,width=580,height=525,directories=no,status=no,scroll=yes,scrollbars=yes,menubar=no,left=10,top=10");
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Anonymous

The map isn't actually loaded until the user's browser hits the new URL. In order to get the viewer to open an already existing map you need to modify mapframe.(aspx|php) with something like:

try { map.Open(resourceSrvc, mapName); }
catch (MgException) { map.Create(resourceSrvc, resId, mapName); }

Just note that it will make an entry in the error log if it can't open the existing map.

Also you will need to start the map yourself. If you starting from a layout definition you will need to grab the mapdefinition in order to use map.create(). You can get the layout's XML via ResourceService.GetResourceContent(ResourceIdentifier).

ResourceService = (MgResourceService) SiteConnection.CreateService(MgServiceType.ResourceService);

Map.Create(ResourceService, ResourceIdentifier, ResourceIdentifier.GetName());

Not exactly easy as pie, but it is possible.
Message 3 of 5
Anonymous
in reply to: Anonymous

At what point the Map will be ready ?

When can I get the Session and Map Name ?

Is there a sample Javascript Functions which can provide this info or only available on server side NameValueCollection pair ?

Thanks for spending time and talking with me.

Regards
Anand
Message 4 of 5
Anonymous
in reply to: Anonymous

There is GetMapName() and GetSessionId() on the map frame (you can get the map frame by calling GetMapFrame() inside the root of the viewer). A reference is available at http://mapguide.osgeo.org/files/mapguide/docs/2.0/viewerapi.html

So for instance a window that was launched from within mapguide could call window.opener.GetMapFrame().GetSessionId() to get the session id.
Message 5 of 5
Anonymous
in reply to: Anonymous

> {quote:title=sakkaku wrote:}{quote}
> try { map.Open(resourceSrvc, mapName); }
> catch (MgException) { map.Create(resourceSrvc, resId, mapName); }
>
> Just note that it will make an entry in the error log if it can't open the existing map.

This also works and avoids throwing the exception. The variable MgResourceIdentifier mapStateId could be moved up from lower in the page to avoid creating another MgResourceIdentifier, but i prefer to keep the modification simple.

{code}
if(resourceSrvc.ResourceExists(new MgResourceIdentifier("Session:" + sessionId + "//" + mapName + "." + MgResourceType.Map)))
map.Open(resourceSrvc, mapName);
else
map.Create(resourceSrvc, resId, mapName);
{code}

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

Post to forums  

Autodesk Design & Make Report