import {
  ModifyFeature_default
} from "./chunk-YNX27GDF.js";
import {
  ol_coordinate_dist2d,
  ol_coordinate_findSegment,
  ol_coordinate_offsetCoords
} from "./chunk-3UNEODO2.js";
import {
  Draw_default
} from "./chunk-MEQVYVYE.js";
import {
  Select_default
} from "./chunk-6DXBPPKF.js";
import {
  Toggle_default
} from "./chunk-NNBJMTCH.js";
import {
  Button_default
} from "./chunk-VCBXDRBT.js";
import {
  Bar_default
} from "./chunk-NMUIRNIP.js";
import {
  Vector_default as Vector_default2
} from "./chunk-PD2E5XZ4.js";
import {
  element_default
} from "./chunk-S3QBQTEW.js";
import "./chunk-V7WRBSQ6.js";
import "./chunk-W7BDJOQY.js";
import {
  Circle_default,
  LineString_default,
  MultiPolygon_default
} from "./chunk-7JXPN73Q.js";
import {
  Feature_default
} from "./chunk-E53S5GN6.js";
import {
  Vector_default
} from "./chunk-T3TT2KJN.js";
import "./chunk-HM3IY3H4.js";
import "./chunk-JFXZSSOM.js";
import "./chunk-ZUI5NXIU.js";
import "./chunk-I4Q72WOW.js";
import {
  Pointer_default
} from "./chunk-RTVPCGIJ.js";
import {
  Interaction_default
} from "./chunk-MSWSBYBR.js";
import {
  click,
  shiftKeyOnly
} from "./chunk-QCJTGAWF.js";
import "./chunk-CAVOO5JW.js";
import "./chunk-VRTURNK3.js";
import "./chunk-2C73OZ6M.js";
import {
  Collection_default
} from "./chunk-M5TTSD4C.js";
import "./chunk-ZCRXKB7J.js";
import "./chunk-RW3V7S4F.js";
import {
  Circle_default as Circle_default2,
  Fill_default,
  RegularShape_default,
  Stroke_default,
  Style_default
} from "./chunk-PAB2HIXK.js";
import "./chunk-I6K7MRGV.js";
import "./chunk-PGWX4545.js";
import "./chunk-AYBYZSAV.js";
import "./chunk-YLJGUH5Z.js";
import {
  LinearRing_default,
  Point_default,
  Polygon_default,
  fromCircle,
  fromExtent
} from "./chunk-AZGMK675.js";
import "./chunk-BHVDQB66.js";
import "./chunk-6EWLK2BW.js";
import "./chunk-6Y7C6NBJ.js";
import "./chunk-5D2XPBR2.js";
import "./chunk-SHUBVYN4.js";
import "./chunk-FM44FOIC.js";
import "./chunk-LMC3RO5P.js";
import "./chunk-X52LGBOS.js";
import "./chunk-QFCIXVZ3.js";
import "./chunk-A3RXLHYB.js";
import "./chunk-ZLPTRF2L.js";
import "./chunk-54BTDBAD.js";
import "./chunk-UPTVWZ45.js";
import "./chunk-5XHD7RSF.js";
import "./chunk-Q5ZULJHM.js";
import {
  unByKey
} from "./chunk-NGFXCWUF.js";
import "./chunk-K25ZO44T.js";
import {
  boundingExtent,
  buffer,
  createEmpty,
  extend,
  getCenter
} from "./chunk-SRXHWJOY.js";
import "./chunk-5RHQVMYD.js";
import "./chunk-DC5AMYBS.js";

// node_modules/ol-ext/control/TextButton.js
var ol_control_TextButton = class olcontrolTextButton extends Button_default {
  constructor(options) {
    options = options || {};
    options.className = (options.className || "") + " ol-text-button";
    super(options);
  }
};
var TextButton_default = ol_control_TextButton;

// node_modules/ol-ext/interaction/Delete.js
var ol_interaction_Delete = class olinteractionDelete extends Select_default {
  constructor(options) {
    super(options);
    this.on("select", (function(e) {
      this.getFeatures().clear();
      this.delete(e.selected);
    }).bind(this));
  }
  /** Get vector source of the map
   * @return {Array<ol.source.Vector>}
   */
  _getSources(layers) {
    if (!this.getMap())
      return [];
    if (!layers)
      layers = this.getMap().getLayers();
    var sources = [];
    layers.forEach((function(l) {
      if (l.getLayers) {
        sources = sources.concat(this._getSources(l.getLayers()));
      } else {
        if (l.getSource && l.getSource() instanceof Vector_default2) {
          sources.push(l.getSource());
        }
      }
    }).bind(this));
    return sources;
  }
  /** Delete features: remove the features from the map (from all layers in the map)
   * @param {ol.Collection<ol.Feature>|Array<ol.Feature>} features The features to delete
   * @api
   */
  delete(features) {
    if (features && (features.length || features.getLength())) {
      this.dispatchEvent({ type: "deletestart", features });
      var delFeatures = [];
      this._getSources().forEach(function(source) {
        try {
          features.forEach(function(f) {
            source.removeFeature(f);
            delFeatures.push(f);
          });
        } catch (e) {
        }
      });
      this.dispatchEvent({ type: "deleteend", features: delFeatures });
    }
  }
};
var Delete_default = ol_interaction_Delete;

// node_modules/ol-ext/style/defaultStyle.js
var ol_style_Style_defaultStyle;
(function() {
  var white = [255, 255, 255, 1];
  var blue = [0, 153, 255, 1];
  var width = 3;
  var defaultEditStyle = [
    new Style_default({
      stroke: new Stroke_default({ color: white, width: width + 2 })
    }),
    new Style_default({
      image: new Circle_default2({
        radius: width * 2,
        fill: new Fill_default({ color: blue }),
        stroke: new Stroke_default({ color: white, width: width / 2 })
      }),
      stroke: new Stroke_default({ color: blue, width }),
      fill: new Fill_default({
        color: [255, 255, 255, 0.5]
      })
    })
  ];
  ol_style_Style_defaultStyle = function(edit) {
    if (edit === true) {
      return defaultEditStyle;
    } else {
      edit = edit || {};
      var fill = new Fill_default({
        color: edit.fillColor || "rgba(255,255,255,0.4)"
      });
      var stroke = new Stroke_default({
        color: edit.color || "#3399CC",
        width: 1.25
      });
      var style = new Style_default({
        image: new Circle_default2({
          fill,
          stroke,
          radius: 5
        }),
        fill,
        stroke
      });
      return [style];
    }
  };
})();
var defaultStyle_default = ol_style_Style_defaultStyle;

// node_modules/ol-ext/interaction/Offset.js
var ol_interaction_Offset = class olinteractionOffset extends Pointer_default {
  constructor(options) {
    options = options || {};
    super({
      handleDownEvent: function(e) {
        return self.handleDownEvent_(e);
      },
      handleDragEvent: function(e) {
        return self.handleDragEvent_(e);
      },
      handleMoveEvent: function(e) {
        return self.handleMoveEvent_(e);
      },
      handleUpEvent: function(e) {
        return self.handleUpEvent_(e);
      }
    });
    var self = this;
    this._filter = options.filter;
    this.features_ = options.features;
    this.layers_ = options.layers ? options.layers instanceof Array ? options.layers : [options.layers] : null;
    this.set("duplicate", options.duplicate);
    this.source_ = options.source;
    this._style = typeof options.style === "function" ? options.style : function() {
      if (options.style)
        return options.style;
      else
        return defaultStyle_default(true);
    };
    this.previousCursor_ = false;
  }
  /** Get Feature at pixel
   * @param {ol.MapBrowserEvent} evt Map browser event.
   * @return {any} a feature and the hit point
   * @private
   */
  getFeatureAtPixel_(e) {
    var self = this;
    return this.getMap().forEachFeatureAtPixel(
      e.pixel,
      function(feature, layer) {
        var current;
        if (self._filter && !self._filter(feature, layer))
          return false;
        if (self.layers_) {
          for (var i = 0; i < self.layers_.length; i++) {
            if (self.layers_[i] === layer) {
              current = feature;
              break;
            }
          }
        } else if (self.features_) {
          self.features_.forEach(function(f) {
            if (f === feature) {
              current = feature;
            }
          });
        } else {
          current = feature;
        }
        var typeGeom = current.getGeometry().getType();
        if (current && /Polygon|LineString/.test(typeGeom)) {
          if (typeGeom === "Polygon" && current.getGeometry().getCoordinates().length > 1)
            return false;
          var p = current.getGeometry().getClosestPoint(e.coordinate);
          var dx = p[0] - e.coordinate[0];
          var dy = p[1] - e.coordinate[1];
          var d = Math.sqrt(dx * dx + dy * dy) / e.frameState.viewState.resolution;
          if (d < 5) {
            return {
              feature: current,
              hit: p,
              coordinates: current.getGeometry().getCoordinates(),
              geom: current.getGeometry().clone(),
              geomType: typeGeom
            };
          } else {
            return false;
          }
        } else {
          return false;
        }
      },
      { hitTolerance: 5 }
    );
  }
  /**
   * @param {ol.MapBrowserEvent} e Map browser event.
   * @return {boolean} `true` to start the drag sequence.
   * @private
   */
  handleDownEvent_(e) {
    this.current_ = this.getFeatureAtPixel_(e);
    if (this.current_) {
      this.currentStyle_ = this.current_.feature.getStyle();
      if (this.source_ && (this.get("duplicate") || e.originalEvent.ctrlKey)) {
        this.current_.feature = this.current_.feature.clone();
        this.current_.feature.setStyle(this._style(this.current_.feature));
        this.source_.addFeature(this.current_.feature);
      } else {
        this.current_.feature.setStyle(this._style(this.current_.feature));
        this._modifystart = true;
      }
      this.dispatchEvent({ type: "offsetstart", feature: this.current_.feature, offset: 0 });
      return true;
    } else {
      return false;
    }
  }
  /**
   * @param {ol.MapBrowserEvent} e Map browser event.
   * @private
   */
  handleDragEvent_(e) {
    if (this._modifystart) {
      this.dispatchEvent({ type: "modifystart", features: [this.current_.feature] });
      this._modifystart = false;
    }
    var p = this.current_.geom.getClosestPoint(e.coordinate);
    var d = ol_coordinate_dist2d(p, e.coordinate);
    var seg, v1, v2, offset;
    switch (this.current_.geomType) {
      case "Polygon": {
        seg = ol_coordinate_findSegment(p, this.current_.coordinates[0]).segment;
        if (seg) {
          v1 = [seg[1][0] - seg[0][0], seg[1][1] - seg[0][1]];
          v2 = [e.coordinate[0] - p[0], e.coordinate[1] - p[1]];
          if (v1[0] * v2[1] - v1[1] * v2[0] > 0) {
            d = -d;
          }
          offset = [];
          for (var i = 0; i < this.current_.coordinates.length; i++) {
            offset.push(ol_coordinate_offsetCoords(this.current_.coordinates[i], i == 0 ? d : -d));
          }
          this.current_.feature.setGeometry(new Polygon_default(offset));
        }
        break;
      }
      case "LineString": {
        seg = ol_coordinate_findSegment(p, this.current_.coordinates).segment;
        if (seg) {
          v1 = [seg[1][0] - seg[0][0], seg[1][1] - seg[0][1]];
          v2 = [e.coordinate[0] - p[0], e.coordinate[1] - p[1]];
          if (v1[0] * v2[1] - v1[1] * v2[0] > 0) {
            d = -d;
          }
          offset = ol_coordinate_offsetCoords(this.current_.coordinates, d);
          this.current_.feature.setGeometry(new LineString_default(offset));
        }
        break;
      }
      default: {
        break;
      }
    }
    this.dispatchEvent({ type: "offsetting", feature: this.current_.feature, offset: d, segment: [p, e.coordinate], coordinate: e.coordinate });
  }
  /**
   * @param {ol.MapBrowserEvent} e Map browser event.
   * @private
   */
  handleUpEvent_(e) {
    if (!this._modifystart) {
      this.dispatchEvent({ type: "offsetend", feature: this.current_.feature, coordinate: e.coordinate });
    }
    this.current_.feature.setStyle(this.currentStyle_);
    this.current_ = false;
  }
  /**
   * @param {ol.MapBrowserEvent} e Event.
   * @private
   */
  handleMoveEvent_(e) {
    var f = this.getFeatureAtPixel_(e);
    if (f) {
      if (this.previousCursor_ === false) {
        this.previousCursor_ = e.map.getTargetElement().style.cursor;
      }
      element_default.setCursor(e.map, "pointer");
    } else {
      element_default.setCursor(e.map, this.previousCursor_);
      this.previousCursor_ = false;
    }
  }
};
var Offset_default = ol_interaction_Offset;

