1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for
* full list of contributors). Published under the 2-clause BSD license.
* See license.txt in the OpenLayers distribution or repository for the
* full text of the license. */
/**
* @requires OpenLayers/Layer.js
* @requires OpenLayers/Layer/Markers.js
*/
/**
* Class: OpenLayers.Layer.Boxes
* Draw divs as 'boxes' on the layer.
*
* Inherits from:
* - <OpenLayers.Layer.Markers>
*/
OpenLayers.Layer.Boxes = OpenLayers.Class(OpenLayers.Layer.Markers, {
/**
* Constructor: OpenLayers.Layer.Boxes
*
* Parameters:
* name - {String}
* options - {Object} Hashtable of extra options to tag onto the layer
*/
/**
* Method: drawMarker
* Calculate the pixel location for the marker, create it, and
* add it to the layer's div
*
* Parameters:
* marker - {<OpenLayers.Marker.Box>}
*/
drawMarker: function(marker) {
var topleft = this.map.getLayerPxFromLonLat({
lon: marker.bounds.left,
lat: marker.bounds.top
});
var botright = this.map.getLayerPxFromLonLat({
lon: marker.bounds.right,
lat: marker.bounds.bottom
});
if (botright == null || topleft == null) {
marker.display(false);
} else {
var markerDiv = marker.draw(topleft, {
w: Math.max(1, botright.x - topleft.x),
h: Math.max(1, botright.y - topleft.y)
});
if (!marker.drawn) {
this.div.appendChild(markerDiv);
marker.drawn = true;
}
}
},
/**
* APIMethod: removeMarker
*
* Parameters:
* marker - {<OpenLayers.Marker.Box>}
*/
removeMarker: function(marker) {
OpenLayers.Util.removeItem(this.markers, marker);
if ((marker.div != null) &&
(marker.div.parentNode == this.div) ) {
this.div.removeChild(marker.div);
}
},
CLASS_NAME: "OpenLayers.Layer.Boxes"
});
|