EditingToolbar.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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/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. * APIProperty: citeCompliant
  26. * {Boolean} If set to true, coordinates of features drawn in a map extent
  27. * crossing the date line won't exceed the world bounds. Default is false.
  28. */
  29. citeCompliant: false,
  30. /**
  31. * Constructor: OpenLayers.Control.EditingToolbar
  32. * Create an editing toolbar for a given layer.
  33. *
  34. * Parameters:
  35. * layer - {<OpenLayers.Layer.Vector>}
  36. * options - {Object}
  37. */
  38. initialize: function(layer, options) {
  39. OpenLayers.Control.Panel.prototype.initialize.apply(this, [options]);
  40. this.addControls(
  41. [ new OpenLayers.Control.Navigation() ]
  42. );
  43. var controls = [
  44. new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Point, {
  45. displayClass: 'olControlDrawFeaturePoint',
  46. handlerOptions: {citeCompliant: this.citeCompliant}
  47. }),
  48. new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Path, {
  49. displayClass: 'olControlDrawFeaturePath',
  50. handlerOptions: {citeCompliant: this.citeCompliant}
  51. }),
  52. new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Polygon, {
  53. displayClass: 'olControlDrawFeaturePolygon',
  54. handlerOptions: {citeCompliant: this.citeCompliant}
  55. })
  56. ];
  57. this.addControls(controls);
  58. },
  59. /**
  60. * Method: draw
  61. * calls the default draw, and then activates mouse defaults.
  62. *
  63. * Returns:
  64. * {DOMElement}
  65. */
  66. draw: function() {
  67. var div = OpenLayers.Control.Panel.prototype.draw.apply(this, arguments);
  68. if (this.defaultControl === null) {
  69. this.defaultControl = this.controls[0];
  70. }
  71. return div;
  72. },
  73. CLASS_NAME: "OpenLayers.Control.EditingToolbar"
  74. });