wiki:maestro/MaestroAPI/samples/RuntimeMap

Version 6 (modified by ksgeograf, 16 years ago) ( diff )

--

Utilizing RuntimeMap via Meastro API

This page describes how to use the MaestroAPI from the MapGuide Maestro project in your own application.

Just a quick one on creating and using RuntimeMaps via Meastro API. To get Meastro API going please download latest Maestro package, then reference OSGeo.MapGuide.MaestroAPI.dll and MapGuideDotNetApi.dll only. This example uses Maestro API HttpServerConnection object which talks to the MG's mapagent.fcgi via HTTP. In other words - your code (i.e. ASP.NET page) may reside on remote computer calling MG server via HTTP.

(VB.NET)

Imports OSGeo.MapGuide.MaestroAPI
...

' Create an Uri object pointing to mapagent.fcgi location
Dim host As New Uri("http://myserver/mapguide2009/mapagent/mapagent.fcgi")

' Create HttpServerConnection object with credentials enabling establishing a session
Dim conn As New HttpServerConnection(host, "Administrator", "admin", "en", True)

' Get a helper reference object to a Map resource named PLAN stored in a Library
Dim res As New ResourceIdentifier("MyFolder/Maps/PLAN", ResourceTypes.MapDefinition)

' Let ResourceIdentifier helper class tell us map's ResourceId
Dim mapId As String = res.ResourceId

' Now get MapDefinition for our map named PLAN
Dim mapDef As MapDefinition = conn.GetMapDefinition(mapId)

' Here, ResourceIdentifier helper class tells us map name
Dim mapName As String = res.Name

'Make a new ResourceIdentifier class to point to the runtime map in the session repository.
Dim rtMapId as String = new ResourceIdentifier(mapName, ResourceTypes.RuntimeMap, conn.SessionID)

' Finally, we're telling HttpServerConnection to create runtime map
conn.CreateRuntimeMap(rtMapId, mapDef)

' And here it is - an instance of our brand new RuntimeMap object 
Dim rtMap As RuntimeClasses.RuntimeMap = conn.GetRuntimeMap(rtMapId)

Having a reference to RuntimeMap enables us manipulating Library-resident map "clone" (see conn.CreateRuntimeMap) sitting in a Session. Don't forget - each MG Session may have different instance of RuntimeMap in it. When RuntimeMap is created, it's properties (including layers, layer visibility, etc.) is inherited from the original MapDefinition. Let's change visibility of PARCELS layer initially being turned off:

' Simply tell the PARCELS layer to turn on
rtMap.Layers("PARCELS").Visible = True

' Don't forget - you need to commit any change to RuntimeMap using HttpServerConnection.SaveRuntimeMap() method
conn.SaveRuntimeMap(rtMapId, rtMap)

That's it for starters. More to come.

Note: See TracWiki for help on using the wiki.