[OpenLayers-Trac] [OpenLayers] #3571: moveTo generates "Uncaught
TypeError: Cannot call method 'getLonLatFromLayerPx' of null"
OpenLayers
trac-20090302 at openlayers.org
Mon Nov 7 18:38:19 EST 2011
#3571: moveTo generates "Uncaught TypeError: Cannot call method
'getLonLatFromLayerPx' of null"
-----------------------------------------------------+----------------------
Reporter: outbreakmonkey | Owner: euzuro
Type: bug | Status: new
Priority: minor | Milestone: 2.12 Release
Component: Marker | Version: 2.11
Keywords: moveto, typeerror, getLonLatFromLayerPx | State:
-----------------------------------------------------+----------------------
Using Chrome and Firefox, I get the following error whenever I try to move
a marker.
{{{
Uncaught TypeError: Cannot call method 'getLonLatFromLayerPx' of null
(Openlayers.js:2149)
}}}
Everytime I call moveTo on a marker, I get the Uncaught TypeError.
It appears that this.map is null.
The error appears to be in "OpenLayers.Marker.moveTo" in Openlayers.js.
The error stops javascript execution, so as a temporary fix for my own
site I've added
(this.map)?this.map.getLonLatFromLayerPx(px):"";
From my checks, it doesn't appear that this.map is ever set. Am I calling
this wrong?
FYI, map is set before the moveTo, because I'm able to set:
markerpos=map.getLayerPxFromLonLat(newpos);
I'm calling the map and moveTo as such:
{{{
<script language="javascript">
var map;
var fromProjection = new OpenLayers.Projection("EPSG:4326"); //
transform from WGS 1984
var toProjection = new OpenLayers.Projection("EPSG:900913"); // to
Spherical Mercator Projection
var markers=new OpenLayers.Layer.Markers("Markers");
var size = new OpenLayers.Size(20,20);
var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
var icon = new OpenLayers.Icon('OpenLayers-2.11/img/locbox.png',
size, offset);
var currentposmarker=new OpenLayers.Marker(new
OpenLayers.LonLat(<?PHP echo
$curloc;?>).transform(fromProjection,toProjection),icon);
function init() {
var extent = new
OpenLayers.Bounds(147.00,-39.00,155.00,-22.00).transform(fromProjection,toProjection);
var options = {
restrictedExtent : extent
};
map = new OpenLayers.Map("basicMap",options);
var mapnik = new OpenLayers.Layer.OSM();
map.addLayer(mapnik);
map.addLayer(markers);
var lonLat = new OpenLayers.LonLat(<?PHP echo $curloc;?>)
//start lonlat
.transform(
fromProjection, // transform from WGS 1984
toProjection // to Spherical Mercator Projection
);
markers.addMarker(currentposmarker);
map.setCenter(lonLat,16); // Center of the map
refreshloop();
}
</script>
}}}
And Updating the location of the marker like so:
{{{
function processlocation(data) {
var newpos=new
OpenLayers.LonLat(data.longitude,data.latitude).transform(
fromProjection,
toProjection
);
markerpos=map.getLayerPxFromLonLat(newpos);
map.panTo(newpos);
}}}
--
Ticket URL: <http://trac.openlayers.org/ticket/3571>
OpenLayers <http://openlayers.org/>
A free AJAX map viewer
More information about the Trac
mailing list