<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns="http://www.w3.org/TR/REC-html40" xmlns:v =
"urn:schemas-microsoft-com:vml" xmlns:o =
"urn:schemas-microsoft-com:office:office" xmlns:w =
"urn:schemas-microsoft-com:office:word" xmlns:m =
"http://schemas.microsoft.com/office/2004/12/omml"><HEAD>
<META content="text/html; charset=us-ascii" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.6001.19328">
<STYLE>@font-face {
font-family: Calibri;
}
@font-face {
font-family: Consolas;
}
@page WordSection1 {size: 8.5in 11.0in; margin: 1.0in 1.0in 1.0in 1.0in; }
P.MsoNormal {
MARGIN: 0in 0in 0pt; FONT-FAMILY: "Calibri","sans-serif"; FONT-SIZE: 11pt
}
LI.MsoNormal {
MARGIN: 0in 0in 0pt; FONT-FAMILY: "Calibri","sans-serif"; FONT-SIZE: 11pt
}
DIV.MsoNormal {
MARGIN: 0in 0in 0pt; FONT-FAMILY: "Calibri","sans-serif"; FONT-SIZE: 11pt
}
A:link {
COLOR: blue; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.MsoHyperlink {
COLOR: blue; TEXT-DECORATION: underline; mso-style-priority: 99
}
A:visited {
COLOR: purple; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.MsoHyperlinkFollowed {
COLOR: purple; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.EmailStyle17 {
FONT-FAMILY: "Courier New"; COLOR: windowtext; mso-style-type: personal
}
SPAN.EmailStyle18 {
FONT-FAMILY: "Courier New"; COLOR: #1f497d; mso-style-type: personal-reply
}
.MsoChpDefault {
FONT-SIZE: 10pt; mso-style-type: export-only
}
DIV.WordSection1 {
page: WordSection1
}
</STYLE>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></HEAD>
<BODY lang=EN-US link=blue vLink=purple>
<DIV dir=ltr lang=de class=OutlookMessageHeader align=left><SPAN
class=078185919-31102012><FONT color=#0000ff size=2 face=Arial>you doesn't take
the name, but the object</FONT></SPAN></DIV>
<DIV dir=ltr lang=de class=OutlookMessageHeader align=left><SPAN
class=078185919-31102012><FONT color=#0000ff size=2
face=Arial></FONT></SPAN> </DIV>
<DIV dir=ltr lang=de class=OutlookMessageHeader align=left><SPAN
class=078185919-31102012><FONT color=#0000ff size=2
face=Arial>map.removeLayer(<FONT color=#000000 size=3
face=Consolas>lineLayer</FONT>); </FONT></SPAN></DIV><SPAN
class=078185919-31102012>
<DIV dir=ltr lang=de class=OutlookMessageHeader align=left><SPAN
class=078185919-31102012><FONT color=#0000ff size=2 face=Arial>map.destroy(<FONT
color=#000000 size=3 face=Consolas>lineLayer</FONT>); </FONT></SPAN></DIV>
<DIV><FONT color=#0000ff size=2 face=Arial></FONT> </DIV>
<DIV><FONT color=#0000ff size=2 face=Arial><SPAN
class=078185919-31102012>lineLayer have to be a global variable, what's true in
your case.</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff size=2 face=Arial><SPAN
class=078185919-31102012><BR>Arnd</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff size=2 face=Arial></FONT> </DIV>
<DIV><FONT color=#0000ff size=2 face=Arial></FONT> </DIV>
<DIV dir=ltr lang=de class=OutlookMessageHeader align=left> </SPAN></DIV>
<DIV dir=ltr lang=de class=OutlookMessageHeader align=left>
<HR tabIndex=-1>
</DIV>
<DIV dir=ltr lang=de class=OutlookMessageHeader align=left><FONT size=2
face=Tahoma><B>Von:</B> openlayers-users-bounces@lists.osgeo.org
[mailto:openlayers-users-bounces@lists.osgeo.org] <B>Im Auftrag von
</B>miguel<BR><B>Gesendet:</B> Mittwoch, 31. Oktober 2012 12:19<BR><B>An:</B>
openlayers-users@lists.osgeo.org<BR><B>Betreff:</B> [OpenLayers-Users] How to
remove vector layer properly or justpeieces of a vector
layer?<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV class=WordSection1>
<P class=MsoNormal><o:p> </o:p></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">Hi guys
I’ve been racking my head on how to remove just the vector layer from my map.
Below is my code I have a function call killLayer(), but it does not work
at all I have try different variations. So I just need to understand if I add a
layer in my init function, how can I get a reference to that layer to remove
later on from another function. In this case my vector layer. I would like
to remove it and just keep the base layer. Any help would be immensely
appreciated.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">Miguel<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt"><o:p> </o:p></SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">My
Code:<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt"><o:p> </o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
var map;<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
var lineLayer = new
OpenLayers.Layer.Vector("LineLayer");<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
var mapBounds = new OpenLayers.Bounds( 0.0, -906.0, 800.0,
0.0);<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
var mapMinZoom = 0;<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
var mapMaxZoom = 7;<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt"><o:p> </o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
// avoid pink
tiles<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
OpenLayers.IMAGE_RELOAD_ATTEMPTS =
3;<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
OpenLayers.Util.onImageLoadErrorColor
= "transparent";<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt"><o:p> </o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
function
init(){<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
var
navigation_control = new
OpenLayers.Control.Navigation({});<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
var
controls_array = [<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
navigation_control,<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
new OpenLayers.Control.PanZoomBar({}),<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
new OpenLayers.Control.LayerSwitcher({}),<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
new OpenLayers.Control.Permalink(),<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
new OpenLayers.Control.MousePosition({})<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
];<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt"> <o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt"> var
options = {<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
controls: [],<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
maxExtent:
new OpenLayers.Bounds( 0.0, -906.0, 800.0, 0.0 ),<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
maxResolution: 4.000000,<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
numZoomLevels: 8<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
};<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt"> //{controls:
controls_array}<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
map = new OpenLayers.Map('map',
options ); ;<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
//tile map service TMS
stands for tile map service.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
var layer = new OpenLayers.Layer.TMS(
"TMS Layer","",<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
{ url:
'', serviceVersion: '.', layername: '.', alpha: true,<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
type: 'png', getURL: overlay_getTileURL <o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
});<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
map.addLayer(layer);<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
map.zoomToExtent( mapBounds ); <o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
//create the new layer vector layer which includes all the
drawings.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
/*here im addding to lines separate line segments.*/<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
map.addLayer(lineLayer);<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
var points = new Array(<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
new OpenLayers.Geometry.Point(56.0000, -244) , //x and y cordinate of
first point<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
new OpenLayers.Geometry.Point(368,-248) //x and y
cordinate of the second point<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
);<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
var second_segment = new Array(<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
new OpenLayers.Geometry.Point(480,-230), //x and y cordinate of first
point<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
new OpenLayers.Geometry.Point(668,-250) //x and y cordinate of first
point<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
);<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
var line = new
OpenLayers.Geometry.LineString(points);<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
var line2 = new
OpenLayers.Geometry.LineString(second_segment);<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
var style={<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
strokeColor: '#0000ff', <o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
strokeOpacity: 0.5, <o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
strokeWidth: 6};<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
var lineFeature = new OpenLayers.Feature.Vector(line, null,
style);<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
var lineFeatureN = new OpenLayers.Feature.Vector(line2, null,
style);<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
lineLayer.addFeatures([lineFeature]);<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
lineLayer.addFeatures([lineFeatureN]);<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
map.addControl(new OpenLayers.Control.PanZoomBar());<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
map.addControl(new OpenLayers.Control.MousePosition());<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
map.addControl(new OpenLayers.Control.MouseDefaults());<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
map.addControl(new OpenLayers.Control.KeyboardDefaults());<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt"><o:p> </o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
}<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt"><o:p> </o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
function killLayer()
{<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
//map.removeLayer("LineLayer");<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
//lineLayer.destroy();<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
//map.destroy("LineLayer");<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
lineLayer.removeFeatures(lineFeature);<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Consolas; FONT-SIZE: 12pt">
}<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Courier New'"><o:p> </o:p></SPAN></P></DIV></BODY></HTML>