Version 3 (modified by 16 years ago) ( diff ) | ,
---|
Utilizing RuntimeMap via Maestro API
This page describes how to use the MaestroAPI from the MapGuide Maestro project in your own application.
This example shows how to make a copy of a WebLayout, and use it to override the zoom level for a particular user. The code should be placed in an aspx page, otherwise the Response.Redirect call won't work.
This example uses the http version, so no MapGuide binaries are required. Read about the difference between LocalNativeConnection and HttpServerConnection here
(VB.NET)
Imports OSGeo.MapGuide.MaestroAPI ... 'Read the setup, either from QueryString, Form, Cookies or hardcoded values Dim username As String = IIF(Request.Params("USERNAME") Is Nothing, "Anonymous", Request.Params("USERNAME")) Dim password As String = IIF(Request.Params("PASSWORD") Is Nothing, "", Request.Params("PASSWORD")) Dim layout As String = IIF(Request.Params("LAYOUT") Is Nothing, "Library://MyLayout.WebLayout", Request.Params("LAYOUT")) Dim locale As String = IIF(Request.Params("LOCALE") Is Nothing, "en", Request.Params("LOCALE")) 'Setup connection Dim host As New Uri("http://localhost/mapguide/mapagent/mapagent.fcgi") Dim conn As New HttpServerConnection(host, username , password, locale, True) 'Obtain the weblayout and map Dim weblayout as WebLayout = con.GetWebLayout(layout) Dim mapdefinition as MapDefinition = con.GetMapDefinition(weblayout.Map.ResourceId) 'Modify the initial view of the weblayout weblayout.Map.InitialView = new MapViewType() weblayout.Map.InitialView.Scale = 2000 'Zoom to 1:2000 weblayout.Map.InitialView.CenterX = (mapdefinition.Extents.MaxX - mapdefinition.Extents.MinX) + mapdefinition.Extents.MinX weblayout.Map.InitialView.CenterY = (mapdefinition.Extents.MaxY - mapdefinition.Extents.MinX) + mapdefinition.Extents.MinY 'Obtain a unique session based id for the temporary weblayout (which is a copy of an existing WebLayout) Dim tempid as ResourceIdentifier = new ResourceIdentifier(Guid.NewGuid(), OSGeo.MapGuide.MaestroAPI.ResourceTypes.WebLayout, con.SessionID) 'Save the layout, otherwise you can't reference it con.SaveResourceAs(weblayout, tempid) 'Open the viewer, and use the temporary layout, since the map only exists in the 'current session, we must use that session, and NOT supply username/password Response.Redirect("/mapguide/ajaxviewer/?LAYOUT=" & Server.UrlEncode(tempWebLayout) & "&SESSION=" & Server.UrlEncode(con.SessionID), true)
(C#)
import OSGeo.MapGuide.MaestroAPI; ... //Read the setup, either from QueryString, Form, Cookies or hardcoded values string username As = Request.Params("USERNAME") == null ? "Anonymous" : Request.Params("USERNAME"); string password = Request.Params("PASSWORD") == null ? "" : Request.Params("PASSWORD"); string layout = Request.Params("LAYOUT") == null ? "Library://MyLayout.WebLayout" : Request.Params("LAYOUT"); string locale = Request.Params("LOCALE") == null ? "en" : Request.Params("LOCALE"); //Setup connection Uri host = new Uri("http://localhost/mapguide/mapagent/mapagent.fcgi"); ServerConnectionI conn = new HttpServerConnection(host, username , password, locale, True); 'Obtain the weblayout and map WebLayout weblayout = con.GetWebLayout(layout); MapDefinition mapdefinition = con.GetMapDefinition(weblayout.Map.ResourceId); //Modify the initial view of the weblayout weblayout.Map.InitialView = new MapViewType(); weblayout.Map.InitialView.Scale = 2000 //Zoom to 1:2000 weblayout.Map.InitialView.CenterX = (mapdefinition.Extents.MaxX - mapdefinition.Extents.MinX) + mapdefinition.Extents.MinX; weblayout.Map.InitialView.CenterY = (mapdefinition.Extents.MaxY - mapdefinition.Extents.MinX) + mapdefinition.Extents.MinY; //Obtain a unique session based id for the temporary weblayout (which is a copy of an existing WebLayout) ResourceIdentifier tempid = new ResourceIdentifier(Guid.NewGuid(), OSGeo.MapGuide.MaestroAPI.ResourceTypes.WebLayout, con.SessionID); //Save the layout, otherwise you can't reference it con.SaveResourceAs(weblayout, tempid); //Open the viewer, and use the temporary layout, since the map only exists in the //current session, we must use that session, and NOT supply username/password Response.Redirect("/mapguide/ajaxviewer/?LAYOUT=" + Server.UrlEncode(tempWebLayout) + "&SESSION=" + Server.UrlEncode(con.SessionID), true);
Note:
See TracWiki
for help on using the wiki.