// node_modules/ol-ext/interaction/Split.js
var ol_interaction_Split = class olinteractionSplit extends Interaction_default {
  constructor(options) {
    if (!options)
      options = {};
    super({
      handleEvent: function(e) {
        switch (e.type) {
          case "singleclick":
            return this.handleDownEvent(e);
          case "pointermove":
            return this.handleMoveEvent(e);
          default:
            return true;
        }
      }
    });
    this.snapDistance_ = options.snapDistance || 25;
    this.tolerance_ = options.tolerance || 1e-10;
    this.cursor_ = options.cursor;
    this.setSources(options.sources);
    if (options.features) {
      if (!this.sources_) this.sources_ = [];
      this.sources_.push(new Vector_default2({ features: options.features }));
    }
    this.filterSplit_ = options.filter || function() {
      return true;
    };
    var white = [255, 255, 255, 1];
    var blue = [0, 153, 255, 1];
    var width = 3;
    var fill = new Fill_default({ color: "rgba(255,255,255,0.4)" });
    var stroke = new Stroke_default({
      color: "#3399CC",
      width: 1.25
    });
    var sketchStyle = [
      new Style_default({
        image: new Circle_default2({
          fill,
          stroke,
          radius: 5
        }),
        fill,
        stroke
      })
    ];
    var featureStyle = [
      new Style_default({
        stroke: new Stroke_default({
          color: white,
          width: width + 2
        })
      }),
      new Style_default({
        image: new Circle_default2({
          radius: 2 * width,
          fill: new Fill_default({
            color: blue
          }),
          stroke: new Stroke_default({
            color: white,
            width: width / 2
          })
        }),
        stroke: new Stroke_default({
          color: blue,
          width
        })
      })
    ];
    if (options.sketchStyle)
      sketchStyle = options.sketchStyle instanceof Array ? options.sketchStyle : [options.sketchStyle];
    if (options.featureStyle)
      featureStyle = options.featureStyle instanceof Array ? options.featureStyle : [options.featureStyle];
    this.overlayLayer_ = new Vector_default({
      source: new Vector_default2({
        useSpatialIndex: false
      }),
      name: "Split overlay",
      displayInLayerSwitcher: false,
      style: function(f) {
        if (f._sketch_)
          return sketchStyle;
        else
          return featureStyle;
      }
    });
  }
  /**
   * Remove the interaction from its current map, if any,  and attach it to a new
   * map, if any. Pass `null` to just remove the interaction from the current map.
   * @param {ol.Map} map Map.
   * @api stable
   */
  setMap(map) {
    if (this.getMap()) {
      this.getMap().removeLayer(this.overlayLayer_);
    }
    super.setMap(map);
    this.overlayLayer_.setMap(map);
  }
  /** Get sources to split features in
   * @return {Array<ol.source.Vector>}
   */
  getSources() {
    if (!this.sources_ && this.getMap()) {
      var sources = [];
      var getSources = function(layers) {
        layers.forEach(function(layer) {
          if (layer.getVisible()) {
            if (layer.getSource && layer.getSource() instanceof Vector_default2) {
              sources.unshift(layer.getSource());
            } else if (layer.getLayers) {
              getSources(layer.getLayers());
            }
          }
        });
      };
      getSources(this.getMap().getLayers());
      return sources;
    }
    return this.sources_ || [];
  }
  /** Set sources to split features in
   * @param {ol.source.Vector|Array<ol.source.Vector>|boolean} [sources] if not defined get all map vector sources
   */
  setSources(sources) {
    this.sources_ = sources ? sources instanceof Array ? sources || false : [sources] : false;
  }
  /** Get closest feature at pixel
   * @param {ol.Pixel}
   * @return {ol.feature}
   * @private
   */
  getClosestFeature(e) {
    var source, f, c, g, d = this.snapDistance_ + 1;
    this.getSources().forEach(function(si) {
      var fi = si.getClosestFeatureToCoordinate(e.coordinate);
      if (fi && fi.getGeometry().splitAt) {
        var ci = fi.getGeometry().getClosestPoint(e.coordinate);
        var gi = new LineString_default([e.coordinate, ci]);
        var di = gi.getLength() / e.frameState.viewState.resolution;
        if (di < d) {
          source = si;
          d = di;
          f = fi;
          g = gi;
          c = ci;
        }
      }
    });
    if (d > this.snapDistance_) {
      return false;
    } else {
      var coord = this.getNearestCoord(c, f.getGeometry().getCoordinates());
      var p = this.getMap().getPixelFromCoordinate(coord);
      if (ol_coordinate_dist2d(e.pixel, p) < this.snapDistance_) {
        c = coord;
      }
      return { source, feature: f, coord: c, link: g };
    }
  }
  /** Get nearest coordinate in a list
  * @param {ol.coordinate} pt the point to find nearest
  * @param {Array<ol.coordinate>} coords list of coordinates
  * @return {ol.coordinate} the nearest coordinate in the list
  */
  getNearestCoord(pt, coords) {
    var d, dm = Number.MAX_VALUE, p0;
    for (var i = 0; i < coords.length; i++) {
      d = ol_coordinate_dist2d(pt, coords[i]);
      if (d < dm) {
        dm = d;
        p0 = coords[i];
      }
    }
    return p0;
  }
  /**
   * @param {ol.MapBrowserEvent} evt Map browser event.
   * @return {boolean} `true` to start the drag sequence.
   */
  handleDownEvent(evt) {
    var current = this.getClosestFeature(evt);
    if (current) {
      var self = this;
      self.overlayLayer_.getSource().clear();
      var split = current.feature.getGeometry().splitAt(current.coord, this.tolerance_);
      var i;
      if (split.length > 1) {
        var tosplit = [];
        for (i = 0; i < split.length; i++) {
          var f = current.feature.clone();
          f.setGeometry(split[i]);
          tosplit.push(f);
        }
        self.dispatchEvent({ type: "beforesplit", original: current.feature, features: tosplit });
        current.source.dispatchEvent({ type: "beforesplit", original: current.feature, features: tosplit });
        current.source.removeFeature(current.feature);
        for (i = 0; i < tosplit.length; i++) {
          current.source.addFeature(tosplit[i]);
        }
        self.dispatchEvent({ type: "aftersplit", original: current.feature, features: tosplit });
        current.source.dispatchEvent({ type: "aftersplit", original: current.feature, features: tosplit });
      }
    }
    return false;
  }
  /**
   * @param {ol.MapBrowserEvent} evt Event.
   */
  handleMoveEvent(e) {
    var map = e.map;
    this.overlayLayer_.getSource().clear();
    var current = this.getClosestFeature(e);
    if (current && this.filterSplit_(current.feature)) {
      var p, l;
      this.overlayLayer_.getSource().addFeature(current.feature);
      p = new Feature_default(new Point_default(current.coord));
      p._sketch_ = true;
      this.overlayLayer_.getSource().addFeature(p);
      l = new Feature_default(current.link);
      l._sketch_ = true;
      this.overlayLayer_.getSource().addFeature(l);
      this.dispatchEvent({
        type: "pointermove",
        coordinate: e.coordinate,
        frameState: e.frameState,
        originalEvent: e.originalEvent,
        map: e.map,
        pixel: e.pixel,
        feature: current.feature,
        linkGeometry: current.link
      });
    } else {
      this.dispatchEvent(e);
    }
    var element = map.getTargetElement();
    if (this.cursor_) {
      if (current) {
        if (element.style.cursor != this.cursor_) {
          this.previousCursor_ = element.style.cursor;
          element_default.setCursor(element, this.cursor_);
        }
      } else if (this.previousCursor_ !== void 0) {
        element_default.setCursor(element, this.previousCursor_);
        this.previousCursor_ = void 0;
      }
    }
  }
};
var Split_default = ol_interaction_Split;

