<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Dear list<br>
<br>
I'm using a self-made function for clearing all layers in my map and
adding a stored set of predefined layers.<br>
In this routine i call map.removeLayer() for all non-base layers,
before I add the new layer set.<br>
<br>
However, after having removed the layers I get an exception from
GeoExt.VectorLegend:<br>
<ol class="outline-disclosure" tabindex="0" style="box-sizing:
border-box; font-size: 12px; list-style-type: none;
-webkit-padding-start: 12px; margin-top: 0px; margin-right: 0px;
margin-bottom: 0px; margin-left: 0px; outline-style: none;
outline-width: initial; outline-color: initial; padding-left: 0px;
line-height: 12px; color: rgb(0, 0, 0); font-family: Consolas,
'Lucida Console', monospace; font-style: normal; font-variant:
normal; font-weight: normal; letter-spacing: normal; orphans: 2;
text-align: -webkit-auto; text-indent: 0px; text-transform: none;
white-space: normal; widows: 2; word-spacing: 0px;
-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;
background-color: rgb(255, 255, 255); ">
<li title="" class="parent expanded" style="box-sizing:
border-box; padding-top: 0px; padding-right: 0px;
padding-bottom: 0px; padding-left: 14px; margin-top: 1px;
margin-bottom: 1px; margin-left: -12px; word-wrap: break-word; "><span
class="console-message-text source-code" style="box-sizing:
border-box; white-space: pre-wrap; font-family: Consolas,
'Lucida Console', monospace; font-size: 12px !important;
color: red !important; "><span style="box-sizing: border-box;
">Uncaught TypeError: Cannot read property 'map' of null</span></span></li>
<ol class="children expanded" style="box-sizing: border-box;
position: relative; padding-top: 0px !important; padding-right:
0px !important; padding-bottom: 0px !important; padding-left:
12px !important; margin-top: 0px; margin-right: 0px;
margin-bottom: 0px; margin-left: 0px; color: black; cursor:
default; min-width: 100%; list-style-type: none;
-webkit-padding-start: 12px; font-size: inherit; line-height:
12px; display: block; ">
<li title="" style="box-sizing: border-box; padding-top: 0px;
padding-right: 0px; padding-bottom: 0px; padding-left: 14px;
margin-top: 1px; margin-bottom: 1px; margin-left: -2px;
word-wrap: break-word; ">
<div style="box-sizing: border-box; "><span
class="console-message-text source-code"
style="box-sizing: border-box; white-space: pre-wrap;
font-family: Consolas, 'Lucida Console', monospace;
font-size: 12px !important; color: red !important; ">GeoExt.VectorLegend.Ext.extend.onMapZoom</span><a
href="http://localhost/barentswatch/GeoExt-1.1/lib/GeoExt/widgets/VectorLegend.js"
class="console-message-url webkit-html-resource-link"
title="http://localhost/barentswatch/GeoExt-1.1/lib/GeoExt/widgets/VectorLegend.js"
style="box-sizing: border-box; float: right; margin-left:
4px; color: rgb(84, 84, 84); cursor: pointer; max-width:
100%; ">VectorLegend.js:261</a></div>
</li>
<li title="" style="box-sizing: border-box; padding-top: 0px;
padding-right: 0px; padding-bottom: 0px; padding-left: 14px;
margin-top: 1px; margin-bottom: 1px; margin-left: -2px;
word-wrap: break-word; ">
<div style="box-sizing: border-box; "><span
class="console-message-text source-code"
style="box-sizing: border-box; white-space: pre-wrap;
font-family: Consolas, 'Lucida Console', monospace;
font-size: 12px !important; color: red !important; ">OpenLayers.Events.OpenLayers.Class.triggerEvent</span><a
href="http://localhost/barentswatch/OpenLayers-2.11/lib/OpenLayers/Events.js"
class="console-message-url webkit-html-resource-link"
title="http://localhost/barentswatch/OpenLayers-2.11/lib/OpenLayers/Events.js"
style="box-sizing: border-box; float: right; margin-left:
4px; color: rgb(84, 84, 84); cursor: pointer; max-width:
100%; ">Events.js:798</a></div>
</li>
<li title="" style="box-sizing: border-box; padding-top: 0px;
padding-right: 0px; padding-bottom: 0px; padding-left: 14px;
margin-top: 1px; margin-bottom: 1px; margin-left: -2px;
word-wrap: break-word; ">
<div style="box-sizing: border-box; "><span
class="console-message-text source-code"
style="box-sizing: border-box; white-space: pre-wrap;
font-family: Consolas, 'Lucida Console', monospace;
font-size: 12px !important; color: red !important; ">OpenLayers.Map.OpenLayers.Class.moveTo</span><a
href="http://localhost/barentswatch/OpenLayers-2.11/lib/OpenLayers/Map.js"
class="console-message-url webkit-html-resource-link"
title="http://localhost/barentswatch/OpenLayers-2.11/lib/OpenLayers/Map.js"
style="box-sizing: border-box; float: right; margin-left:
4px; color: rgb(84, 84, 84); cursor: pointer; max-width:
100%; ">Map.js:1890</a></div>
</li>
<li title="" style="box-sizing: border-box; padding-top: 0px;
padding-right: 0px; padding-bottom: 0px; padding-left: 14px;
margin-top: 1px; margin-bottom: 1px; margin-left: -2px;
word-wrap: break-word; ">
<div style="box-sizing: border-box; "><span
class="console-message-text source-code"
style="box-sizing: border-box; white-space: pre-wrap;
font-family: Consolas, 'Lucida Console', monospace;
font-size: 12px !important; color: red !important; ">OpenLayers.Map.OpenLayers.Class.setCenter</span><a
href="http://localhost/barentswatch/OpenLayers-2.11/lib/OpenLayers/Map.js"
class="console-message-url webkit-html-resource-link"
title="http://localhost/barentswatch/OpenLayers-2.11/lib/OpenLayers/Map.js"
style="box-sizing: border-box; float: right; margin-left:
4px; color: rgb(84, 84, 84); cursor: pointer; max-width:
100%; ">Map.js:1662</a></div>
</li>
<li title="" style="box-sizing: border-box; padding-top: 0px;
padding-right: 0px; padding-bottom: 0px; padding-left: 14px;
margin-top: 1px; margin-bottom: 1px; margin-left: -2px;
word-wrap: break-word; ">
<div style="box-sizing: border-box; "><span
class="console-message-text source-code"
style="box-sizing: border-box; white-space: pre-wrap;
font-family: Consolas, 'Lucida Console', monospace;
font-size: 12px !important; color: red !important; ">OpenLayers.Control.Navigation.OpenLayers.Class.wheelChange</span><a
href="http://localhost/barentswatch/OpenLayers-2.11/lib/OpenLayers/Control/Navigation.js"
class="console-message-url webkit-html-resource-link"
title="http://localhost/barentswatch/OpenLayers-2.11/lib/OpenLayers/Control/Navigation.js"
style="box-sizing: border-box; float: right; margin-left:
4px; color: rgb(84, 84, 84); cursor: pointer; max-width:
100%; ">Navigation.js:279</a></div>
</li>
<li title="" style="box-sizing: border-box; padding-top: 0px;
padding-right: 0px; padding-bottom: 0px; padding-left: 14px;
margin-top: 1px; margin-bottom: 1px; margin-left: -2px;
word-wrap: break-word; ">
<div style="box-sizing: border-box; "><span
class="console-message-text source-code"
style="box-sizing: border-box; white-space: pre-wrap;
font-family: Consolas, 'Lucida Console', monospace;
font-size: 12px !important; color: red !important; ">OpenLayers.Control.Navigation.OpenLayers.Class.wheelDown</span><a
href="http://localhost/barentswatch/OpenLayers-2.11/lib/OpenLayers/Control/Navigation.js"
class="console-message-url webkit-html-resource-link"
title="http://localhost/barentswatch/OpenLayers-2.11/lib/OpenLayers/Control/Navigation.js"
style="box-sizing: border-box; float: right; margin-left:
4px; color: rgb(84, 84, 84); cursor: pointer; max-width:
100%; ">Navigation.js:303</a></div>
</li>
<li title="" style="box-sizing: border-box; padding-top: 0px;
padding-right: 0px; padding-bottom: 0px; padding-left: 14px;
margin-top: 1px; margin-bottom: 1px; margin-left: -2px;
word-wrap: break-word; ">
<div style="box-sizing: border-box; "><span
class="console-message-text source-code"
style="box-sizing: border-box; white-space: pre-wrap;
font-family: Consolas, 'Lucida Console', monospace;
font-size: 12px !important; color: red !important; ">OpenLayers.Handler.OpenLayers.Class.callback</span><a
href="http://localhost/barentswatch/OpenLayers-2.11/lib/OpenLayers/Handler.js"
class="console-message-url webkit-html-resource-link"
title="http://localhost/barentswatch/OpenLayers-2.11/lib/OpenLayers/Handler.js"
style="box-sizing: border-box; float: right; margin-left:
4px; color: rgb(84, 84, 84); cursor: pointer; max-width:
100%; ">Handler.js:205</a></div>
</li>
<li title="" style="box-sizing: border-box; padding-top: 0px;
padding-right: 0px; padding-bottom: 0px; padding-left: 14px;
margin-top: 1px; margin-bottom: 1px; margin-left: -2px;
word-wrap: break-word; ">
<div style="box-sizing: border-box; "><span
class="console-message-text source-code"
style="box-sizing: border-box; white-space: pre-wrap;
font-family: Consolas, 'Lucida Console', monospace;
font-size: 12px !important; color: red !important; ">OpenLayers.Handler.MouseWheel.OpenLayers.Class.wheelZoom</span><a
href="http://localhost/barentswatch/OpenLayers-2.11/lib/OpenLayers/Handler/MouseWheel.js"
class="console-message-url webkit-html-resource-link"
title="http://localhost/barentswatch/OpenLayers-2.11/lib/OpenLayers/Handler/MouseWheel.js"
style="box-sizing: border-box; float: right; margin-left:
4px; color: rgb(84, 84, 84); cursor: pointer; max-width:
100%; ">MouseWheel.js:229</a></div>
</li>
<li title="" class="" style="box-sizing: border-box;
padding-top: 0px; padding-right: 0px; padding-bottom: 0px;
padding-left: 14px; margin-top: 1px; margin-bottom: 1px;
margin-left: -2px; word-wrap: break-word; ">
<div style="box-sizing: border-box; "><span
class="console-message-text source-code"
style="box-sizing: border-box; white-space: pre-wrap;
font-family: Consolas, 'Lucida Console', monospace;
font-size: 12px !important; color: red !important; ">OpenLayers.Handler.MouseWheel.OpenLayers.Class.onWheelEvent</span><a
href="http://localhost/barentswatch/OpenLayers-2.11/lib/OpenLayers/Handler/MouseWheel.js"
class="console-message-url webkit-html-resource-link"
title="http://localhost/barentswatch/OpenLayers-2.11/lib/OpenLayers/Handler/MouseWheel.js"
style="box-sizing: border-box; float: right; margin-left:
4px; color: rgb(84, 84, 84); cursor: pointer; max-width:
100%; ">MouseWheel.js:191</a></div>
</li>
<li title="" class="selected" style="padding: 0px 0px 0px 14px;
margin-top: 1px; margin-bottom: 1px; margin-left: -2px;
word-wrap: break-word;">
<div style=""><span class="console-message-text source-code"
style="white-space: pre-wrap; font-family:
Consolas,'Lucida Console',monospace; font-size: 12px !
important; color: red ! important;">(anonymous function)</span></div>
</li>
</ol>
</ol>
<p>To the inner level this maps down to the function<br>
onMapZoom: function() {<br>
this.setCurrentScaleDenominator(<br>
this.layer.map.getScale()<br>
);<br>
},<br>
</p>
<p>And by inspection this.layer is undefined.<br>
</p>
<p>How can this be?<br>
Removing the layer with any combination of (one or both)<br>
map.removeLayer(layer) and<br>
layer.destroy()<br>
gives the same result.<br>
</p>
<p>best regards,<br>
Frank<br>
</p>
<p><br>
</p>
<br>
</body>
</html>