[mapguide-users] Getting all object Enveloppe

David Hequet david.hequet at free.fr
Tue Jun 5 08:28:33 EDT 2007


Thank you, i wrote a method using my method (using au selection object). I
will try to optimize it with your advice later. I'm curently busy with the
"set the extent to the map in the session" part of my dev. Here is what i
did:

'infos:
'me._map = map resource in the session
'aMgEnveloppe = valid mgenveloppe of my data
'me._sessionId = current mapguide session

Dim aMgByteReader As MgByteReader
Dim aContent As String
Dim anXmlDoc As XmlDocument
Dim anXmlNode As XmlNode
Dim aRootNode As XmlNode

' lecture du contenu de definition de la carte pour retrouver le nom de la
resource associée
aMgByteReader =
Me._resourceService.GetResourceContent(Me._map.GetMapDefinition())
aContent = aMgByteReader.ToString()
anXmlDoc = New XmlDocument()
anXmlDoc.LoadXml(aContent)

aRootNode = anXmlDoc.DocumentElement
' modification des etendues
anXmlNode = aRootNode.SelectSingleNode("Extents/MinX")
anXmlNode.ChildNodes(0).Value = aMgEnveloppe.GetLowerLeftCoordinate.GetX
anXmlNode = aRootNode.SelectSingleNode("Extents/MinY")
anXmlNode.ChildNodes(0).Value = aMgEnveloppe.GetLowerLeftCoordinate.GetY
anXmlNode = aRootNode.SelectSingleNode("Extents/MaxX")
anXmlNode.ChildNodes(0).Value = aMgEnveloppe.GetUpperRightCoordinate.GetX
anXmlNode = aRootNode.SelectSingleNode("Extents/MaxY")
anXmlNode.ChildNodes(0).Value = aMgEnveloppe.GetUpperRightCoordinate.GetY

Dim anXmlStream As MemoryStream = New MemoryStream()

anXmlDoc.Save(anXmlStream)
Dim aMapDefinition() As Byte = anXmlStream.ToArray()
Dim utf8 As Encoding = Encoding.UTF8
Dim aMapDefStr As String = New String(utf8.GetChars(aMapDefinition))
aMapDefinition = New Byte(aMapDefStr.Length - 1) {}
'Dim byteCount As Integer = utf8.GetBytes(aMapDefStr, 1, aMapDefStr.Length -
1, aMapDefinition, 0)

Dim aByteSource As MgByteSource = New MgByteSource(aMapDefinition,
aMapDefinition.Length())
aByteSource.SetMimeType(MgMimeType.Xml)

Dim aMgByteReader2 As MgByteReader = aByteSource.GetReader()

Dim mapStateId As MgResourceIdentifier = New MgResourceIdentifier("Session:"
+ Me._sessionId + "//" + Me._map.GetName() + "." + MgResourceType.Map)
Me._resourceService.SetResource(mapStateId, aMgByteReader, Nothing)

I don't have any error, but when i refresh the map or try a "zoom to initial
view" nothing happen.
Maybe might i update the weblayout's initial view? (but scale calc needed..)

Anyone got an idea?
Thank you


Kenneth, GEOGRAF A/S wrote:
> 
> You don't have to use the selection part.
> You can extract the object directly from the feature reader.
> Once you have the object, you can also get the extent (aka bbox).
> If you then construct an envelope object, you can add the features 
> envelope to original envelope.
> 
> Something like:
> 
> create a new MgFeatureQueryOptions with an empty filter
> create a new Envelope
> For Each Layer
> {
>    Use a featureReader with the MgFeatureQueryOptions
>    Add the feature's envelope to the outer Envelope
> }
> Get zoom extents from the Envelope
> 
> 
> Other than this, I don't think you can optimize it anymore, as you need 
> to execute the query on each layer.
> 
> I think there is a "Get Extents" on the feature source, but I can't find 
> it. And I don't think it works on filtered datasources.
> 
> Perhaps you can execute the query with some SQL optimizations like 
> "Select Envelope(geometry) from datasource".
> 
> Hope it helps.
> 
> Regards, Kenneth, GEOGRAF A/S
> 
> 
> 
> David Hequet wrote:
>> Hello,
>>
>> I'm trying to make a fonction that can return me the enveloppe of the
>> entire
>> visible map (no way with original map extent).
>>
>> Explain: I have a map "template" with a lot of layers, i have a function
>> that change all the layer filter (basic filter, no spatial) to see
>> different
>> map based on that template. Doing that make the "zoom to original extent"
>> useless, because data are not on the same area.
>> I wan't to set the new map extent in the MapDefinition. 
>> My ask is about getting the new extent.
>>
>> I thought to do it like that:
>>
>> create a new MgSelection
>> create a new MgFeatureQueryOptions with an empty filter
>> For Each Layer
>> {
>>    Use a featureReader with the MgFeatureQueryOptions
>>    Add the selected feature to the MgSelection
>> }
>> Getting the MgSelection enveloppe
>>
>> It will work, but i don't think it's very optimized with a lot of
>> Layer/Feature (and it will used at each map load, filter modification..)
>>
>> Did someone have a better way?
>>
>> Thank you!
>>
>> Ps: sorry for my poor english, ask i you want precision.
>>   
> _______________________________________________
> 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/Getting-all-object-Enveloppe-tf3864317s16610.html#a10968414
Sent from the MapGuide Users mailing list archive at Nabble.com.



More information about the mapguide-users mailing list