// node_modules/ol-ext/interaction/Transform.js
var ol_interaction_Transform = class olinteractionTransform extends Pointer_default {
  constructor(options) {
    options = options || {};
    super({
      handleDownEvent: function(e) {
        return self.handleDownEvent_(e);
      },
      handleDragEvent: function(e) {
        return this.handleDragEvent_(e);
      },
      handleMoveEvent: function(e) {
        return this.handleMoveEvent_(e);
      },
      handleUpEvent: function(e) {
        return this.handleUpEvent_(e);
      }
    });
    var self = this;
    this.selection_ = new Collection_default();
    this.handles_ = new Collection_default();
    this.overlayLayer_ = new Vector_default({
      source: new Vector_default2({
        features: this.handles_,
        useSpatialIndex: false,
        wrapX: false
        // For vector editing across the -180° and 180° meridians to work properly, this should be set to false
      }),
      name: "Transform overlay",
      displayInLayerSwitcher: false,
      // Return the style according to the handle type
      style: function(feature) {
        return self.style[(feature.get("handle") || "default") + (feature.get("constraint") || "") + (feature.get("option") || "")];
      },
      updateWhileAnimating: true,
      updateWhileInteracting: true
    });
    this.features_ = options.features;
    if (typeof options.filter === "function")
      this._filter = options.filter;
    this.layers_ = options.layers ? options.layers instanceof Array ? options.layers : [options.layers] : null;
    this._handleEvent = options.condition || function() {
      return true;
    };
    this.addFn_ = options.addCondition || function() {
      return false;
    };
    this.setPointRadius(options.pointRadius);
    this.set("translateFeature", options.translateFeature !== false);
    this.set("translate", options.translate !== false);
    this.set("translateBBox", options.translateBBox === true);
    this.set("stretch", options.stretch !== false);
    this.set("scale", options.scale !== false);
    this.set("rotate", options.rotate !== false);
    this.set("keepAspectRatio", options.keepAspectRatio || function(e) {
      return e.originalEvent.shiftKey;
    });
    this.set("modifyCenter", options.modifyCenter || function(e) {
      return e.originalEvent.metaKey || e.originalEvent.ctrlKey;
    });
    this.set("noFlip", options.noFlip || false);
    this.set("selection", options.selection !== false);
    this.set("hitTolerance", options.hitTolerance || 0);
    this.set("enableRotatedTransform", options.enableRotatedTransform || false);
    this.set("keepRectangle", options.keepRectangle || false);
    this.set("buffer", options.buffer || 0);
    this.on("propertychange", function() {
      this.drawSketch_();
    });
    this.setDefaultStyle();
    if (options.select) {
      this.on("change:active", (function(e) {
        if (this.getActive()) {
          this.setSelection(options.select.getFeatures().getArray());
        } else {
          options.select.getFeatures().extend(this.selection_);
          this.selection_.forEach(function(f) {
            options.select.getFeatures().push(f);
          });
          this.select(null);
        }
      }).bind(this));
    } else {
      this.on("change:active", (function(e) {
        this.select(null);
      }).bind(this));
    }
  }
  /**
   * Remove the interaction from its current map, if any,  and attach it to a new
   * map, if any. Pass `null` to just remove the interaction from the current map.
   * @param {ol.Map} map Map.
   * @api stable
   */
  setMap(map) {
    var oldMap = this.getMap();
    if (oldMap) {
      oldMap.removeLayer(this.overlayLayer_);
      if (this.previousCursor_) {
        element_default.setCursor(oldMap, this.previousCursor_);
      }
      this.previousCursor_ = void 0;
    }
    super.setMap(map);
    this.overlayLayer_.setMap(map);
    if (map === null) {
      this.select(null);
    }
    if (map !== null) {
      this.isTouch = /touch/.test(map.getViewport().className);
      this.setDefaultStyle();
    }
  }
  /**
   * Activate/deactivate interaction
   * @param {bool}
   * @api stable
   */
  setActive(b) {
    if (this.overlayLayer_) this.overlayLayer_.setVisible(b);
    super.setActive(b);
  }
  /** Set default sketch style
   * @param {Object} [options]
   *  @param {ol_style_Stroke} [stroke] stroke style for selection rectangle, default red dash
   *  @param {ol_style_Fill} [fill] fill style for selection rectangle, default red
   *  @param {ol_style_Stroke} [pointStroke] stroke style for handles, default red
   *  @param {ol_style_Fill} [pointFill] fill style for handles, default white
   */
  setDefaultStyle(options) {
    options = options || {};
    var stroke = options.pointStroke || new Stroke_default({ color: [255, 0, 0, 1], width: 1 });
    var strokedash = options.stroke || new Stroke_default({ color: [255, 0, 0, 1], width: 1, lineDash: [4, 4] });
    var fill0 = options.fill || new Fill_default({ color: [255, 0, 0, 0.01] });
    var fill = options.pointFill || new Fill_default({ color: [255, 255, 255, 0.8] });
    var circle = new RegularShape_default({
      fill,
      stroke,
      radius: this.isTouch ? 12 : 6,
      displacement: this.isTouch ? [24, -24] : [12, -12],
      points: 15
    });
    if (!circle.setDisplacement)
      circle.getAnchor()[0] = this.isTouch ? -10 : -5;
    var bigpt = new RegularShape_default({
      fill,
      stroke,
      radius: this.isTouch ? 16 : 8,
      points: 4,
      angle: Math.PI / 4
    });
    var smallpt = new RegularShape_default({
      fill,
      stroke,
      radius: this.isTouch ? 12 : 6,
      points: 4,
      angle: Math.PI / 4
    });
    function createStyle(img, stroke2, fill2) {
      return [new Style_default({ image: img, stroke: stroke2, fill: fill2 })];
    }
    this.style = {
      "default": createStyle(bigpt, strokedash, fill0),
      "translate": createStyle(bigpt, stroke, fill),
      "rotate": createStyle(circle, stroke, fill),
      "rotate0": createStyle(bigpt, stroke, fill),
      "scale": createStyle(bigpt, stroke, fill),
      "scale1": createStyle(bigpt, stroke, fill),
      "scale2": createStyle(bigpt, stroke, fill),
      "scale3": createStyle(bigpt, stroke, fill),
      "scalev": createStyle(smallpt, stroke, fill),
      "scaleh1": createStyle(smallpt, stroke, fill),
      "scalev2": createStyle(smallpt, stroke, fill),
      "scaleh3": createStyle(smallpt, stroke, fill)
    };
    this.drawSketch_();
  }
  /**
   * Set sketch style.
   * @param {style} style Style name: 'default','translate','rotate','rotate0','scale','scale1','scale2','scale3','scalev','scaleh1','scalev2','scaleh3'
   * @param {ol.style.Style|Array<ol.style.Style>} olstyle
   * @api stable
   */
  setStyle(style, olstyle) {
    if (!olstyle)
      return;
    if (olstyle instanceof Array)
      this.style[style] = olstyle;
    else
      this.style[style] = [olstyle];
    for (var i = 0; i < this.style[style].length; i++) {
      var im = this.style[style][i].getImage();
      if (im) {
        if (style == "rotate") {
          im.getAnchor()[0] = -5;
        }
        if (this.isTouch)
          im.setScale(1.8);
      }
      var tx = this.style[style][i].getText();
      if (tx) {
        if (style == "rotate")
          tx.setOffsetX(this.isTouch ? 14 : 7);
        if (this.isTouch)
          tx.setScale(1.8);
      }
    }
    this.drawSketch_();
  }
  /** Get Feature at pixel
   * @param {ol.Pixel}
   * @return {ol.feature}
   * @private
   */
  getFeatureAtPixel_(pixel) {
    var self = this;
    return this.getMap().forEachFeatureAtPixel(
      pixel,
      function(feature, layer) {
        var found = false;
        if (!layer) {
          if (feature === self.bbox_) {
            if (self.get("translateBBox")) {
              return { feature, handle: "translate", constraint: "", option: "" };
            } else {
              return false;
            }
          }
          self.handles_.forEach(function(f) {
            if (f === feature)
              found = true;
          });
          if (found)
            return { feature, handle: feature.get("handle"), constraint: feature.get("constraint"), option: feature.get("option") };
        }
        if (!self.get("selection")) {
          if (self.selection_.getArray().some(function(f) {
            return feature === f;
          })) {
            return { feature };
          }
          return null;
        }
        if (self._filter) {
          if (self._filter(feature, layer))
            return { feature };
          else
            return null;
        } else if (self.layers_) {
          for (var i = 0; i < self.layers_.length; i++) {
            if (self.layers_[i] === layer)
              return { feature };
          }
          return null;
        } else if (self.features_) {
          self.features_.forEach(function(f) {
            if (f === feature)
              found = true;
          });
          if (found)
            return { feature };
          else
            return null;
        } else
          return { feature };
      },
      { hitTolerance: this.get("hitTolerance") }
    ) || {};
  }
  /** Rotate feature from map view rotation
   * @param {ol.Feature} f the feature
   * @param {boolean} clone clone resulting geom
   * @param {ol.geom.Geometry} rotated geometry
   */
  getGeometryRotateToZero_(f, clone) {
    var origGeom = f.getGeometry();
    var viewRotation = this.getMap().getView().getRotation();
    if (viewRotation === 0 || !this.get("enableRotatedTransform")) {
      return clone ? origGeom.clone() : origGeom;
    }
    var rotGeom = origGeom.clone();
    rotGeom.rotate(viewRotation * -1, this.getMap().getView().getCenter());
    return rotGeom;
  }
  /** Test if rectangle
   * @param {ol.Geometry} geom
   * @returns {boolean}
   * @private
   */
  _isRectangle(geom) {
    if (this.get("keepRectangle") && geom.getType() === "Polygon") {
      var coords = geom.getCoordinates()[0];
      return coords.length === 5;
    }
    return false;
  }
  /** Draw transform sketch
  * @param {boolean} draw only the center
  */
  drawSketch_(center) {
    var i, f, geom;
    var keepRectangle = this.selection_.item(0) && this._isRectangle(this.selection_.item(0).getGeometry());
    this.overlayLayer_.getSource().clear();
    if (!this.selection_.getLength())
      return;
    var viewRotation = this.getMap().getView().getRotation();
    var ext = this.getGeometryRotateToZero_(this.selection_.item(0)).getExtent();
    var coords;
    if (keepRectangle) {
      coords = this.getGeometryRotateToZero_(this.selection_.item(0)).getCoordinates()[0].slice(0, 4);
      coords.unshift(coords[3]);
    }
    ext = buffer(ext, this.get("buffer"));
    this.selection_.forEach((function(f2) {
      var extendExt = this.getGeometryRotateToZero_(f2).getExtent();
      extend(ext, extendExt);
    }).bind(this));
    var ptRadius = this.selection_.getLength() === 1 ? this._pointRadius(this.selection_.item(0)) : 0;
    if (ptRadius && !(ptRadius instanceof Array))
      ptRadius = [ptRadius, ptRadius];
    if (center === true) {
      if (!this.ispt_) {
        this.overlayLayer_.getSource().addFeature(new Feature_default({ geometry: new Point_default(this.center_), handle: "rotate0" }));
        geom = fromExtent(ext);
        if (this.get("enableRotatedTransform") && viewRotation !== 0) {
          geom.rotate(viewRotation, this.getMap().getView().getCenter());
        }
        f = this.bbox_ = new Feature_default(geom);
        this.overlayLayer_.getSource().addFeature(f);
      }
    } else {
      if (this.ispt_) {
        var p = this.getMap().getPixelFromCoordinate(getCenter(ext));
        if (p) {
          var dx = ptRadius ? ptRadius[0] || 10 : 10;
          var dy = ptRadius ? ptRadius[1] || 10 : 10;
          ext = boundingExtent([
            this.getMap().getCoordinateFromPixel([p[0] - dx, p[1] - dy]),
            this.getMap().getCoordinateFromPixel([p[0] + dx, p[1] + dy])
          ]);
        }
      }
      geom = keepRectangle ? new Polygon_default([coords]) : fromExtent(ext);
      if (this.get("enableRotatedTransform") && viewRotation !== 0) {
        geom.rotate(viewRotation, this.getMap().getView().getCenter());
      }
      f = this.bbox_ = new Feature_default(geom);
      var features = [];
      var g = geom.getCoordinates()[0];
      if (!this.ispt_ || ptRadius) {
        features.push(f);
        if (!this.iscircle_ && !this.ispt_ && this.get("stretch") && this.get("scale"))
          for (i = 0; i < g.length - 1; i++) {
            f = new Feature_default({ geometry: new Point_default([(g[i][0] + g[i + 1][0]) / 2, (g[i][1] + g[i + 1][1]) / 2]), handle: "scale", constraint: i % 2 ? "h" : "v", option: i });
            features.push(f);
          }
        if (this.get("scale"))
          for (i = 0; i < g.length - 1; i++) {
            f = new Feature_default({ geometry: new Point_default(g[i]), handle: "scale", option: i });
            features.push(f);
          }
        if (this.get("translate") && !this.get("translateFeature")) {
          f = new Feature_default({ geometry: new Point_default([(g[0][0] + g[2][0]) / 2, (g[0][1] + g[2][1]) / 2]), handle: "translate" });
          features.push(f);
        }
      }
      if (!this.iscircle_ && this.get("rotate")) {
        f = new Feature_default({ geometry: new Point_default(g[3]), handle: "rotate" });
        features.push(f);
      }
      this.overlayLayer_.getSource().addFeatures(features);
    }
  }
  /** Select a feature to transform
  * @param {ol.Feature} feature the feature to transform
  * @param {boolean} add true to add the feature to the selection, default false
  */
  select(feature, add) {
    if (!feature) {
      if (this.selection_) {
        this.selection_.clear();
        this.drawSketch_();
      }
      return;
    }
    if (!feature.getGeometry || !feature.getGeometry()) return;
    if (add) {
      this.selection_.push(feature);
    } else {
      var index = this.selection_.getArray().indexOf(feature);
      this.selection_.removeAt(index);
    }
    this.ispt_ = this.selection_.getLength() === 1 ? this.selection_.item(0).getGeometry().getType() == "Point" : false;
    this.iscircle_ = this.selection_.getLength() === 1 ? this.selection_.item(0).getGeometry().getType() == "Circle" : false;
    this.drawSketch_();
    this.watchFeatures_();
    this.dispatchEvent({ type: "select", feature, features: this.selection_ });
  }
  /** Update the selection collection.
  * @param {ol.Collection<ol.Feature>} features the features to transform
  */
  setSelection(features) {
    this.selection_.clear();
    features.forEach((function(feature) {
      this.selection_.push(feature);
    }).bind(this));
    this.ispt_ = this.selection_.getLength() === 1 ? this.selection_.item(0).getGeometry().getType() == "Point" : false;
    this.iscircle_ = this.selection_.getLength() === 1 ? this.selection_.item(0).getGeometry().getType() == "Circle" : false;
    this.drawSketch_();
    this.watchFeatures_();
    this.dispatchEvent({ type: "select", features: this.selection_ });
  }
  /** Watch selected features
   * @private
   */
  watchFeatures_() {
    if (this._featureListeners) {
      this._featureListeners.forEach(function(l) {
        unByKey(l);
      });
    }
    this._featureListeners = [];
    this.selection_.forEach((function(f) {
      this._featureListeners.push(
        f.on("change", (function() {
          if (!this.isUpdating_) {
            this.drawSketch_();
          }
        }).bind(this))
      );
    }).bind(this));
  }
  /**
   * @param {ol.MapBrowserEvent} evt Map browser event.
   * @return {boolean} `true` to start the drag sequence.
   * @private
   */
  handleDownEvent_(evt) {
    if (!this._handleEvent(evt, this.selection_))
      return;
    var sel = this.getFeatureAtPixel_(evt.pixel);
    var feature = sel.feature;
    if (this.selection_.getLength() && this.selection_.getArray().indexOf(feature) >= 0 && (this.ispt_ && this.get("translate") || this.get("translateFeature"))) {
      sel.handle = "translate";
    }
    if (sel.handle) {
      this.mode_ = sel.handle;
      this.opt_ = sel.option;
      this.constraint_ = sel.constraint;
      var viewRotation = this.getMap().getView().getRotation();
      this.coordinate_ = feature.get("handle") ? feature.getGeometry().getCoordinates() : evt.coordinate;
      this.pixel_ = this.getMap().getCoordinateFromPixel(this.coordinate_);
      this.geoms_ = [];
      this.rotatedGeoms_ = [];
      var extent = createEmpty();
      var rotExtent = createEmpty();
      this.hasChanged_ = false;
      for (var i = 0, f; f = this.selection_.item(i); i++) {
        this.geoms_.push(f.getGeometry().clone());
        extent = extend(extent, f.getGeometry().getExtent());
        if (this.get("enableRotatedTransform") && viewRotation !== 0) {
          var rotGeom = this.getGeometryRotateToZero_(f, true);
          this.rotatedGeoms_.push(rotGeom);
          rotExtent = extend(rotExtent, rotGeom.getExtent());
        }
      }
      this.extent_ = fromExtent(extent).getCoordinates()[0];
      if (this.get("enableRotatedTransform") && viewRotation !== 0) {
        this.rotatedExtent_ = fromExtent(rotExtent).getCoordinates()[0];
      }
      if (this.mode_ === "rotate") {
        this.center_ = this.getCenter() || getCenter(extent);
        var element = evt.map.getTargetElement();
        element_default.setCursor(element, this.Cursors.rotate0);
        this.previousCursor_ = element.style.cursor;
      } else {
        this.center_ = getCenter(extent);
      }
      this.angle_ = Math.atan2(this.center_[1] - evt.coordinate[1], this.center_[0] - evt.coordinate[0]);
      this.dispatchEvent({
        type: this.mode_ + "start",
        feature: this.selection_.item(0),
        features: this.selection_,
        pixel: evt.pixel,
        coordinate: evt.coordinate
      });
      return true;
    } else if (this.get("selection")) {
      if (feature) {
        if (!this.addFn_(evt))
          this.selection_.clear();
        var index = this.selection_.getArray().indexOf(feature);
        if (index < 0)
          this.selection_.push(feature);
        else
          this.selection_.removeAt(index);
      } else {
        this.selection_.clear();
      }
      this.ispt_ = this.selection_.getLength() === 1 ? this.selection_.item(0).getGeometry().getType() == "Point" : false;
      this.iscircle_ = this.selection_.getLength() === 1 ? this.selection_.item(0).getGeometry().getType() == "Circle" : false;
      this.drawSketch_();
      this.watchFeatures_();
      this.dispatchEvent({ type: "select", feature, features: this.selection_, pixel: evt.pixel, coordinate: evt.coordinate });
      return false;
    }
  }
  /**
   * Get the rotation center
   * @return {ol.coordinate|undefined}
   */
  getCenter() {
    return this.get("center");
  }
  /**
   * Set the rotation center
   * @param {ol.coordinate|undefined} c the center point, default center on the objet
   */
  setCenter(c) {
    return this.set("center", c);
  }
  /**
   * @param {ol.MapBrowserEvent} evt Map browser event.
   * @private
   */
  handleDragEvent_(evt) {
    if (!this._handleEvent(evt, this.features_))
      return;
    var viewRotation = this.getMap().getView().getRotation();
    var i, j, f, geometry;
    var pt0 = [this.coordinate_[0], this.coordinate_[1]];
    var pt = [evt.coordinate[0], evt.coordinate[1]];
    this.isUpdating_ = true;
    this.hasChanged_ = true;
    switch (this.mode_) {
      case "rotate": {
        var a = Math.atan2(this.center_[1] - pt[1], this.center_[0] - pt[0]);
        if (!this.ispt) {
          for (i = 0, f; f = this.selection_.item(i); i++) {
            geometry = this.geoms_[i].clone();
            geometry.rotate(a - this.angle_, this.center_);
            if (geometry.getType() == "Circle")
              geometry.setCenterAndRadius(geometry.getCenter(), geometry.getRadius());
            f.setGeometry(geometry);
          }
        }
        this.drawSketch_(true);
        this.dispatchEvent({
          type: "rotating",
          feature: this.selection_.item(0),
          features: this.selection_,
          angle: a - this.angle_,
          pixel: evt.pixel,
          coordinate: evt.coordinate
        });
        break;
      }
      case "translate": {
        var deltaX = pt[0] - pt0[0];
        var deltaY = pt[1] - pt0[1];
        for (i = 0, f; f = this.selection_.item(i); i++) {
          f.getGeometry().translate(deltaX, deltaY);
        }
        this.handles_.forEach(function(f2) {
          f2.getGeometry().translate(deltaX, deltaY);
        });
        this.coordinate_ = evt.coordinate;
        this.dispatchEvent({
          type: "translating",
          feature: this.selection_.item(0),
          features: this.selection_,
          delta: [deltaX, deltaY],
          pixel: evt.pixel,
          coordinate: evt.coordinate
        });
        break;
      }
      case "scale": {
        var center = this.center_;
        if (this.get("modifyCenter")(evt)) {
          var extentCoordinates = this.extent_;
          if (this.get("enableRotatedTransform") && viewRotation !== 0) {
            extentCoordinates = this.rotatedExtent_;
          }
          center = extentCoordinates[(Number(this.opt_) + 2) % 4];
        }
        var keepRectangle = this.geoms_.length == 1 && this._isRectangle(this.geoms_[0]);
        var stretch = this.constraint_;
        var opt = this.opt_;
        var downCoordinate = this.coordinate_;
        var dragCoordinate = evt.coordinate;
        if (this.get("enableRotatedTransform") && viewRotation !== 0) {
          var downPoint = new Point_default(this.coordinate_);
          downPoint.rotate(viewRotation * -1, center);
          downCoordinate = downPoint.getCoordinates();
          var dragPoint = new Point_default(evt.coordinate);
          dragPoint.rotate(viewRotation * -1, center);
          dragCoordinate = dragPoint.getCoordinates();
        }
        var scx = (dragCoordinate[0] - center[0]) / (downCoordinate[0] - center[0]);
        var scy = (dragCoordinate[1] - center[1]) / (downCoordinate[1] - center[1]);
        var displacementVector = [dragCoordinate[0] - downCoordinate[0], dragCoordinate[1] - downCoordinate[1]];
        if (this.get("enableRotatedTransform") && viewRotation !== 0) {
          var centerPoint = new Point_default(center);
          centerPoint.rotate(viewRotation * -1, this.getMap().getView().getCenter());
          center = centerPoint.getCoordinates();
        }
        if (this.get("noFlip")) {
          if (scx < 0)
            scx = -scx;
          if (scy < 0)
            scy = -scy;
        }
        if (this.constraint_) {
          if (this.constraint_ == "h")
            scx = 1;
          else
            scy = 1;
        } else {
          if (this.get("keepAspectRatio")(evt)) {
            scx = scy = Math.min(scx, scy);
          }
        }
        for (i = 0, f; f = this.selection_.item(i); i++) {
          geometry = viewRotation === 0 || !this.get("enableRotatedTransform") ? this.geoms_[i].clone() : this.rotatedGeoms_[i].clone();
          geometry.applyTransform((function(g1, g2, dim) {
            if (dim < 2) return g2;
            if (!keepRectangle) {
              for (j = 0; j < g1.length; j += dim) {
                if (scx != 1)
                  g2[j] = center[0] + (g1[j] - center[0]) * scx;
                if (scy != 1)
                  g2[j + 1] = center[1] + (g1[j + 1] - center[1]) * scy;
              }
            } else {
              var pointArray = [[6], [0, 8], [2], [4]];
              var pointA = [g1[0], g1[1]];
              var pointB = [g1[2], g1[3]];
              var pointC = [g1[4], g1[5]];
              var pointD = [g1[6], g1[7]];
              var pointA1 = [g1[8], g1[9]];
              if (stretch) {
                var base = opt % 2 === 0 ? this._countVector(pointA, pointB) : this._countVector(pointD, pointA);
                var projectedVector = this._projectVectorOnVector(displacementVector, base);
                var nextIndex = opt + 1 < pointArray.length ? opt + 1 : 0;
                var coordsToChange = [...pointArray[opt], ...pointArray[nextIndex]];
                for (j = 0; j < g1.length; j += dim) {
                  g2[j] = coordsToChange.includes(j) ? g1[j] + projectedVector[0] : g1[j];
                  g2[j + 1] = coordsToChange.includes(j) ? g1[j + 1] + projectedVector[1] : g1[j + 1];
                }
              } else {
                var projectedLeft, projectedRight;
                switch (opt) {
                  case 0:
                    displacementVector = this._countVector(pointD, dragCoordinate);
                    projectedLeft = this._projectVectorOnVector(displacementVector, this._countVector(pointC, pointD));
                    projectedRight = this._projectVectorOnVector(displacementVector, this._countVector(pointA, pointD));
                    [g2[0], g2[1]] = this._movePoint(pointA, projectedLeft);
                    [g2[4], g2[5]] = this._movePoint(pointC, projectedRight);
                    [g2[6], g2[7]] = this._movePoint(pointD, displacementVector);
                    [g2[8], g2[9]] = this._movePoint(pointA1, projectedLeft);
                    break;
                  case 1:
                    displacementVector = this._countVector(pointA, dragCoordinate);
                    projectedLeft = this._projectVectorOnVector(displacementVector, this._countVector(pointD, pointA));
                    projectedRight = this._projectVectorOnVector(displacementVector, this._countVector(pointB, pointA));
                    [g2[0], g2[1]] = this._movePoint(pointA, displacementVector);
                    [g2[2], g2[3]] = this._movePoint(pointB, projectedLeft);
                    [g2[6], g2[7]] = this._movePoint(pointD, projectedRight);
                    [g2[8], g2[9]] = this._movePoint(pointA1, displacementVector);
                    break;
                  case 2:
                    displacementVector = this._countVector(pointB, dragCoordinate);
                    projectedLeft = this._projectVectorOnVector(displacementVector, this._countVector(pointA, pointB));
                    projectedRight = this._projectVectorOnVector(displacementVector, this._countVector(pointC, pointB));
                    [g2[0], g2[1]] = this._movePoint(pointA, projectedRight);
                    [g2[2], g2[3]] = this._movePoint(pointB, displacementVector);
                    [g2[4], g2[5]] = this._movePoint(pointC, projectedLeft);
                    [g2[8], g2[9]] = this._movePoint(pointA1, projectedRight);
                    break;
                  case 3:
                    displacementVector = this._countVector(pointC, dragCoordinate);
                    projectedLeft = this._projectVectorOnVector(displacementVector, this._countVector(pointB, pointC));
                    projectedRight = this._projectVectorOnVector(displacementVector, this._countVector(pointD, pointC));
                    [g2[2], g2[3]] = this._movePoint(pointB, projectedRight);
                    [g2[4], g2[5]] = this._movePoint(pointC, displacementVector);
                    [g2[6], g2[7]] = this._movePoint(pointD, projectedLeft);
                    break;
                }
              }
            }
            if (geometry.getType() == "Circle") geometry.setCenterAndRadius(geometry.getCenter(), geometry.getRadius());
            return g2;
          }).bind(this));
          if (this.get("enableRotatedTransform") && viewRotation !== 0) {
            geometry.rotate(viewRotation, this.getMap().getView().getCenter());
          }
          f.setGeometry(geometry);
        }
        this.drawSketch_();
        this.dispatchEvent({
          type: "scaling",
          feature: this.selection_.item(0),
          features: this.selection_,
          scale: [scx, scy],
          pixel: evt.pixel,
          coordinate: evt.coordinate
        });
        break;
      }
      default:
        break;
    }
    this.isUpdating_ = false;
  }
  /**
   * @param {ol.MapBrowserEvent} evt Event.
   * @private
   */
  handleMoveEvent_(evt) {
    if (!this._handleEvent(evt, this.features_))
      return;
    if (!this.mode_) {
      var sel = this.getFeatureAtPixel_(evt.pixel);
      var element = evt.map.getTargetElement();
      if (sel.feature) {
        var c = sel.handle ? this.Cursors[(sel.handle || "default") + (sel.constraint || "") + (sel.option || "")] : this.Cursors.select;
        if (this.previousCursor_ === void 0) {
          this.previousCursor_ = element.style.cursor;
        }
        element_default.setCursor(element, c);
      } else {
        if (this.previousCursor_ !== void 0) {
          element_default.setCursor(element, this.previousCursor_);
        }
        this.previousCursor_ = void 0;
      }
    }
  }
  /**
   * @param {ol.MapBrowserEvent} evt Map browser event.
   * @return {boolean} `false` to stop the drag sequence.
   */
  handleUpEvent_(evt) {
    if (this.mode_ === "rotate") {
      var element = evt.map.getTargetElement();
      element_default.setCursor(element, this.Cursors.default);
      this.previousCursor_ = void 0;
    }
    this.dispatchEvent({
      type: this.mode_ + "end",
      feature: this.selection_.item(0),
      features: this.selection_,
      oldgeom: this.geoms_[0],
      oldgeoms: this.geoms_,
      // handle changes
      transformed: this.hasChanged_
    });
    this.drawSketch_();
    this.hasChanged_ = false;
    this.mode_ = null;
    return false;
  }
  /** Set the point radius to calculate handles on points
   *  @param {number|Array<number>|function} [pointRadius=0] radius for points or a function that takes a feature and returns the radius (or [radiusX, radiusY]). If not null show handles to transform the points
   */
  setPointRadius(pointRadius) {
    if (typeof pointRadius === "function") {
      this._pointRadius = pointRadius;
    } else {
      this._pointRadius = function() {
        return pointRadius;
      };
    }
  }
  /** Get the features that are selected for transform
   * @return ol.Collection
   */
  getFeatures() {
    return this.selection_;
  }
  /**
   * @private
   */
  _projectVectorOnVector(displacement_vector, base) {
    var k = (displacement_vector[0] * base[0] + displacement_vector[1] * base[1]) / (base[0] * base[0] + base[1] * base[1]);
    return [base[0] * k, base[1] * k];
  }
  /**
   * @private
   */
  _countVector(start, end) {
    return [end[0] - start[0], end[1] - start[1]];
  }
  /**
   * @private
   */
  _movePoint(point, displacementVector) {
    return [point[0] + displacementVector[0], point[1] + displacementVector[1]];
  }
};
ol_interaction_Transform.prototype.Cursors = {
  "default": "auto",
  "select": "pointer",
  "translate": "move",
  "rotate": "move",
  "rotate0": "move",
  "scale": "nesw-resize",
  "scale1": "nwse-resize",
  "scale2": "nesw-resize",
  "scale3": "nwse-resize",
  "scalev": "ew-resize",
  "scaleh1": "ns-resize",
  "scalev2": "ew-resize",
  "scaleh3": "ns-resize"
};
var Transform_default = ol_interaction_Transform;

