Changes between Initial Version and Version 1 of maestro/MaestroAPI/samples/CustomizedZoomWithWebLayout


Ignore:
Timestamp:
Dec 2, 2008, 4:48:55 AM (15 years ago)
Author:
ksgeograf
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • maestro/MaestroAPI/samples/CustomizedZoomWithWebLayout

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