Files
openlayers/lib/OpenLayers/Layer/Markers.js
euzuro 06cbeb2f11 fix for #60
conversions to/from lonlat/px need to take into account
the offset of the layersContainerDiv. 


I have introduced the following functions for converting
between layer and screen pixel values:

getLayerPxFromScreenPx() and getScreenPxFromLayerPx()

they are pretty self-explanitory.


I then renamed:

getPixelFromLonLat() and getLonLatFromPixel()

to:

getScreenPxFromLonLat() and getLonLatFroScreenmPx()

and added:

getLayerPxFromLonLat() and getLonLatFromLayerPx()


updates were made throughout the code, demos, and tests
so everything should still run smoothly.

-e-

git-svn-id: http://svn.openlayers.org/trunk/openlayers@329 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
2006-05-24 18:45:50 +00:00

72 lines
1.7 KiB
JavaScript

// @require: OpenLayers/Layer.js
/**
* @class
*/
OpenLayers.Layer.Markers = Class.create();
OpenLayers.Layer.Markers.prototype =
Object.extend( new OpenLayers.Layer(), {
/** internal marker list
* @type Array(OpenLayers.Marker) */
markers: null,
/**
* @constructor
*
* @param {String} name
*/
initialize: function(name) {
OpenLayers.Layer.prototype.initialize.apply(this, arguments);
this.markers = new Array();
},
/**
* @param {OpenLayers.Bounds} bounds
* @param {Boolean} zoomChanged
*/
moveTo: function(bounds, zoomChanged) {
if (zoomChanged) {
this.redraw();
}
},
/**
* @param {OpenLayers.Marker} marker
*/
addMarker: function(marker) {
this.markers.append(marker);
if (this.map && this.map.getExtent()) {
this.drawMarker(marker);
}
},
/** clear all the marker div's from the layer and then redraw all of them.
* Use the map to recalculate new placement of markers.
*/
redraw: function() {
for(i=0; i < this.markers.length; i++) {
this.drawMarker(this.markers[i]);
}
},
/** Calculate the screen pixel location for the marker, create it, and
* add it to the layer's div
*
* @private
*
* @param {OpenLayers.Marker} marker
*/
drawMarker: function(marker) {
var px = this.map.getLayerPxFromLonLat(marker.lonlat);
var markerImg = marker.draw(px);
if (!marker.drawn) {
this.div.appendChild(markerImg);
marker.drawn = true;
}
},
/** @final @type String */
CLASS_NAME: "OpenLayers.Layer.Markers"
});