[mapguide-users] Changing existing dynamic layer's Filter on the fly

Maksim Sestic max at geoinova.com
Thu Nov 15 08:59:49 EST 2007


Hi Kenneth,

It would be much easier if MgLayer had Filter property in first place :-)
Alas, it doesn't (MGE 2008). It has FeatureSourceId and FeatureClassName
properties, though, but not Filter property (and I have no clue why's that,
probably somebody forgot to expose it).

So I guess I still have to drill down the layer's XML definition to change
the element value. But then, how do I change layer definition of runtime map
and get it refreshed in Ajax viewer?

Regards,
Maksim Sestic


Kenneth, GEOGRAF A/S wrote:
> 
> When the MapDefinition is turned into a runtime Map, it copies 
> properties from the layerdefinition.
> This means that you will see no changes, even if you choose to modify 
> the LayerDefinition.
> 
> You must modify the layer copy in the runtime map.
> Fortunately, that is actually easier than what you are doing now:
> 
> MgMap map = new MgMap();
> map.Open("map", srv);
> 
> map.Layers("layername").Filter = "Column = 5";
> map.Save();
> 
> Regards, Kenneth, GEOGRAF A/S
> 
> 
> 
> Maksim Sestic skrev:
>> 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
>>
>>
>>
>>
>>  
>>   
> _______________________________________________
> mapguide-users mailing list
> mapguide-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapguide-users
> 
> 

-- 
View this message in context: http://www.nabble.com/Changing-existing-dynamic-layer%27s-Filter-on-the-fly-tf4811727s16610.html#a13768007
Sent from the MapGuide Users mailing list archive at Nabble.com.



More information about the mapguide-users mailing list