wiki:maestro/MaestroAPI/samples/ModifyLayerFilter

Utilizing RuntimeMap via Maestro API

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

This example shows how to modify the filter of a layer, so it displays another subset of the features. The filter is changed only in the current session, meaning that other users won't be affected. The code should be placed in an aspx page, otherwise the RegisterStartupScript? call won't work.

This example uses the http version, so no MapGuide binaries are required. Read about the difference between LocalNativeConnection and HttpServerConnection here

(VB.NET)

Imports OSGeo.MapGuide.MaestroAPI
...

'Read setup from querystring or form
Dim sessionID As String = Request.Params("SESSIONID")
Dim mapdefinition As String = Request.Params("MAPDEFINITION")
Dim layername As String = Request.Params("LAYERNAME")
Dim newFilter As String = Request.Params("NEWFILTER")

'Replace "myserver" with the server name, or use "localhost"
Dim host As New Uri("http://myserver/mapguide/mapagent/mapagent.fcgi")
Dim conn as ServerConnectionI = New HttpServerConnection(host, sessionID, "en", true)

'Use the same naming system as the viewer, when reading the runtime map ID
Dim mapName as String = new ResourceIdentifier(mapdefinition).Name
Dim rtMapId as String = new ResourceIdentifier(mapName, ResourceTypes.RuntimeMap, conn.SessionID)

'Load the runtime map
Dim rtMap as RuntimeClasses.RuntimeMap = conn.GetRuntimeMap(rtMapId)
Dim rtLayer as RuntimeClasses.RuntimeMapLayer = rtMap.Layers(layername)

'Get the current layer and assing the filter
Dim layerDefinition as LayerDefinition = conn.GetLayerDefinition(rtLayer.ResourceId)
Dim vectorLayerDefinition as VectorLayerDefinitionType = layerDefinition.Item
vectorLayerDefinition.Filter = newFilter

'Save a copy of the layer, temporary, and random name
rtLayer.ResourceID = new ResourceIdentifier(Guid.NewGuid().ToString(), ResourceTypes.LayerDefinition, conn.SessionID)
conn.SaveResourceAs(layerDefinition, rtLayer.ResourceID)

'Save the runtime map, pointing to the updated layerdefinition
conn.SaveRuntimeMap(rtMapId, rtMap)

'Tell the client to refresh
RegisterStartupScript("key", "<script>GetMapFrame().Refresh();</script>")

Last modified 5 years ago Last modified on Jan 22, 2013 6:21:11 PM