[mapguide-users] RE: [Mapguide_users] FW: Remove layers at runtime
Buscher, Shane
Shane.Buscher at nngco.com
Thu Jan 18 12:06:26 EST 2007
Thanks so much for your help. I'll try the workaround you suggested.
Regards,
Shane
________________________________
From: mapguide-users-bounces at lists.osgeo.org
[mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of Walt
Welton-Lair
Sent: Thursday, January 18, 2007 10:54 AM
To: mapguide-users at lists.osgeo.org
Subject: RE: [mapguide-users] RE: [Mapguide_users] FW: Remove layers at
runtime
Shane,
I've determined that there are two problems preventing this from working
correctly.
1) There's a MapGuide server bug in which the information needed to
remove the layer from the DWF Viewer is not encoded properly.
2) There's a refresh bug in DWF Viewer - when a layer is removed the
graphics associated with that layer are not getting removed.
The first problem will cause the layer/legend control to not update
correctly. But if you're hiding that control then it doesn't matter all
that much.
The second problem is what's causing your refresh issues. There is a
workaround for this: you need to force a full refresh of the DWF Viewer.
This tells the viewer to throw away all graphical data and re-request
it. You're actually seeing this happen when you zoom out (after 4-5
zooms, as you wrote). And note that despite the first bug you'll get
back the correct graphics because the layers have been removed on the
server, just not in the client.
To force the full refresh you'll need to modify your script code:
Dim javaScript As String =
"parent.parent.mapFrame.emapViewer.Document.ForceRefresh = true;
parent.parent.mapFrame.Refresh();"
You might have to edit this. Basically you need to get to the instance
of the DWF Viewer control (in MapGuide this is stored in the emapViewer
variable - see dwfmappane.templ), set its Document.ForceRefresh property
to true, and then call Refresh.
I'll be submitting a fix for the first bug shortly. The DWF Viewer bug
will get addressed in a future release of the viewer.
Of course your other option is to use AJAX viewer...
Hope this helps.
Walt
________________________________
From: Buscher, Shane [mailto:Shane.Buscher at nngco.com]
Sent: Thursday, January 18, 2007 3:29 PM
To: Walt Welton-Lair; Trevor Wekel
Subject: RE: [mapguide-users] RE: [Mapguide_users] FW: Remove layers at
runtime
Walt,
We're using DWF Viewer 6.5. Unfortunately I'm not adding the layers to
the legend at runtime, or even displaying the legend so I'm not sure if
it updates correctly. I'll try to test this out though and get back to
you.
-shane
________________________________
From: Walt Welton-Lair [mailto:walt.welton-lair at autodesk.com]
Sent: Thursday, January 18, 2007 7:25 AM
To: Buscher, Shane; Trevor Wekel
Subject: RE: [mapguide-users] RE: [Mapguide_users] FW: Remove layers at
runtime
I've made progress on this - I think it actually involves a couple of
bugs.
Two questions:
1/ does the DWF Viewer's layer/legend control correctly update when you
remove the layers?
2/ What version of DWF Viewer are you using (6.5 or 7.0)?
Thanks,
Walt
________________________________
From: Buscher, Shane [mailto:Shane.Buscher at nngco.com]
Sent: Tuesday, January 16, 2007 8:53 PM
To: Trevor Wekel; Walt Welton-Lair
Subject: RE: [mapguide-users] RE: [Mapguide_users] FW: Remove layers at
runtime
Thanks for looking into this!
________________________________
From: Trevor Wekel [mailto:trevor.wekel at autodesk.com]
Sent: Tuesday, January 16, 2007 11:24 AM
To: Buscher, Shane; Walt Welton-Lair; mapguide-users at lists.osgeo.org
Subject: RE: [mapguide-users] RE: [Mapguide_users] FW: Remove layers at
runtime
Ok. Looks like this is a bug in trunk and may be a bug in 1.0.2. We
are investigating and will keep you posted.
Thanks Shane,
Trevor
________________________________
From: Buscher, Shane [mailto:Shane.Buscher at nngco.com]
Sent: Tuesday, January 16, 2007 6:48 AM
To: Trevor Wekel; Walt Welton-Lair; mapguide-users at lists.osgeo.org
Subject: RE: [mapguide-users] RE: [Mapguide_users] FW: Remove layers at
runtime
I'm running 1.02.
-shane
________________________________
From: Trevor Wekel [mailto:trevor.wekel at autodesk.com]
Sent: Monday, January 15, 2007 5:58 PM
To: Buscher, Shane; Walt Welton-Lair; mapguide-users at lists.osgeo.org
Subject: RE: [mapguide-users] RE: [Mapguide_users] FW: Remove layers at
runtime
Hi Shane,
Walt and I are digging through some code. What version of MapGuide are
you on?
Thanks,
Trevor
________________________________
From: Buscher, Shane [mailto:Shane.Buscher at nngco.com]
Sent: Monday, January 15, 2007 2:51 PM
To: Walt Welton-Lair; mapguide-users at lists.osgeo.org
Subject: RE: [mapguide-users] RE: [Mapguide_users] FW: Remove layers at
runtime
Walt,
My code works fine with the AJAX viewer, so the refresh problem is
related exclusively to the DWF viewer.
Here's the results I'm seeing in the DWF viewer after trying to remove
layers at runtime:
Action Result
Javascript Refresh() Does not
remove layers
Exec built in Refresh command Does not remove layers
Pan multiple times Does not remove
layers
Zoom In multiple times Does not remove
layers
Zoom Out multiple times Layers are removed
Remove layers when not in their map extent Layers are removed
Specifically, when zooming out about 4-5 times the layers are
consistently removed. Hope this helps.
-shane
________________________________
From: mapguide-users-bounces at lists.osgeo.org
[mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of Walt
Welton-Lair
Sent: Monday, January 15, 2007 3:22 PM
To: mapguide-users at lists.osgeo.org
Subject: RE: [mapguide-users] RE: [Mapguide_users] FW: Remove layers at
runtime
There's a server-side bug in the current MapGuide code where the DWF
Viewer isn't properly refreshed after a pan. I don't know if that bug
made it into an actual released build though. If it did then that could
be related to the refresh problem you're seeing. Try interacting with
your map by simply panning a little and let us know if the view updates
correctly. The AJAX Viewer doesn't have this problem.
Walt
________________________________
From: Buscher, Shane [mailto:Shane.Buscher at nngco.com]
Sent: Monday, January 15, 2007 10:12 PM
To: Walt Welton-Lair; Mapguide_users at lists.osgeo.org; Trevor Wekel
Subject: RE: [mapguide-users] RE: [Mapguide_users] FW: Remove layers at
runtime
Walt/Trevor,
I'm definitely refreshing by calling the Refresh method in the viewer
api. My exact code is below. I know the refresh gets executed
successfully because I see a quick status bar in the top left corner of
the viewer flash. If I comment out the javascript call, no status bar
flashes. Furthermore, the built-in RefreshMap command that you can add
as a button in Studio doesn't work either after running the code snippet
below.
I also know, according to the users guide p. 56, that you don't have to
refresh the map from the client after adding layers because the
LayerCollection takes care of this for you. I've tested this when
adding layers, and this is true. I am somewhat assuming that removing a
layer would be the same. I wonder if there is a problem with the DWF
viewer. I suppose I can try the AJAX viewer... It might be really
helpful if somebody could duplicate the issue.
Regards,
Shane
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
'Remove layers
Dim lyr0 As MgLayer = map.GetLayers.GetItem(0)
Dim lyr1 As MgLayer = map.GetLayers.GetItem(1)
map.GetLayers.Remove(lyr0)
map.GetLayers.Remove(lyr1)
map.Save(resourceService)
'emit javascript to refresh map
Dim scriptKey As String = "Refresh"
If Not Page.ClientScript.IsStartupScriptRegistered(Me.GetType,
scriptKey) Then
Dim javaScript As String =
"parent.parent.mapFrame.Refresh();"
Page.ClientScript.RegisterStartupScript(Me.GetType,
scriptKey, javaScript, True)
End If
End Sub
________________________________
From: mapguide-users-bounces at lists.osgeo.org
[mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of Walt
Welton-Lair
Sent: Monday, January 15, 2007 1:52 PM
To: Mapguide_users at lists.osgeo.org
Subject: RE: [mapguide-users] RE: [Mapguide_users] FW: Remove layers at
runtime
Yeah a missing refresh would make sense. Isn't it the client's
responsibility though to request the refresh?
-----Original Message-----
From: mapguide-users-bounces at lists.osgeo.org on behalf of Trevor
Wekel
Sent: Mon 1/15/2007 7:12 PM
To: Buscher, Shane; Mapguide_users at lists.osgeo.org
Cc:
Subject: [mapguide-users] RE: [Mapguide_users] FW: Remove layers
at runtime
Hi Shane,
Hmm... I wonder if the viewer is not bothering to request the
map overlay image again? That would explain the behaviour you are
seeing.
Are you using a Windows box as a client? Are you familiar with
Fiddler?
Fiddler is an HTTP proxy that captures HTTP requests and
responses. If you install and use it, you should be able to see all the
traffic between the client and Web Extensions / MapAgent. There should
be a GETDYNAMICMAPOVERLAY request generated by the client. This request
should refresh the map and show the added/removed layers.
Also, are you using Base Map layers (ie. tiled images)? Base
Map layers should not be changed on the fly. They should be considered
static. This is probably not an issue since you are adding dynamic
layers but I just figured I would check.
Thanks,
Trevor
________________________________
From: Buscher, Shane [mailto:Shane.Buscher at nngco.com]
Sent: Monday, January 15, 2007 11:04 AM
To: Trevor Wekel; Mapguide_users at lists.osgeo.org
Subject: RE: [Mapguide_users] FW: Remove layers at runtime
Trevor,
I think I found a big hint after testing what you suggested.
When the layers I'm trying to remove are within the map view extent,
they do not 'disappear' upon removing them. However, If the layers are
completely outside the map view extent they indeed get removed with the
same code. It doesn't matter if it's one layer or multiples. Hopefully
this gives you something to work with.
Regards,
Shane
________________________________
From: Trevor Wekel [mailto:trevor.wekel at autodesk.com]
Sent: Monday, January 15, 2007 11:18 AM
To: Buscher, Shane; Mapguide_users at lists.osgeo.org
Subject: RE: [Mapguide_users] FW: Remove layers at runtime
Hi Shane,
My bad. I've been working with the Mapguide 1.1.x and trunk
branches. You are working on the released 1.0.x branch. Sorry for the
confusion. 1.0.x does not have the boolean return.
Is there any difference if you try to remove only one layer so
there are still layers on the map?
Thanks,
Trevor
________________________________
From: Buscher, Shane [mailto:Shane.Buscher at nngco.com]
Sent: Saturday, January 13, 2007 1:31 PM
To: Trevor Wekel; Mapguide_users at lists.osgeo.org
Subject: RE: [Mapguide_users] FW: Remove layers at runtime
Trevor,
MgLayerCollection.Remove doesn't return a boolean according to
the api documentation, and also doesn't indicate it in the intellisense.
Regards,
Shane
________________________________
From: Trevor Wekel [mailto:trevor.wekel at autodesk.com]
Sent: Fri 1/12/2007 5:18 PM
To: Buscher, Shane; Mapguide_users at lists.osgeo.org
Subject: RE: [Mapguide_users] FW: Remove layers at runtime
Hi Shane,
Remove() should returns a boolean true or false. false
indicates that the layer was not removed. Can you see if the remove was
successful? (just trying to debug a bit)
Thanks,
Trevor
________________________________
From: Buscher, Shane [mailto:Shane.Buscher at nngco.com]
Sent: Friday, January 12, 2007 4:13 PM
To: Trevor Wekel; Mapguide_users at lists.osgeo.org
Subject: RE: [Mapguide_users] FW: Remove layers at runtime
Trevor,
Thanks for the response. I think I'm doing everything you
suggested correctly, but have provided the snippets below. When the
page loads the ConnectToMapGuide() method gets called, which opens up
the MgMap and sets it to a module level variable (map). Then, Button1
is clicked which successfully adds two layers to the map. When Button2
gets invoked, I try to remove the layers but the layers still persist in
the map.
I'm not sure where to go from here. Do you need to copy the
layers in session, then add them from there in order to have the ability
to remove them? Just reaching...
Regards,
Shane
'class vars
Private resourceService As MgResourceService
Private map As MgMap
Private Sub ConnectToMapGuide()
'Connect to MapGuide site
Dim userInfo As New
MgUserInformation(Session.Item("mgSessionId"))
Dim siteConn As New MgSiteConnection
siteConn.Open(userInfo)
'set resource service
resourceService =
siteConn.CreateService(MgServiceType.ResourceService)
'Open map
map = New MgMap
map.Open(resourceService, Session.Item("mgMapName"))
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
'add dwf layer
Dim schematicId As NewMgResourceIdentifier _
("Library://VST/Layers/SouthOmahaTeamSchematic.LayerDefinition")
Dim schematic As MgLayer = CreateLayer(schematicId,
False)
map.GetLayers.Insert(index, schematic)
'add sdf layer
Dim valveId As New MgResourceIdentifier _
("Library://VST/Layers/SouthOmahaValves.LayerDefinition")
Dim valves As MgLayer = CreateLayer(valveId, True)
map.GetLayers.Insert(index, valves)
map.Save(resourceService)
'emit javascript to refresh map
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim lyr0 As MgLayer = map.GetLayers.GetItem(0)
Dim lyr1 As MgLayer = map.GetLayers.GetItem(1)
map.GetLayers.Remove(lyr0)
map.GetLayers.Remove(lyr1)
map.Save(resourceService)
'emit javascript to refresh map
End Sub
________________________________
From: Trevor Wekel [mailto:trevor.wekel at autodesk.com]
Sent: Friday, January 12, 2007 3:37 PM
To: Buscher, Shane; Mapguide_users at lists.osgeo.org
Subject: RE: [Mapguide_users] FW: Remove layers at runtime
Hi Shane,
This should work. During your setup, are you calling
MgMap.Open() or MgMap.Create()? The MgMap.Open() should set up the
resource identifier correctly so that Save() will have the map to the
correct session repository.
Is the session id being propagated correctly? If you can do the
following and the layer appears in the viewer then the session should be
ok.
MgMap.Open()
MgMap.GetLayers().Insert(layer)
MgMap.Save()
If the Insert() works and Remove() doesn't
MgMap.Open()
MgMap.GetLayers().Remove(layer)
MgMap.Save()
Then this is probably a bug. Also, does the behaviour depend on
the number remaining layers?
Thanks,
Trevor
________________________________
From: Buscher, Shane [mailto:Shane.Buscher at nngco.com]
Sent: Friday, January 12, 2007 7:16 AM
To: Buscher, Shane; Mapguide_users at lists.osgeo.org
Subject: RE: [Mapguide_users] FW: Remove layers at runtime
I haven't got any feedback yet, but I have been trying
desperately to make this work. To recap, I'm finding that adding a
layer to a map at runtime with MgLayerCollection.Add works fine.
However, when I try to remove layer(s) with MgLayerCollection.Clear,
MgLayerCollection.Remove, or MgLayerCollection.RemoveAt the layer(s) are
indeed removed from the collection- but not the map. I am saving the
map and refreshing the map after removal.
So why does inserting a layer into the MgMapCollection work, but
removing not? Looking at the developers guide on page 56 there is a
note for getting a layer collection from the map (MgMap.GetLayers):
In the MapGuide API, getting a collection returns a reference to
the collection. So adding the layer to the layer collection immediately
updates the map.
I am get the impression that adding a layer to the collection
automatically updates the map, this doesn't apply for removing a layer.
I can't figure out what I need to do to mimic what the api does for you
when inserting a layer when trying to remove a layer. Or is this a bug?
Thanks for any help in advance.
Regards,
Shane
________________________________
From: mapguide_users-bounces at lists.osgeo.org
[mailto:mapguide_users-bounces at lists.osgeo.org] On Behalf Of Buscher,
Shane
Sent: Tuesday, January 09, 2007 4:49 PM
To: Mapguide_users at lists.osgeo.org
Subject: [Mapguide_users] FW: Remove layers at runtime
I've run into issues with removing all layers from the map at
runtime. See the code snippet below. All the layers get removed from
the layerCollection, but the layers still display. I've successfully
used the same code to insert layers, except I execute the
layerCollection.Insert(index, layer) method. I don't know why the same
code wouldn't work for clearing layers.
I have multiple layers stored in a library repository that users
need to add and remove at runtime. Do I need to copy each layer in
indvidual session repositories to add and reomove them? If I don't,
will one user adding/removing layers affect other user sessions? I know
this is the case when you edit data, but these layers are view only.
'Connect to site server, set resource service, and open map
ConnectToMapGuide()
'Clear all layers in the map
Dim layerCollection As MgLayerCollection = map.GetLayers()
If layerCollection.GetCount > 0 Then
layerCollection.Clear()
End If
map.Save(resourceService)
'emit javascript to refresh map
Dim scriptKey As String = "ForceRefresh"
If Not Page.ClientScript.IsStartupScriptRegistered(Me.GetType,
scriptKey) Then
Dim javaScript As String = "refreshMap(" &
MapAction.RefreshMap & ");"
Page.ClientScript.RegisterStartupScript(Me.GetType, scriptKey,
javaScript, True)
End If
Regards,
Shane
Operations IT
Northern Natural Gas
402.398.7841
We think in generalities, but live in detail.
-Alred North Whitehead
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapguide-users/attachments/20070118/906cc010/attachment-0001.html
More information about the mapguide-users
mailing list