// node_modules/ol-ext/interaction/DrawRegular.js
var ol_interaction_DrawRegular = class olinteractionDrawRegular extends Interaction_default {
  constructor(options) {
    options = options || {};
    super({
      handleEvent: function(e) {
        return self.handleEvent_(e);
      }
    });
    var self = this;
    this.squaredClickTolerance_ = options.clickTolerance ? options.clickTolerance * options.clickTolerance : 36;
    this.maxCircleCoordinates_ = options.maxCircleCoordinates || 100;
    this.features_ = options.features;
    this.source_ = options.source;
    this.conditionFn_ = options.condition;
    this.squareFn_ = options.squareCondition;
    this.centeredFn_ = options.centerCondition;
    this.canRotate_ = options.canRotate !== false;
    this.geometryName_ = options.geometryName || "geometry";
    this.setSides(options.sides);
    var defaultStyle = defaultStyle_default(true);
    this.sketch_ = new Collection_default();
    this.overlayLayer_ = new Vector_default({
      source: new Vector_default2({
        features: this.sketch_,
        useSpatialIndex: false
      }),
      name: "DrawRegular overlay",
      displayInLayerSwitcher: false,
      style: options.style || defaultStyle
    });
  }
  /**
   * Remove the interaction from its current map, if any,  and attach it to a new
   * map, if any. Pass `null` to just remove the interaction from the current map.
   * @param {ol.Map} map Map.
   * @api stable
   */
  setMap(map) {
    if (this.getMap()) this.getMap().removeLayer(this.overlayLayer_);
    super.setMap(map);
    this.overlayLayer_.setMap(map);
  }
  /**
   * Activate/deactivate the interaction
   * @param {boolean}
   * @api stable
   */
  setActive(b) {
    this.reset();
    super.setActive(b);
  }
  /**
   * Reset the interaction
   * @api stable
   */
  reset() {
    if (this.overlayLayer_) this.overlayLayer_.getSource().clear();
    this.started_ = false;
  }
  /**
   * Set the number of sides.
   * @param {int} number of sides.
   * @api stable
   */
  setSides(nb) {
    nb = parseInt(nb);
    this.sides_ = nb > 2 ? nb : 0;
  }
  /**
   * Allow rotation when centered + square
   * @param {bool}
   * @api stable
   */
  canRotate(b) {
    if (b === true || b === false)
      this.canRotate_ = b;
    return this.canRotate_;
  }
  /**
   * Get the number of sides.
   * @return {int} number of sides.
   * @api stable
   */
  getSides() {
    return this.sides_;
  }
  /** Get geom of the current drawing
  * @return {ol.geom.Polygon | ol.geom.Point}
  */
  getGeom_() {
    this.overlayLayer_.getSource().clear();
    if (!this.center_)
      return false;
    var g;
    if (this.coord_) {
      var center = this.center_;
      var coord = this.coord_;
      var d, dmax, r, circle, centerPx;
      if (!this.sides_ && this.square_ && !this.centered_) {
        center = [(coord[0] + center[0]) / 2, (coord[1] + center[1]) / 2];
        d = [coord[0] - center[0], coord[1] - center[1]];
        r = Math.sqrt(d[0] * d[0] + d[1] * d[1]);
        circle = new Circle_default(center, r, "XY");
        centerPx = this.getMap().getPixelFromCoordinate(center);
        dmax = Math.max(100, Math.abs(centerPx[0] - this.coordPx_[0]), Math.abs(centerPx[1] - this.coordPx_[1]));
        dmax = Math.min(this.maxCircleCoordinates_, Math.round(dmax / 3));
        return fromCircle(circle, dmax, 0);
      } else {
        var hasrotation = this.canRotate_ && this.centered_ && this.square_;
        d = [coord[0] - center[0], coord[1] - center[1]];
        if (this.square_ && !hasrotation) {
          var dm = Math.max(Math.abs(d[0]), Math.abs(d[1]));
          coord = [
            center[0] + (d[0] > 0 ? dm : -dm),
            center[1] + (d[1] > 0 ? dm : -dm)
          ];
        }
        r = Math.sqrt(d[0] * d[0] + d[1] * d[1]);
        if (r > 0) {
          circle = new Circle_default(center, r, "XY");
          var a;
          if (hasrotation)
            a = Math.atan2(d[1], d[0]);
          else
            a = this.startAngle[this.sides_] || this.startAngle["default"];
          if (this.sides_) {
            g = fromCircle(circle, this.sides_, a);
          } else {
            centerPx = this.getMap().getPixelFromCoordinate(this.center_);
            dmax = Math.max(100, Math.abs(centerPx[0] - this.coordPx_[0]), Math.abs(centerPx[1] - this.coordPx_[1]));
            dmax = Math.min(this.maxCircleCoordinates_, Math.round(dmax / (this.centered_ ? 3 : 5)));
            g = fromCircle(circle, dmax, 0);
          }
          if (hasrotation)
            return g;
          var ext = g.getExtent();
          if (!this.centered_)
            center = this.center_;
          else
            center = [2 * this.center_[0] - this.coord_[0], 2 * this.center_[1] - this.coord_[1]];
          var scx = (center[0] - coord[0]) / (ext[0] - ext[2]);
          var scy = (center[1] - coord[1]) / (ext[1] - ext[3]);
          if (this.square_) {
            var sc = Math.min(Math.abs(scx), Math.abs(scy));
            scx = Math.sign(scx) * sc;
            scy = Math.sign(scy) * sc;
          }
          var t = [center[0] - ext[0] * scx, center[1] - ext[1] * scy];
          g.applyTransform(function(g1, g2, dim) {
            for (var i = 0; i < g1.length; i += dim) {
              g2[i] = g1[i] * scx + t[0];
              g2[i + 1] = g1[i + 1] * scy + t[1];
            }
            return g2;
          });
          return g;
        }
      }
    }
    return new Point_default(this.center_);
  }
  /** Draw sketch
  * @return {ol.Feature} The feature being drawn.
  */
  drawSketch_(evt) {
    this.overlayLayer_.getSource().clear();
    if (evt) {
      this.square_ = this.squareFn_ ? this.squareFn_(evt) : evt.originalEvent.shiftKey;
      this.centered_ = this.centeredFn_ ? this.centeredFn_(evt) : evt.originalEvent.metaKey || evt.originalEvent.ctrlKey;
      var g = this.getGeom_();
      if (g) {
        var f = this.feature_;
        if (g.getType() === "Polygon")
          f.getGeometry().setCoordinates(g.getCoordinates());
        this.overlayLayer_.getSource().addFeature(f);
        if (this.coord_ && this.square_ && (this.canRotate_ && this.centered_ && this.coord_ || !this.sides_ && !this.centered_)) {
          this.overlayLayer_.getSource().addFeature(new Feature_default(new LineString_default([this.center_, this.coord_])));
        }
        return f;
      }
    }
  }
  /** Draw sketch (Point)
  */
  drawPoint_(pt, noclear) {
    if (!noclear) {
      this.overlayLayer_.getSource().clear();
    }
    this.overlayLayer_.getSource().addFeature(new Feature_default(new Point_default(pt)));
  }
  /**
   * @param {ol.MapBrowserEvent} evt Map browser event.
   */
  handleEvent_(evt) {
    var dx, dy;
    this._eventTime = /* @__PURE__ */ new Date();
    switch (evt.type) {
      case "pointerdown": {
        if (this.conditionFn_ && !this.conditionFn_(evt)) break;
        this.downPx_ = evt.pixel;
        this.start_(evt);
        var dt = 500;
        this._longTouch = false;
        setTimeout((function() {
          this._longTouch = /* @__PURE__ */ new Date() - this._eventTime > 0.9 * dt;
          if (this._longTouch)
            this.handleMoveEvent_(evt);
        }).bind(this), dt);
        this.lastEvent = evt.type;
        break;
      }
      case "pointerup": {
        if (this.started_ && this.coord_) {
          dx = this.downPx_[0] - evt.pixel[0];
          dy = this.downPx_[1] - evt.pixel[1];
          if (dx * dx + dy * dy <= this.squaredClickTolerance_) {
            if (this.lastEvent == "pointerdown" || this.lastEvent == "pointermove" || this.lastEvent == "keydown") {
              this.end_(evt);
            } else {
              dx = this.upPx_[0] - evt.pixel[0];
              dy = this.upPx_[1] - evt.pixel[1];
              if (dx * dx + dy * dy <= this.squaredClickTolerance_) {
                this.end_(evt);
              } else {
                this.handleMoveEvent_(evt);
                this.drawPoint_(evt.coordinate, true);
              }
            }
          }
        }
        this.upPx_ = evt.pixel;
        break;
      }
      case "pointerdrag": {
        if (this.started_) {
          var centerPx = this.getMap().getPixelFromCoordinate(this.center_);
          dx = centerPx[0] - evt.pixel[0];
          dy = centerPx[1] - evt.pixel[1];
          if (dx * dx + dy * dy <= this.squaredClickTolerance_) {
            this.reset();
          }
        }
        return !this._longTouch;
      }
      case "pointermove": {
        if (this.started_) {
          dx = this.downPx_[0] - evt.pixel[0];
          dy = this.downPx_[1] - evt.pixel[1];
          if (dx * dx + dy * dy > this.squaredClickTolerance_) {
            this.handleMoveEvent_(evt);
            this.lastEvent = evt.type;
          }
        } else {
          this.drawPoint_(evt.coordinate);
        }
        break;
      }
      default: {
        if (this.started_ && (evt.type === "click" || evt.type === "singleclick" || evt.type === "dblclick")) {
          return false;
        }
        this.lastEvent = evt.type;
        break;
      }
    }
    return true;
  }
  /** Stop drawing.
   */
  finishDrawing() {
    if (this.started_ && this.coord_) {
      this.end_({ pixel: this.upPx_, coordinate: this.coord_ });
    }
  }
  /**
   * @param {ol.MapBrowserEvent} evt Event.
   */
  handleMoveEvent_(evt) {
    if (this.started_) {
      this.coord_ = evt.coordinate;
      this.coordPx_ = evt.pixel;
      var f = this.drawSketch_(evt);
      this.dispatchEvent({
        type: "drawing",
        feature: f,
        pixel: evt.pixel,
        startCoordinate: this.center_,
        coordinate: evt.coordinate,
        square: this.square_,
        centered: this.centered_
      });
    } else {
      this.drawPoint_(evt.coordinate);
    }
  }
  /** Start an new draw
   * @param {ol.MapBrowserEvent} evt Map browser event.
   * @return {boolean} `false` to stop the drag sequence.
   */
  start_(evt) {
    if (!this.started_) {
      this.started_ = true;
      this.center_ = evt.coordinate;
      this.coord_ = null;
      var f = this.feature_ = new Feature_default({});
      f.setGeometryName(this.geometryName_ || "geometry");
      f.setGeometry(new Polygon_default([[evt.coordinate, evt.coordinate, evt.coordinate]]));
      this.drawSketch_(evt);
      this.dispatchEvent({ type: "drawstart", feature: f, pixel: evt.pixel, coordinate: evt.coordinate });
    } else {
      this.coord_ = evt.coordinate;
    }
  }
  /** End drawing
   * @param {ol.MapBrowserEvent} evt Map browser event.
   * @return {boolean} `false` to stop the drag sequence.
   */
  end_(evt) {
    this.coord_ = evt.coordinate;
    this.started_ = false;
    if (this.coord_ && (this.center_[0] !== this.coord_[0] || this.center_[1] !== this.coord_[1])) {
      var f = this.feature_;
      f.setGeometry(this.getGeom_());
      if (this.source_)
        this.source_.addFeature(f);
      else if (this.features_)
        this.features_.push(f);
      this.dispatchEvent({ type: "drawend", feature: f, pixel: evt.pixel, coordinate: evt.coordinate, square: this.square_, centered: this.centered_ });
    } else {
      this.dispatchEvent({ type: "drawcancel", feature: null, pixel: evt.pixel, coordinate: evt.coordinate, square: this.square_, centered: this.centered_ });
    }
    this.center_ = this.coord_ = null;
    this.drawSketch_();
  }
};
ol_interaction_DrawRegular.prototype.startAngle = {
  "default": Math.PI / 2,
  3: -Math.PI / 2,
  4: Math.PI / 4
};
var DrawRegular_default = ol_interaction_DrawRegular;

