<HTML dir=ltr><HEAD><TITLE>FW: Remove layers at runtime</TITLE>
<META http-equiv=Content-Type content="text/html; charset=unicode">
<META content="MSHTML 6.00.2900.3020" name=GENERATOR>
<STYLE>font-face {
        font-family: Tahoma;
}
font-face {
        font-family: StoneSans;
}
P.MsoNormal {
        FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman"
}
LI.MsoNormal {
        FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman"
}
DIV.MsoNormal {
        FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman"
}
A:link {
        COLOR: blue; TEXT-DECORATION: underline
}
SPAN.MsoHyperlink {
        COLOR: blue; TEXT-DECORATION: underline
}
A:visited {
        COLOR: purple; TEXT-DECORATION: underline
}
SPAN.MsoHyperlinkFollowed {
        COLOR: purple; TEXT-DECORATION: underline
}
P {
        FONT-SIZE: 12pt; MARGIN-LEFT: 0in; MARGIN-RIGHT: 0in; FONT-FAMILY: "Times New Roman";}
SPAN.EmailStyle18 {
        COLOR: navy; FONT-FAMILY: Arial;}
SPAN.EmailStyle19 {
        COLOR: navy; FONT-FAMILY: Arial;}
DIV.Section1 {
        page: Section1
}
</STYLE>
<BASE href=https://nngowa.nngco.com/exchange/Shane.Buscher/Drafts/RE:%20%5BMapguide_users%5D%20FW:%20Remove%20layers%20at%20runtime.EML/1_text.htm></HEAD>
<BODY lang=EN-US vLink=purple link=blue>
<DIV id=idOWAReplyText61961 dir=ltr>
<DIV dir=ltr><FONT face=Arial color=#000000 size=2>Trevor,</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>MgLayerCollection.Remove doesn't return a boolean according to the api documentation, and also doesn't indicate it in the intellisense. </FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>Regards,</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>Shane</FONT></DIV></DIV>
<DIV dir=ltr><BR>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> Trevor Wekel [mailto:trevor.wekel@autodesk.com]<BR><B>Sent:</B> Fri 1/12/2007 5:18 PM<BR><B>To:</B> Buscher, Shane; Mapguide_users@lists.osgeo.org<BR><B>Subject:</B> RE: [Mapguide_users] FW: Remove layers at runtime<BR></FONT><BR></DIV>
<DIV>
<DIV dir=ltr align=left><SPAN class=120501723-12012007><FONT face=Arial color=#0000ff size=2>Hi Shane,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=120501723-12012007><FONT face=Arial color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=120501723-12012007><FONT face=Arial color=#0000ff size=2>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)</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=120501723-12012007><FONT face=Arial color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=120501723-12012007><FONT face=Arial color=#0000ff size=2>Thanks,<BR>Trevor</FONT></SPAN></DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> Buscher, Shane [mailto:Shane.Buscher@nngco.com] <BR><B>Sent:</B> Friday, January 12, 2007 4:13 PM<BR><B>To:</B> Trevor Wekel; Mapguide_users@lists.osgeo.org<BR><B>Subject:</B> RE: [Mapguide_users] FW: Remove layers at runtime<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV class=Section1>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">Trevor,</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">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. </SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">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…</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">Regards,</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">Shane</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face="Courier New" color=green size=2><SPAN style="FONT-SIZE: 10pt; COLOR: green; FONT-FAMILY: 'Courier New'">‘class vars</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">Private</SPAN></FONT><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> resourceService <FONT color=blue><SPAN style="COLOR: blue">As</SPAN></FONT> MgResourceService</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">Private</SPAN></FONT><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> map <FONT color=blue><SPAN style="COLOR: blue">As</SPAN></FONT> MgMap<FONT color=green><SPAN style="COLOR: green"></SPAN></FONT></SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face="Courier New" color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">Private</SPAN></FONT><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <FONT color=blue><SPAN style="COLOR: blue">Sub</SPAN></FONT> ConnectToMapGuide()</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <FONT color=green><SPAN style="COLOR: green">'Connect to MapGuide site</SPAN></FONT></SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <FONT color=blue><SPAN style="COLOR: blue">Dim</SPAN></FONT> userInfo <FONT color=blue><SPAN style="COLOR: blue">As</SPAN></FONT> <FONT color=blue><SPAN style="COLOR: blue">New</SPAN></FONT> MgUserInformation(Session.Item(<FONT color=maroon><SPAN style="COLOR: maroon">"mgSessionId"</SPAN></FONT>))</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <FONT color=blue><SPAN style="COLOR: blue">Dim</SPAN></FONT> siteConn <FONT color=blue><SPAN style="COLOR: blue">As</SPAN></FONT> <FONT color=blue><SPAN style="COLOR: blue">New</SPAN></FONT> MgSiteConnection</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> siteConn.Open(userInfo)</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <FONT color=green><SPAN style="COLOR: green">'set resource service</SPAN></FONT></SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> resourceService = siteConn.CreateService(MgServiceType.ResourceService)</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <FONT color=green><SPAN style="COLOR: green">'Open map</SPAN></FONT></SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> map = <FONT color=blue><SPAN style="COLOR: blue">New</SPAN></FONT> MgMap</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> map.Open(resourceService, Session.Item(<FONT color=maroon><SPAN style="COLOR: maroon">"mgMapName"</SPAN></FONT>))</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">End</SPAN></FONT><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <FONT color=blue><SPAN style="COLOR: blue">Sub</SPAN></FONT></SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face="Courier New" color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">Protected</SPAN></FONT><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <FONT color=blue><SPAN style="COLOR: blue">Sub</SPAN></FONT> Button1_Click(<FONT color=blue><SPAN style="COLOR: blue">ByVal</SPAN></FONT> sender <FONT color=blue><SPAN style="COLOR: blue">As</SPAN></FONT> <FONT color=blue><SPAN style="COLOR: blue">Object</SPAN></FONT>, <FONT color=blue><SPAN style="COLOR: blue">ByVal</SPAN></FONT> e <FONT color=blue><SPAN style="COLOR: blue">As</SPAN></FONT> System.EventArgs) <FONT color=blue><SPAN style="COLOR: blue">Handles</SPAN></FONT> Button1.Click</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <FONT color=green><SPAN style="COLOR: green">‘add dwf layer</SPAN></FONT></SPAN></FONT></P>
<P class=MsoNormal style="TEXT-INDENT: 0.5in"><FONT face="Courier New" color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'"> Dim</SPAN></FONT><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> schematicId <FONT color=blue><SPAN style="COLOR: blue">As</SPAN></FONT> <FONT color=blue><SPAN style="COLOR: blue">New</SPAN></FONT>MgResourceIdentifier _ </SPAN></FONT></P>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in; TEXT-INDENT: 0.5in"><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">(<FONT color=maroon><SPAN style="COLOR: maroon">"Library://VST/Layers/SouthOmahaTeamSchematic.LayerDefinition"</SPAN></FONT>)</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <FONT color=blue><SPAN style="COLOR: blue">Dim</SPAN></FONT> schematic <FONT color=blue><SPAN style="COLOR: blue">As</SPAN></FONT> MgLayer = CreateLayer(schematicId, <FONT color=blue><SPAN style="COLOR: blue">False</SPAN></FONT>)</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> map.GetLayers.Insert(index, schematic)</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <FONT color=green><SPAN style="COLOR: green">‘add sdf layer</SPAN></FONT></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face="Courier New" color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'"> Dim</SPAN></FONT><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> valveId <FONT color=blue><SPAN style="COLOR: blue">As</SPAN></FONT> <FONT color=blue><SPAN style="COLOR: blue">New</SPAN></FONT> MgResourceIdentifier _ </SPAN></FONT></P>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in; TEXT-INDENT: 0.5in"><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">(<FONT color=maroon><SPAN style="COLOR: maroon">"Library://VST/Layers/SouthOmahaValves.LayerDefinition"</SPAN></FONT>)</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <FONT color=blue><SPAN style="COLOR: blue">Dim</SPAN></FONT> valves <FONT color=blue><SPAN style="COLOR: blue">As</SPAN></FONT> MgLayer = CreateLayer(valveId, <FONT color=blue><SPAN style="COLOR: blue">True</SPAN></FONT>)</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> map.GetLayers.Insert(index, valves)</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> </SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> map.Save(resourceService)</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <FONT color=green><SPAN style="COLOR: green">'emit javascript to refresh map</SPAN></FONT></SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">End</SPAN></FONT><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <FONT color=blue><SPAN style="COLOR: blue">Sub</SPAN></FONT></SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face="Courier New" color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">Protected</SPAN></FONT><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <FONT color=blue><SPAN style="COLOR: blue">Sub</SPAN></FONT> Button2_Click(<FONT color=blue><SPAN style="COLOR: blue">ByVal</SPAN></FONT> sender <FONT color=blue><SPAN style="COLOR: blue">As</SPAN></FONT> <FONT color=blue><SPAN style="COLOR: blue">Object</SPAN></FONT>, <FONT color=blue><SPAN style="COLOR: blue">ByVal</SPAN></FONT> e <FONT color=blue><SPAN style="COLOR: blue">As</SPAN></FONT> System.EventArgs) <FONT color=blue><SPAN style="COLOR: blue">Handles</SPAN></FONT> Button2.Click</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <FONT color=blue><SPAN style="COLOR: blue">Dim</SPAN></FONT> lyr0 <FONT color=blue><SPAN style="COLOR: blue">As</SPAN></FONT> MgLayer = map.GetLayers.GetItem(0)</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <FONT color=blue><SPAN style="COLOR: blue">Dim</SPAN></FONT> lyr1 <FONT color=blue><SPAN style="COLOR: blue">As</SPAN></FONT> MgLayer = map.GetLayers.GetItem(1)</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> map.GetLayers.Remove(lyr0)</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> map.GetLayers.Remove(lyr1)</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> map.Save(resourceService)</SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <FONT color=green><SPAN style="COLOR: green">'emit javascript to refresh map</SPAN></FONT></SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">End</SPAN></FONT><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <FONT color=blue><SPAN style="COLOR: blue">Sub</SPAN></FONT></SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'"></SPAN></FONT> </P>
<DIV>
<DIV class=MsoNormal style="TEXT-ALIGN: center" align=center><FONT face="Times New Roman" size=3><SPAN style="FONT-SIZE: 12pt">
<HR tabIndex=-1 align=center width="100%" SIZE=2>
</SPAN></FONT></DIV>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><B><FONT face=Tahoma size=2><SPAN style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">From:</SPAN></FONT></B><FONT face=Tahoma size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma"> Trevor Wekel [mailto:trevor.wekel@autodesk.com] <BR><B><SPAN style="FONT-WEIGHT: bold">Sent:</SPAN></B> Friday, January 12, 2007 3:37 PM<BR><B><SPAN style="FONT-WEIGHT: bold">To:</SPAN></B> Buscher, Shane; Mapguide_users@lists.osgeo.org<BR><B><SPAN style="FONT-WEIGHT: bold">Subject:</SPAN></B> RE: [Mapguide_users] FW: Remove layers at runtime</SPAN></FONT></P></DIV>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face="Times New Roman" size=3><SPAN style="FONT-SIZE: 12pt"></SPAN></FONT> </P>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face=Arial color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">Hi Shane,</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face="Times New Roman" size=3><SPAN style="FONT-SIZE: 12pt"></SPAN></FONT> </P>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face=Arial color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">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.</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face="Times New Roman" size=3><SPAN style="FONT-SIZE: 12pt"></SPAN></FONT> </P>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face=Arial color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">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.</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face="Times New Roman" size=3><SPAN style="FONT-SIZE: 12pt"></SPAN></FONT> </P>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face=Arial color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">MgMap.Open()</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face=Arial color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">MgMap.GetLayers().Insert(layer)</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face=Arial color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">MgMap.Save()</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face="Times New Roman" size=3><SPAN style="FONT-SIZE: 12pt"></SPAN></FONT> </P>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face=Arial color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">If the Insert() works and Remove() doesn't</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face="Times New Roman" size=3><SPAN style="FONT-SIZE: 12pt"></SPAN></FONT> </P>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face=Arial color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">MgMap.Open()</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face=Arial color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">MgMap.GetLayers().Remove(layer)</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face=Arial color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">MgMap.Save()</SPAN></FONT></P>
<DIV>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face="Times New Roman" size=3><SPAN style="FONT-SIZE: 12pt"></SPAN></FONT> </P></DIV>
<DIV>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face=Arial color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">Then this is probably a bug. Also, does the behaviour depend on the number remaining layers?</SPAN></FONT></P></DIV>
<DIV>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face="Times New Roman" size=3><SPAN style="FONT-SIZE: 12pt"></SPAN></FONT> </P></DIV>
<DIV>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face=Arial color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">Thanks,</SPAN></FONT></P></DIV>
<DIV>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face=Arial color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">Trevor</SPAN></FONT></P></DIV>
<DIV>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face="Times New Roman" size=3><SPAN style="FONT-SIZE: 12pt"></SPAN></FONT> </P></DIV>
<DIV>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face="Times New Roman" size=3><SPAN style="FONT-SIZE: 12pt"></SPAN></FONT> </P></DIV>
<DIV class=MsoNormal style="MARGIN-LEFT: 0.5in; TEXT-ALIGN: center" align=center><FONT face="Times New Roman" size=3><SPAN style="FONT-SIZE: 12pt">
<HR tabIndex=-1 align=center width="100%" SIZE=2>
</SPAN></FONT></DIV>
<P class=MsoNormal style="MARGIN-BOTTOM: 12pt; MARGIN-LEFT: 0.5in; MARGIN-RIGHT: 0in"><B><FONT face=Tahoma size=2><SPAN style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">From:</SPAN></FONT></B><FONT face=Tahoma size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma"> Buscher, Shane [mailto:Shane.Buscher@nngco.com] <BR><B><SPAN style="FONT-WEIGHT: bold">Sent:</SPAN></B> Friday, January 12, 2007 7:16 AM<BR><B><SPAN style="FONT-WEIGHT: bold">To:</SPAN></B> Buscher, Shane; Mapguide_users@lists.osgeo.org<BR><B><SPAN style="FONT-WEIGHT: bold">Subject:</SPAN></B> RE: [Mapguide_users] FW: Remove layers at runtime</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">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 <I><SPAN style="FONT-STYLE: italic">not the map</SPAN></I>. I am saving the map and refreshing the map after removal. </SPAN></FONT></P>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"></SPAN></FONT> </P>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">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): </SPAN></FONT></P>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"></SPAN></FONT> </P>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><I><FONT face=StoneSans size=1><SPAN style="FONT-SIZE: 9pt; FONT-STYLE: italic; FONT-FAMILY: StoneSans">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.</SPAN></FONT></I></P>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"></SPAN></FONT> </P>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">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?</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"></SPAN></FONT> </P>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">Thanks for any help in advance. </SPAN></FONT></P>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"></SPAN></FONT> </P>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">Regards,</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"></SPAN></FONT> </P>
<P class=MsoNormal style="MARGIN-LEFT: 0.5in"><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">Shane</SPAN></FONT></P>
<DIV>
<DIV style="MARGIN-LEFT: 0.5in">
<DIV class=MsoNormal style="MARGIN-LEFT: 0.5in; TEXT-ALIGN: center" align=center><FONT face="Times New Roman" size=3><SPAN style="FONT-SIZE: 12pt">
<HR tabIndex=-1 align=center width="100%" SIZE=2>
</SPAN></FONT></DIV></DIV>
<P class=MsoNormal style="MARGIN-LEFT: 1in"><B><FONT face=Tahoma size=2><SPAN style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">From:</SPAN></FONT></B><FONT face=Tahoma size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma"> mapguide_users-bounces@lists.osgeo.org [mailto:mapguide_users-bounces@lists.osgeo.org] <B><SPAN style="FONT-WEIGHT: bold">On Behalf Of </SPAN></B>Buscher, Shane<BR><B><SPAN style="FONT-WEIGHT: bold">Sent:</SPAN></B> Tuesday, January 09, 2007 4:49 PM<BR><B><SPAN style="FONT-WEIGHT: bold">To:</SPAN></B> Mapguide_users@lists.osgeo.org<BR><B><SPAN style="FONT-WEIGHT: bold">Subject:</SPAN></B> [Mapguide_users] FW: Remove layers at runtime</SPAN></FONT></P></DIV>
<P class=MsoNormal style="MARGIN-LEFT: 1in"><FONT face="Times New Roman" size=3><SPAN style="FONT-SIZE: 12pt"></SPAN></FONT> </P>
<P style="MARGIN-LEFT: 1in"><FONT face=Arial size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">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</SPAN></FONT> <FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">layerCollection.Insert(index, layer) method. I don’t know why the same code wouldn’t work for clearing layers. </SPAN></FONT></P>
<P style="MARGIN-LEFT: 1in"><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">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. </SPAN></FONT> </P>
<P style="MARGIN-LEFT: 1in"><FONT face=Arial size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">‘</SPAN></FONT><FONT face="Courier New" color=green size=2><SPAN style="FONT-SIZE: 10pt; COLOR: green; FONT-FAMILY: 'Courier New'">Connect to site server, set resource service, and open map</SPAN></FONT></P>
<P style="MARGIN-LEFT: 1in"><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">ConnectToMapGuide() </SPAN></FONT></P>
<P style="MARGIN-LEFT: 1in"><FONT face="Courier New" color=green size=2><SPAN style="FONT-SIZE: 10pt; COLOR: green; FONT-FAMILY: 'Courier New'">'Clear all layers in the map</SPAN></FONT></P>
<P style="MARGIN-LEFT: 1in"><FONT face="Courier New" color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">Dim</SPAN></FONT><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> layerCollection</SPAN></FONT> <FONT face="Courier New" color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">As</SPAN></FONT><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> MgLayerCollection = map.GetLayers()</SPAN></FONT></P>
<P style="MARGIN-LEFT: 1in"><FONT face="Courier New" color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">If</SPAN></FONT><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> layerCollection.GetCount > 0</SPAN></FONT> <FONT face="Courier New" color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">Then</SPAN></FONT></P>
<P style="MARGIN-LEFT: 1in"><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> layerCollection.Clear()</SPAN></FONT></P>
<P style="MARGIN-LEFT: 1in"><FONT face="Courier New" color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">End</SPAN></FONT> <FONT face="Courier New" color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">If</SPAN></FONT></P>
<P style="MARGIN-LEFT: 1in"><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">map.Save(resourceService)</SPAN></FONT></P>
<P style="MARGIN-LEFT: 1in"><FONT face="Courier New" color=green size=2><SPAN style="FONT-SIZE: 10pt; COLOR: green; FONT-FAMILY: 'Courier New'">'emit javascript to refresh map</SPAN></FONT></P>
<P style="MARGIN-LEFT: 1in"><FONT face="Courier New" color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">Dim</SPAN></FONT><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> scriptKey</SPAN></FONT> <FONT face="Courier New" color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">As</SPAN></FONT> <FONT face="Courier New" color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">String</SPAN></FONT><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> =</SPAN></FONT> <FONT face="Courier New" color=maroon size=2><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"ForceRefresh"</SPAN></FONT></P>
<P style="MARGIN-LEFT: 1in"><FONT face="Courier New" color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">If</SPAN></FONT> <FONT face="Courier New" color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">Not</SPAN></FONT><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> Page.ClientScript.IsStartupScriptRegistered(<FONT color=blue><SPAN style="COLOR: blue">Me</SPAN></FONT>.GetType, scriptKey)</SPAN></FONT> <FONT face="Courier New" color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">Then</SPAN></FONT></P>
<P style="MARGIN-LEFT: 1in"><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> </SPAN></FONT> <FONT face="Courier New" color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">Dim</SPAN></FONT><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> javaScript</SPAN></FONT> <FONT face="Courier New" color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">As</SPAN></FONT> <FONT face="Courier New" color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">String</SPAN></FONT><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> =</SPAN></FONT> <FONT face="Courier New" color=maroon size=2><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"refreshMap("</SPAN></FONT><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> & MapAction.RefreshMap &</SPAN></FONT> <FONT face="Courier New" color=maroon size=2><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">");"</SPAN></FONT></P>
<P style="MARGIN-LEFT: 1in"><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> Page.ClientScript.RegisterStartupScript(<FONT color=blue><SPAN style="COLOR: blue">Me</SPAN></FONT>.GetType, scriptKey, javaScript,</SPAN></FONT> <FONT face="Courier New" color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">True</SPAN></FONT><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">)</SPAN></FONT></P>
<P style="MARGIN-LEFT: 1in"><FONT face="Courier New" color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">End</SPAN></FONT> <FONT face="Courier New" color=blue size=2><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">If</SPAN></FONT></P>
<P style="MARGIN-LEFT: 1in"><A name=""><FONT face=Arial size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Regards,</SPAN></FONT></A></P>
<P style="MARGIN-LEFT: 1in"><FONT face=Arial size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Shane</SPAN></FONT></P>
<P style="MARGIN-LEFT: 1in"><FONT face=Arial color=gray size=2><SPAN style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: Arial">Operations IT</SPAN></FONT></P>
<P style="MARGIN-LEFT: 1in"><FONT face=Arial color=gray size=2><SPAN style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: Arial">Northern Natural Gas</SPAN></FONT></P>
<P style="MARGIN-LEFT: 1in"><FONT face=Arial color=gray size=2><SPAN style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: Arial">402.398.7841</SPAN></FONT></P>
<P style="MARGIN-LEFT: 1in"><I><FONT face=Arial color=gray size=2><SPAN style="FONT-SIZE: 10pt; COLOR: gray; FONT-STYLE: italic; FONT-FAMILY: Arial">We think in generalities, but live in detail. </SPAN></FONT></I></P>
<P style="MARGIN-LEFT: 1in"><I><FONT face=Arial color=gray size=2><SPAN style="FONT-SIZE: 10pt; COLOR: gray; FONT-STYLE: italic; FONT-FAMILY: Arial">-Alred North Whitehead</SPAN></FONT></I></P></DIV></DIV></BODY></HTML>