diff --git a/lib/OpenLayers/Marker.js b/lib/OpenLayers/Marker.js index 318dbc0280..1375c54696 100644 --- a/lib/OpenLayers/Marker.js +++ b/lib/OpenLayers/Marker.js @@ -64,17 +64,13 @@ OpenLayers.Marker.prototype = { * @type Boolean */ onScreen:function() { - - var screenBounds = OpenLayers.Bounds.fromSize(this.map.getSize()); - - var iconTop = parseInt(this.icon.div.style.top); - var iconLeft = parseInt(this.icon.div.style.left); - var iconBottom = iconTop + parseInt(this.icon.div.style.height); - var iconRight = iconLeft + parseInt(this.icon.div.style.width); - var iconBounds = - new OpenLayers.Bounds(iconLeft, iconBottom, iconRight, iconTop); - - return screenBounds.containsBounds(iconBounds, true); + + var onScreen = false; + if (this.map) { + var screenBounds = this.map.getExtent(); + onScreen = screenBounds.contains(this.lonlat.lon, this.lonlat.lat); + } + return onScreen; }, /**