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