// node_modules/ol-ext/interaction/DrawHole.js
var ol_interaction_DrawHole = class olinteractionDrawHole extends Draw_default {
  constructor(options) {
    options = options || {};
    var _geometryFn = function(coordinates, geometry) {
      var coord = coordinates[0].pop();
      if (!this.getPolygon() || this.getPolygon().intersectsCoordinate(coord)) {
        this.lastOKCoord = [coord[0], coord[1]];
      }
      coordinates[0].push([this.lastOKCoord[0], this.lastOKCoord[1]]);
      if (geometry) {
        geometry.setCoordinates([coordinates[0].concat([coordinates[0][0]])]);
      } else {
        geometry = new Polygon_default(coordinates);
      }
      return geometry;
    };
    var geomFn = options.geometryFunction;
    if (geomFn) {
      options.geometryFunction = function(c, g, p) {
        g = _geometryFn.bind(this)(c, g);
        return geomFn.bind(this)(c, g, p);
      };
    } else {
      options.geometryFunction = _geometryFn;
    }
    options.type = "Polygon";
    super(options);
    this._select = new Select_default({ style: options.style });
    this._select.setActive(false);
    if (options.layers) {
      if (typeof options.layers === "function") {
        this.layers_ = options.layers;
      } else if (options.layers.indexOf) {
        this.layers_ = function(l) {
          return options.layers.indexOf(l) >= 0;
        };
      }
    }
    if (typeof options.featureFilter === "function") {
      this._features = options.featureFilter;
    } else if (options.featureFilter) {
      var features = options.featureFilter;
      this._features = function(f) {
        if (features.indexOf) {
          return !!features[features.indexOf(f)];
        } else {
          return !!features.item(features.getArray().indexOf(f));
        }
      };
    } else {
      this._features = function() {
        return true;
      };
    }
    this.on("drawstart", this._startDrawing.bind(this));
    this.on("drawend", this._finishDrawing.bind(this));
  }
  /**
   * Remove the interaction from its current map, if any,  and attach it to a new
   * map, if any. Pass `null` to just remove the interaction from the current map.
   * @param {ol.Map} map Map.
   * @api stable
   */
  setMap(map) {
    if (this.getMap()) this.getMap().removeInteraction(this._select);
    if (map) map.addInteraction(this._select);
    super.setMap.call(this, map);
  }
  /**
   * Activate/deactivate the interaction
   * @param {boolean}
   * @api stable
   */
  setActive(b) {
    if (this._select) this._select.getFeatures().clear();
    super.setActive.call(this, b);
  }
  /**
   * Remove last point of the feature currently being drawn
   * (test if points to remove before).
   */
  removeLastPoint() {
    if (this._feature && this._feature.getGeometry().getCoordinates()[0].length > 2) {
      super.removeLastPoint.call(this);
    }
  }
  /**
   * Get the current polygon to hole
   * @return {ol.Feature}
   */
  getPolygon() {
    return this._polygon;
  }
  /**
   * Get current feature to add a hole and start drawing
   * @param {ol_interaction_Draw.Event} e
   * @private
   */
  _startDrawing(e) {
    var map = this.getMap();
    this._feature = e.feature;
    var coord = e.feature.getGeometry().getCoordinates()[0][0];
    this._current = null;
    map.forEachFeatureAtPixel(
      map.getPixelFromCoordinate(coord),
      (function(feature, layer) {
        if (!this._current && this._features(feature, layer)) {
          var poly = feature.getGeometry();
          if (poly.getType() === "Polygon" && poly.intersectsCoordinate(coord)) {
            this._polygonIndex = false;
            this._polygon = poly;
            this._current = feature;
          } else if (poly.getType() === "MultiPolygon" && poly.intersectsCoordinate(coord)) {
            for (var i = 0, p; p = poly.getPolygon(i); i++) {
              if (p.intersectsCoordinate(coord)) {
                this._polygonIndex = i;
                this._polygon = p;
                this._current = feature;
                break;
              }
            }
          }
        }
      }).bind(this),
      {
        layerFilter: this.layers_
      }
    );
    this._select.getFeatures().clear();
    if (!this._current) {
      this.setActive(false);
      this.setActive(true);
    } else {
      this._select.getFeatures().push(this._current);
    }
  }
  /**
   * Stop drawing and add the sketch feature to the target feature.
   * @param {ol_interaction_Draw.Event} e
   * @private
   */
  _finishDrawing(e) {
    e.hole = e.feature;
    e.feature = this._select.getFeatures().item(0);
    this.dispatchEvent({ type: "modifystart", features: [this._current] });
    var c = e.hole.getGeometry().getCoordinates()[0];
    if (c.length > 3) {
      if (this._polygonIndex !== false) {
        var geom = e.feature.getGeometry();
        var newGeom = new MultiPolygon_default([]);
        for (var i = 0, pi; pi = geom.getPolygon(i); i++) {
          if (i === this._polygonIndex) {
            pi.appendLinearRing(new LinearRing_default(c));
            newGeom.appendPolygon(pi);
          } else {
            newGeom.appendPolygon(pi);
          }
        }
        e.feature.setGeometry(newGeom);
      } else {
        this.getPolygon().appendLinearRing(new LinearRing_default(c));
      }
    }
    this.dispatchEvent({ type: "modifyend", features: [this._current] });
    this._feature = null;
    this._select.getFeatures().clear();
  }
  /**
   * Function that is called when a geometry's coordinates are updated.
   * @param {Array<ol.coordinate>} coordinates
   * @param {ol_geom_Polygon} geometry
   * @return {ol_geom_Polygon}
   * @private
   */
  _geometryFn(coordinates, geometry) {
    var coord = coordinates[0].pop();
    if (!this.getPolygon() || this.getPolygon().intersectsCoordinate(coord)) {
      this.lastOKCoord = [coord[0], coord[1]];
    }
    coordinates[0].push([this.lastOKCoord[0], this.lastOKCoord[1]]);
    if (geometry) {
      geometry.setCoordinates([coordinates[0].concat([coordinates[0][0]])]);
    } else {
      geometry = new Polygon_default(coordinates);
    }
    return geometry;
  }
};
var DrawHole_default = ol_interaction_DrawHole;

