Boxes.js 2.1 KB

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