EditingToolbar.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* Copyright (c) 2006-2011 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. * @requires OpenLayers/Control/Panel.js
  7. * @requires OpenLayers/Control/Navigation.js
  8. * @requires OpenLayers/Control/DrawFeature.js
  9. * @requires OpenLayers/Handler/Point.js
  10. * @requires OpenLayers/Handler/Path.js
  11. * @requires OpenLayers/Handler/Polygon.js
  12. */
  13. /**
  14. * Class: OpenLayers.Control.EditingToolbar
  15. * The EditingToolbar is a panel of 4 controls to draw polygons, lines,
  16. * points, or to navigate the map by panning. By default it appears in the
  17. * upper right corner of the map.
  18. *
  19. * Inherits from:
  20. * - <OpenLayers.Control.Panel>
  21. */
  22. OpenLayers.Control.EditingToolbar = OpenLayers.Class(
  23. OpenLayers.Control.Panel, {
  24. /**
  25. * Constructor: OpenLayers.Control.EditingToolbar
  26. * Create an editing toolbar for a given layer.
  27. *
  28. * Parameters:
  29. * layer - {<OpenLayers.Layer.Vector>}
  30. * options - {Object}
  31. */
  32. initialize: function(layer, options) {
  33. OpenLayers.Control.Panel.prototype.initialize.apply(this, [options]);
  34. this.addControls(
  35. [ new OpenLayers.Control.Navigation() ]
  36. );
  37. var controls = [
  38. new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Point, {'displayClass': 'olControlDrawFeaturePoint'}),
  39. new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Path, {'displayClass': 'olControlDrawFeaturePath'}),
  40. new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Polygon, {'displayClass': 'olControlDrawFeaturePolygon'})
  41. ];
  42. this.addControls(controls);
  43. },
  44. /**
  45. * Method: draw
  46. * calls the default draw, and then activates mouse defaults.
  47. *
  48. * Returns:
  49. * {DOMElement}
  50. */
  51. draw: function() {
  52. var div = OpenLayers.Control.Panel.prototype.draw.apply(this, arguments);
  53. if (this.defaultControl === null) {
  54. this.defaultControl = this.controls[0];
  55. }
  56. return div;
  57. },
  58. CLASS_NAME: "OpenLayers.Control.EditingToolbar"
  59. });