| 1 | |
| 2 | == Utilizing !RuntimeMap via Maestro API == |
| 3 | This page describes how to use the MaestroAPI from the [wiki:maestro MapGuide Maestro] project in your own application. |
| 4 | |
| 5 | This example shows how to make a copy of a WebLayout, and use it to override the zoom level for a particular user. |
| 6 | The code should be placed in an aspx page, otherwise the Response.Redirect call won't work. |
| 7 | |
| 8 | This example uses the http version, so no MapGuide binaries are required. |
| 9 | Read about [wiki:maestro/MaestroAPI/basics the difference between LocalNativeConnection and HttpServerConnection here] |
| 10 | |
| 11 | (VB.NET) |
| 12 | {{{ |
| 13 | Imports OSGeo.MapGuide.MaestroAPI |
| 14 | ... |
| 15 | |
| 16 | 'Read the setup, either from QueryString, Form, Cookies or hardcoded values |
| 17 | Dim username As String = IIF(Request.Params("USERNAME") Is Nothing, "Anonymous", Request.Params("USERNAME")) |
| 18 | Dim password As String = IIF(Request.Params("PASSWORD") Is Nothing, "", Request.Params("PASSWORD")) |
| 19 | Dim layout As String = IIF(Request.Params("LAYOUT") Is Nothing, "Library://MyLayout.WebLayout", Request.Params("LAYOUT")) |
| 20 | Dim locale As String = IIF(Request.Params("LOCALE") Is Nothing, "en", Request.Params("LOCALE")) |
| 21 | |
| 22 | |
| 23 | 'Setup connection |
| 24 | Dim host As New Uri("http://localhost/mapguide/mapagent/mapagent.fcgi") |
| 25 | Dim conn As New HttpServerConnection(host, username , password, locale, True) |
| 26 | |
| 27 | 'Obtain the weblayout and map |
| 28 | Dim weblayout as WebLayout = con.GetWebLayout(layout) |
| 29 | Dim mapdefinition as MapDefinition = con.GetMapDefinition(weblayout.Map.ResourceId) |
| 30 | |
| 31 | 'Modify the initial view of the weblayout |
| 32 | weblayout.Map.InitialView = new MapViewType() |
| 33 | weblayout.Map.InitialView.Scale = 2000 'Zoom to 1:2000 |
| 34 | weblayout.Map.InitialView.CenterX = (mapdefinition.Extents.MaxX - mapdefinition.Extents.MinX) + mapdefinition.Extents.MinX |
| 35 | weblayout.Map.InitialView.CenterY = (mapdefinition.Extents.MaxY - mapdefinition.Extents.MinX) + mapdefinition.Extents.MinY |
| 36 | |
| 37 | 'Obtain a unique session based id for the temporary weblayout (which is a copy of an existing WebLayout) |
| 38 | Dim tempid as ResourceIdentifier = new ResourceIdentifier(Guid.NewGuid(), OSGeo.MapGuide.MaestroAPI.ResourceTypes.WebLayout, con.SessionID) |
| 39 | |
| 40 | 'Save the layout, otherwise you can't reference it |
| 41 | con.SaveResourceAs(weblayout, tempid) |
| 42 | |
| 43 | 'Open the viewer, and use the temporary layout, since the map only exists in the |
| 44 | 'current session, we must use that session, and NOT supply username/password |
| 45 | Response.Redirect("/mapguide/ajaxviewer/?LAYOUT=" & Server.UrlEncode(tempWebLayout) & "&SESSION=" & Server.UrlEncode(con.SessionID), true) |
| 46 | }}} |