| 1 | = Utilizing RuntimeMap via Meastro API = |
| 2 | |
| 3 | Just a quick one on creating and using RuntimeMaps via Meastro API. To get Meastro API going please download latest Meastro 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 - you example (ASP.NET page) may reside on remote computer calling MG server via HTTP. |
| 4 | |
| 5 | (VB.NET) |
| 6 | {{{ |
| 7 | Imports OSGeo.MapGuide.MaestroAPI |
| 8 | ... |
| 9 | |
| 10 | ' Create an Uri object pointing to mapagent.fcgi location |
| 11 | Dim host As New Uri("http://myserver/mapguide2009/mapagent/mapagent.fcgi") |
| 12 | |
| 13 | ' Create HttpServerConnection object with credentials enabling establishing a session |
| 14 | Dim conn As New HttpServerConnection(host, "Administrator", "admin", "en", True) |
| 15 | |
| 16 | ' Get a helper reference object to a Map resource named PLAN stored in a Library |
| 17 | Dim res As New ResourceIdentifier("MyFolder/Maps/PLAN", ResourceTypes.MapDefinition) |
| 18 | |
| 19 | ' Let ResourceIdentifier helper class tell us map's ResourceId |
| 20 | Dim mapId As String = res.ResourceId |
| 21 | |
| 22 | ' Now get MapDefinition for our map named PLAN |
| 23 | Dim mapDef As MapDefinition = conn.GetMapDefinition(mapId) |
| 24 | |
| 25 | ' Here, ResourceIdentifier helper class tells us map name |
| 26 | Dim mapName As String = res.Name |
| 27 | |
| 28 | ' Now we decide on a name for our runtime map (stored in a Session) |
| 29 | Dim rtMapId As String = "Session:" + conn.SessionID + "//" + mapName + ".Map" |
| 30 | |
| 31 | ' Finally, we're telling HttpServerConnection to create runtime map |
| 32 | conn.CreateRuntimeMap(rtMapId, mapDef) |
| 33 | |
| 34 | ' And here it is - an instance of our brand new RuntimeMap object |
| 35 | Dim rtMap As RuntimeClasses.RuntimeMap = conn.GetRuntimeMap(rtMapId) |
| 36 | }}} |
| 37 | |
| 38 | 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 turned off: |
| 39 | |
| 40 | {{{ |
| 41 | ' Simply tell the PARCELS layer to turn on |
| 42 | rtMap.Layers("PARCELS").Visible = True |
| 43 | |
| 44 | ' Don't forget - you need to commit any change to RuntimeMap using HttpServerConnection.SaveRuntimeMap() method |
| 45 | conn.SaveRuntimeMap(rtMapId, rtMap) |
| 46 | }}} |
| 47 | |
| 48 | That's it for starters. More to come. |
| 49 | |
| 50 | |