[mapguide-users] RE: [Mapguide_users] FW: Remove layers at runtime

Buscher, Shane Shane.Buscher at nngco.com
Fri Jan 12 18:12:44 EST 2007



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


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...







'class vars

Private resourceService As MgResourceService

Private map As MgMap


Private Sub ConnectToMapGuide()

        'Connect to MapGuide site

        Dim userInfo As New

        Dim siteConn As New MgSiteConnection



        'set resource service

        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 _        


         Dim schematic As MgLayer = CreateLayer(schematicId, False)

         map.GetLayers.Insert(index, schematic)


         'add sdf layer

   Dim valveId As New MgResourceIdentifier _ 


         Dim valves As MgLayer = CreateLayer(valveId, True)

         map.GetLayers.Insert(index, valves)




        '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)





        '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


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






If the Insert() works and Remove() doesn't






Then this is probably a bug.  Also, does the behaviour depend on the
number remaining layers?







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.  






From: mapguide_users-bounces at lists.osgeo.org
[mailto:mapguide_users-bounces at lists.osgeo.org] On Behalf Of Buscher,
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


'Clear all layers in the map

Dim layerCollection As MgLayerCollection = map.GetLayers()

If layerCollection.GetCount > 0 Then


End If


'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



Operations IT

Northern Natural Gas


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/20070112/815a3252/attachment-0001.html

More information about the mapguide-users mailing list