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


Ignore:
Timestamp:
Oct 14, 2008, 7:40:15 AM (16 years ago)
Author:
ksgeograf
Comment:

--

Legend:

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

    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
     5An example of how to add a layer to the map BEFORE it is loaded, using Meastro API. To get Maestro API, please download latest Maestro package, then reference OSGeo.!MapGuide.MaestroAPI.dll and !MapGuideDotNetApi.dll only.
     6
     7If you choose the local version below, Maestro API communicates with MapGuide through a !LocalNativeConnection object which talks to MG through a native connection. So all the !MapGuide unmanaged DLL's must be present in the applications Bin folder.
     8
     9If you choose the remote version, Maestro API communicates with MapGuide through HTTP and no MapGuide binaries are required.
     10
     11Read about [wiki:maestro/MaestroAPI/basics the difference between LocalNativeConnection and HttpServerConnection here]
     12
     13(VB.NET)
     14{{{
     15Imports OSGeo.MapGuide.MaestroAPI
     16...
     17
     18'Read the setup, either from QueryString, Form, Cookies or hardcoded values
     19Dim username As String = IIF(Request.Params("USERNAME") Is Nothing, "Anonymous", Request.Params("USERNAME"))
     20Dim password As String = IIF(Request.Params("PASSWORD") Is Nothing, "", Request.Params("PASSWORD"))
     21Dim layout As String = IIF(Request.Params("LAYOUT") Is Nothing, "Library://MyLayout.WebLayout", Request.Params("LAYOUT"))
     22Dim locale As String = IIF(Request.Params("LOCALE") Is Nothing, "en", Request.Params("LOCALE"))
     23
     24
     25'Create a connection to MapGuide
     26Dim conn As IServerConnection
     27
     28'Pick your connection method here
     29Dim local As Boolean = True
     30
     31If (local) Then
     32    'Replace "webconfig.ini" with the full path to "webconfig.ini"
     33    conn = New LocalNativeConnection("webconfig.ini", username, password, "en")
     34Else
     35    'Replace "myserver" with the server name, or use "localhost"
     36    Dim host As New Uri("http://myserver/mapguide/mapagent/mapagent.fcgi")
     37    conn = New HttpServerConnection(host, username, password, "en", true)
     38End If
     39
     40
     41'Get the original layout
     42Dim weblayout As WebLayout = conn.GetWebLayout(layout )
     43
     44'Get the mapDefinition
     45Dim mapDef As MapDefinition = conn.GetMapDefinition(weblayout .Map.ResourceId)
     46
     47'Create a new MapLayer object
     48Dim layer As new MapLayerType()
     49
     50'Absolute minimum properties
     51layer.Visible = true
     52layer.ResourceId = "Library://MyExtraLayer.LayerDefinition"
     53
     54'Extra properties
     55layer.ExpandInLegend = true
     56layer.ShowInLegend = true
     57layer.LegendLabel = "My layer"
     58layer.Name = "MyLayer"
     59
     60'Add the layer to the MapDefinition
     61mapDef.Layers.Add(layer)
     62
     63'Generate a temporary MapDefinition id
     64Dim tempMapDef As String = new ResourceIdentifier("MyMap", ResourceTypes.MapDefinition, con.SessionID)
     65
     66'Save the modified map at its new temporary location
     67con.SaveResourceAs(mapDef, tempMapDefName)
     68
     69'Generate a temporary WebLayout id
     70Dim tempWebLayout As String = new ResourceIdentifier("MyMap", ResourceTypes.WebLayout, con.SessionID)
     71
     72'Update the WebLayout to point at the modified MapDefinition
     73weblayout.Map.ResourceId = tempMapDef
     74
     75'Save the modified layout at its new temporary location
     76con.SaveResourceAs(weblayout, tempWebLayout)
     77
     78'Redirect the page to the viewer, using the temporary map
     79Response.Redirect("/mapguide/ajaxviewer/?LAYOUT=" & Server.UrlEncode(tempWebLayout) & "&SESSION=" &  Server.UrlEncode(con.SessionID), true)
     80}}}