| 1 | == Utilizing !RuntimeMap via Maestro API == |
| 2 | This page describes how to use the MaestroAPI from the [wiki:maestro MapGuide Maestro] project in your own application. |
| 3 | |
| 4 | This example shows how to modify the filter of a layer, so it displays another subset of the features. |
| 5 | The filter is changed only in the current session, meaning that other users won't be affected. |
| 6 | The code should be placed in an aspx page, otherwise the RegisterStartupScript 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 setup from querystring or form |
| 17 | Dim sessionID As String = Request.Params("SESSIONID") |
| 18 | Dim mapdefinition As String = Request.Params("MAPDEFINITION") |
| 19 | Dim layername As String = Request.Params("LAYERNAME") |
| 20 | Dim newFilter As String = Request.Params("NEWFILTER") |
| 21 | |
| 22 | 'Replace "myserver" with the server name, or use "localhost" |
| 23 | Dim host As New Uri("http://myserver/mapguide/mapagent/mapagent.fcgi") |
| 24 | Dim conn as ServerConnectionI = New HttpServerConnection(host, sessionID, "en", true) |
| 25 | |
| 26 | 'Use the same naming system as the viewer, when reading the runtime map ID |
| 27 | Dim mapName as String = new ResourceIdentifier(mapdefinition).Name |
| 28 | Dim rtMapId as String = new ResourceIdentifier(mapName, ResourceTypes.RuntimeMap, conn.SessionID) |
| 29 | |
| 30 | 'Load the runtime map |
| 31 | Dim rtMap as RuntimeClasses.RuntimeMap = conn.GetRuntimeMap(rtMapId) |
| 32 | Dim rtLayer as RuntimeClasses.RuntimeMapLayer = rtMap.Layers(layername) |
| 33 | |
| 34 | 'Get the current layer and assing the filter |
| 35 | Dim layerDefinition as LayerDefinition = conn.GetLayerDefinition(rtLayer.ResourceId) |
| 36 | Dim vectorLayerDefinition as VectorLayerDefinitionType = layerDefinition.Item |
| 37 | vectorLayerDefinition.Filter = newFilter |
| 38 | |
| 39 | 'Save a copy of the layer, temporary, and random name |
| 40 | rtLayer.ResourceID = new ResourceIdentifier(Guid.NewGuid().ToString(), ResourceTypes.LayerDefinition, conn.SessionID) |
| 41 | conn.SaveResourceAs(layerDefinition, rtLayer) |
| 42 | |
| 43 | 'Save the runtime map, pointing to the updated layerdefinition |
| 44 | conn.SaveRuntimeMap(rtMapId, rtMap) |
| 45 | |
| 46 | 'Tell the client to refresh |
| 47 | RegisterStartupScript("key", "<script>GetMapFrame().Refresh();</script>") |
| 48 | |
| 49 | }}} |