[mapguide-users] Changing existing dynamic layer's Filter on the fly
Maksim Sestic
max at geoinova.com
Thu Nov 15 08:06:36 EST 2007
I think I'm having problems with changing existing dynamic layer's Filter
property (the one that filters data from FeatureSource) using .NET. Here's
the approach that doesn't report any error, but when I refresh the map there
are no changes to the layer - new filter doesn't get applied.
Dim layer As MgLayer = ...getting a MgLayer object...
Dim document As New XmlDocument
document.PreserveWhitespace = True
Dim byteReader As MgByteReader =
resources.Service.GetResourceContent(layer.LayerDefinition)
document.LoadXml(byteReader.ToString)
Allright, it's all in XmlDocument now and then I do some parsing to change
the Filter element. When I save the definition to XML file (just for
testing) everything's OK, structure and data is preserved and Filter element
is set to some new value.
' Saving XmlDocument to memory stream
Dim stream As MemoryStream = New System.IO.MemoryStream()
document.Save(stream)
' Converting stream to byte array
Dim byteArray() As Byte = stream.ToArray
' Converting byte array to String (BOM included, otherwise SetResource
raises an error while parsing XML)
Dim outerXml As String = System.Text.Encoding.UTF8.GetString(byteArray, 0,
byteArray.Length - 1)
' Converting String to byte array with UTF-8 encoding
byteArray = System.Text.Encoding.UTF8.GetBytes(outerXml)
' Creating MgByteSource out of byte array, setting appropriate MimeType
Dim byteSource As MgByteSource = New MgByteSource(byteArray,
byteArray.Length)
byteSource.SetMimeType(MgMimeType.Xml)
' Getting MgResourceIdentifier corresponding to current SessionId and
existing Layer name
Dim resourceId As New
MgResourceIdentifier(String.Format("Session:{0}//{1}.LayerDefinition",
sessionId, layerName))
' Setting a resource (without Header) using MgResourceIdentifier and byte
source
resources.Service.SetResource(resourceId, byteSource.GetReader, Nothing)
' I don't know if this is necessary, but still...
layer.ForceRefresh()
Now, when I call parent.parent.Refresh() on the client side nothing happens.
What am I doing wrong here?
Regards,
Maksim Sestic
--
View this message in context: http://www.nabble.com/Changing-existing-dynamic-layer%27s-Filter-on-the-fly-tf4811727s16610.html#a13767148
Sent from the MapGuide Users mailing list archive at Nabble.com.
More information about the mapguide-users
mailing list