// node_modules/ol-ext/control/EditBar.js
var ol_control_EditBar = class olcontrolEditBar extends Bar_default {
  constructor(options) {
    options = options || {};
    options.interactions = options.interactions || {};
    super({
      className: (options.className ? options.className + " " : "") + "ol-editbar",
      toggleOne: true,
      target: options.target
    });
    this._source = options.source;
    this._interactions = {};
    this._setSelectInteraction(options);
    if (options.edition !== false)
      this._setEditInteraction(options);
    this._setModifyInteraction(options);
  }
  /**
   * Set the map instance the control is associated with
   * and add its controls associated to this map.
   * @param {_ol_Map_} map The map instance.
   */
  setMap(map) {
    if (this.getMap()) {
      if (this._interactions.Delete)
        this.getMap().removeInteraction(this._interactions.Delete);
      if (this._interactions.ModifySelect)
        this.getMap().removeInteraction(this._interactions.ModifySelect);
    }
    super.setMap(map);
    if (this.getMap()) {
      if (this._interactions.Delete)
        this.getMap().addInteraction(this._interactions.Delete);
      if (this._interactions.ModifySelect)
        this.getMap().addInteraction(this._interactions.ModifySelect);
    }
  }
  /** Get an interaction associated with the bar
   * @param {string} name
   */
  getInteraction(name) {
    return this._interactions[name];
  }
  /** Get the option title */
  _getTitle(option) {
    if (option) {
      if (option.get)
        return option.get("title");
      else if (typeof option === "string")
        return option;
      else
        return option.title;
    }
  }
  /** Add selection tool:
   * 1. a toggle control with a select interaction
   * 2. an option bar to delete / get information on the selected feature
   * @private
   */
  _setSelectInteraction(options) {
    var self = this;
    var sbar = new Bar_default();
    var selectCtrl;
    if (options.interactions.Delete !== false) {
      if (options.interactions.Delete instanceof Delete_default) {
        this._interactions.Delete = options.interactions.Delete;
      } else {
        this._interactions.Delete = new Delete_default();
      }
      var del = this._interactions.Delete;
      del.setActive(false);
      if (this.getMap())
        this.getMap().addInteraction(del);
      sbar.addControl(new Button_default({
        className: "ol-delete",
        title: this._getTitle(options.interactions.Delete) || "Delete",
        name: "Delete",
        handleClick: function(e) {
          del.delete(selectCtrl.getInteraction().getFeatures());
          var evt = {
            type: "select",
            selected: [],
            deselected: selectCtrl.getInteraction().getFeatures().getArray().slice(),
            mapBrowserEvent: e.mapBrowserEvent
          };
          selectCtrl.getInteraction().getFeatures().clear();
          selectCtrl.getInteraction().dispatchEvent(evt);
        }
      }));
    }
    if (options.interactions.Info !== false) {
      sbar.addControl(new Button_default({
        className: "ol-info",
        name: "Info",
        title: this._getTitle(options.interactions.Info) || "Show informations",
        handleClick: function() {
          self.dispatchEvent({
            type: "info",
            features: selectCtrl.getInteraction().getFeatures()
          });
        }
      }));
    }
    if (options.interactions.Select !== false) {
      if (options.interactions.Select instanceof Select_default) {
        this._interactions.Select = options.interactions.Select;
      } else {
        this._interactions.Select = new Select_default({
          condition: click
        });
      }
      var sel = this._interactions.Select;
      selectCtrl = new Toggle_default({
        className: "ol-selection",
        name: "Select",
        title: this._getTitle(options.interactions.Select) || "Select",
        interaction: sel,
        bar: sbar.getControls().length ? sbar : void 0,
        autoActivate: true,
        active: true
      });
      this.addControl(selectCtrl);
      sel.on("change:active", (function() {
        if (!sel.getActive()) {
          sel.getFeatures().clear();
        }
      }).bind(this));
    }
  }
  /** Add editing tools
   * @private
   */
  _setEditInteraction(options) {
    if (options.interactions.DrawPoint !== false) {
      if (options.interactions.DrawPoint instanceof Draw_default) {
        this._interactions.DrawPoint = options.interactions.DrawPoint;
      } else {
        this._interactions.DrawPoint = new Draw_default({
          type: "Point",
          source: this._source
        });
      }
      var pedit = new Toggle_default({
        className: "ol-drawpoint",
        name: "DrawPoint",
        title: this._getTitle(options.interactions.DrawPoint) || "Point",
        interaction: this._interactions.DrawPoint
      });
      this.addControl(pedit);
    }
    if (options.interactions.DrawLine !== false) {
      if (options.interactions.DrawLine instanceof Draw_default) {
        this._interactions.DrawLine = options.interactions.DrawLine;
      } else {
        this._interactions.DrawLine = new Draw_default({
          type: "LineString",
          source: this._source,
          // Count inserted points
          geometryFunction: function(coordinates, geometry) {
            if (geometry)
              geometry.setCoordinates(coordinates);
            else
              geometry = new LineString_default(coordinates);
            this.nbpts = geometry.getCoordinates().length;
            return geometry;
          }
        });
      }
      var ledit;
      if (options.drawOptions !== false) {
        ledit = new Toggle_default({
          className: "ol-drawline",
          title: this._getTitle(options.interactions.DrawLine) || "LineString",
          name: "DrawLine",
          interaction: this._interactions.DrawLine,
          // Options bar associated with the control
          bar: new Bar_default({
            controls: [
              new TextButton_default({
                html: this._getTitle(options.interactions.UndoDraw) || "undo",
                title: this._getTitle(options.interactions.UndoDraw) || "delete last point",
                handleClick: function() {
                  if (ledit.getInteraction().nbpts > 1)
                    ledit.getInteraction().removeLastPoint();
                }
              }),
              new TextButton_default({
                html: this._getTitle(options.interactions.FinishDraw) || "finish",
                title: this._getTitle(options.interactions.FinishDraw) || "finish",
                handleClick: function() {
                  if (ledit.getInteraction().nbpts > 2)
                    ledit.getInteraction().finishDrawing();
                }
              })
            ]
          })
        });
      } else {
        ledit = new Toggle_default({
          className: "ol-drawline",
          title: this._getTitle(options.interactions.DrawLine) || "LineString",
          name: "DrawLine",
          interaction: this._interactions.DrawLine
        });
      }
      this.addControl(ledit);
    }
    if (options.interactions.DrawPolygon !== false) {
      if (options.interactions.DrawPolygon instanceof Draw_default) {
        this._interactions.DrawPolygon = options.interactions.DrawPolygon;
      } else {
        this._interactions.DrawPolygon = new Draw_default({
          type: "Polygon",
          source: this._source,
          // Count inserted points
          geometryFunction: function(coordinates, geometry) {
            this.nbpts = coordinates[0].length;
            if (geometry)
              geometry.setCoordinates([coordinates[0].concat([coordinates[0][0]])]);
            else
              geometry = new Polygon_default(coordinates);
            return geometry;
          }
        });
      }
      this._setDrawPolygon(
        "ol-drawpolygon",
        this._interactions.DrawPolygon,
        this._getTitle(options.interactions.DrawPolygon) || "Polygon",
        "DrawPolygon",
        options
      );
    }
    if (options.interactions.DrawHole !== false) {
      if (options.interactions.DrawHole instanceof DrawHole_default) {
        this._interactions.DrawHole = options.interactions.DrawHole;
      } else {
        this._interactions.DrawHole = new DrawHole_default();
      }
      this._setDrawPolygon(
        "ol-drawhole",
        this._interactions.DrawHole,
        this._getTitle(options.interactions.DrawHole) || "Hole",
        "DrawHole",
        options
      );
    }
    if (options.interactions.DrawRegular !== false) {
      var label = { pts: "pts", circle: "circle" };
      if (options.interactions.DrawRegular instanceof DrawRegular_default) {
        this._interactions.DrawRegular = options.interactions.DrawRegular;
        label.pts = this._interactions.DrawRegular.get("ptsLabel") || label.pts;
        label.circle = this._interactions.DrawRegular.get("circleLabel") || label.circle;
      } else {
        this._interactions.DrawRegular = new DrawRegular_default({
          source: this._source,
          sides: 4
        });
        if (options.interactions.DrawRegular) {
          label.pts = options.interactions.DrawRegular.ptsLabel || label.pts;
          label.circle = options.interactions.DrawRegular.circleLabel || label.circle;
        }
      }
      var regular = this._interactions.DrawRegular;
      var div = document.createElement("div");
      var down = element_default.create("DIV", { parent: div });
      element_default.addListener(down, ["click", "touchstart"], (function() {
        var sides = regular.getSides() - 1;
        if (sides < 2)
          sides = 2;
        regular.setSides(sides);
        text.textContent = sides > 2 ? sides + " " + label.pts : label.circle;
      }).bind(this));
      var text = element_default.create("TEXT", { html: "4 " + label.pts, parent: div });
      var up = element_default.create("DIV", { parent: div });
      element_default.addListener(up, ["click", "touchstart"], (function() {
        var sides = regular.getSides() + 1;
        if (sides < 3)
          sides = 3;
        regular.setSides(sides);
        text.textContent = sides + " " + label.pts;
      }).bind(this));
      var ctrl = new Toggle_default({
        className: "ol-drawregular",
        title: this._getTitle(options.interactions.DrawRegular) || "Regular",
        name: "DrawRegular",
        interaction: this._interactions.DrawRegular,
        // Options bar associated with the control
        bar: new Bar_default({
          controls: [
            new TextButton_default({
              html: div
            })
          ]
        })
      });
      this.addControl(ctrl);
    }
  }
  /**
   * @private
   */
  _setDrawPolygon(className, interaction, title, name, options) {
    var fedit;
    if (options.drawOptions !== false) {
      fedit = new Toggle_default({
        className,
        name,
        title,
        interaction,
        // Options bar associated with the control
        bar: new Bar_default({
          controls: [
            new TextButton_default({
              html: this._getTitle(options.interactions.UndoDraw) || "undo",
              title: this._getTitle(options.interactions.UndoDraw) || "undo last point",
              handleClick: function() {
                if (fedit.getInteraction().nbpts > 1)
                  fedit.getInteraction().removeLastPoint();
              }
            }),
            new TextButton_default({
              html: this._getTitle(options.interactions.FinishDraw) || "finish",
              title: this._getTitle(options.interactions.FinishDraw) || "finish",
              handleClick: function() {
                if (fedit.getInteraction().nbpts > 3)
                  fedit.getInteraction().finishDrawing();
              }
            })
          ]
        })
      });
    } else {
      fedit = new Toggle_default({
        className,
        name,
        title,
        interaction
      });
    }
    this.addControl(fedit);
    return fedit;
  }
  /** Add modify tools
   * @private
   */
  _setModifyInteraction(options) {
    if (options.interactions.ModifySelect !== false && options.interactions.Select !== false) {
      if (options.interactions.ModifySelect instanceof ModifyFeature_default) {
        this._interactions.ModifySelect = options.interactions.ModifySelect;
      } else {
        this._interactions.ModifySelect = new ModifyFeature_default({
          features: this.getInteraction("Select").getFeatures()
        });
      }
      if (this.getMap())
        this.getMap().addInteraction(this._interactions.ModifySelect);
      this._interactions.ModifySelect.setActive(this._interactions.Select.getActive());
      this._interactions.Select.on("change:active", (function() {
        this._interactions.ModifySelect.setActive(this._interactions.Select.getActive());
      }).bind(this));
    }
    if (options.interactions.Transform !== false) {
      if (options.interactions.Transform instanceof Transform_default) {
        this._interactions.Transform = options.interactions.Transform;
      } else {
        this._interactions.Transform = new Transform_default({
          select: this._interactions.Select,
          addCondition: shiftKeyOnly
        });
        if (this._interactions.Select) {
          this._interactions.Transform.on("change:active", (function() {
            if (!this._interactions.Select.getActive()) {
              this._interactions.Select.getFeatures().clear();
            }
          }).bind(this));
        }
      }
      var transform = new Toggle_default({
        html: "<i></i>",
        className: "ol-transform",
        title: this._getTitle(options.interactions.Transform) || "Transform",
        name: "Transform",
        interaction: this._interactions.Transform
      });
      this.addControl(transform);
    }
    if (options.interactions.Split !== false) {
      if (options.interactions.Split instanceof Split_default) {
        this._interactions.Split = options.interactions.Split;
      } else {
        this._interactions.Split = new Split_default({
          sources: this._source
        });
      }
      var split = new Toggle_default({
        className: "ol-split",
        title: this._getTitle(options.interactions.Split) || "Split",
        name: "Split",
        interaction: this._interactions.Split
      });
      this.addControl(split);
    }
    if (options.interactions.Offset !== false) {
      if (options.interactions.Offset instanceof Offset_default) {
        this._interactions.Offset = options.interactions.Offset;
      } else {
        this._interactions.Offset = new Offset_default({
          source: this._source
        });
      }
      var offset = new Toggle_default({
        html: "<i></i>",
        className: "ol-offset",
        title: this._getTitle(options.interactions.Offset) || "Offset",
        name: "Offset",
        interaction: this._interactions.Offset
      });
      this.addControl(offset);
    }
  }
};
var EditBar_default = ol_control_EditBar;
export {
  EditBar_default as default
};
//# sourceMappingURL=ol-ext_control_EditBar.js.map
