import { element_default } from "./chunk-S3QBQTEW.js"; import "./chunk-I4Q72WOW.js"; import { Pointer_default } from "./chunk-RTVPCGIJ.js"; import { Interaction_default } from "./chunk-MSWSBYBR.js"; import "./chunk-QCJTGAWF.js"; import "./chunk-CAVOO5JW.js"; import "./chunk-VRTURNK3.js"; import "./chunk-2C73OZ6M.js"; import "./chunk-M5TTSD4C.js"; import "./chunk-ZCRXKB7J.js"; import "./chunk-RW3V7S4F.js"; import "./chunk-PAB2HIXK.js"; import "./chunk-I6K7MRGV.js"; import "./chunk-PGWX4545.js"; import "./chunk-AYBYZSAV.js"; import "./chunk-YLJGUH5Z.js"; import "./chunk-AZGMK675.js"; import { Overlay_default } from "./chunk-C6SRSVJF.js"; import "./chunk-BHVDQB66.js"; import "./chunk-6EWLK2BW.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 "./chunk-SRXHWJOY.js"; import "./chunk-5RHQVMYD.js"; import "./chunk-DC5AMYBS.js"; // node_modules/ol-ext/interaction/DragOverlay.js var ol_interaction_DragOverlay = class olinteractionDragOverlay extends Pointer_default { constructor(options) { options = options || {}; var offset = options.offset || [0, 0]; var centerOnClick = options.centerOnClick || false; super({ // start draging on an overlay handleDownEvent: function(evt) { var res = evt.frameState.viewState.resolution; var coordinate = [evt.coordinate[0] + offset[0] * res, evt.coordinate[1] - offset[1] * res]; if (/^(BUTTON|A)$/.test(evt.originalEvent.target.tagName)) { this._dragging = false; return true; } if (this._dragging) { if (centerOnClick) { this._dragging.setPosition(coordinate, true); } var coordinateInitial = this._dragging.getPosition(); this._dragging.offsetClick = [coordinate[0] - coordinateInitial[0], coordinate[1] - coordinateInitial[1]]; this.dispatchEvent({ type: "dragstart", overlay: this._dragging, originalEvent: evt.originalEvent, frameState: evt.frameState, coordinate: coordinateInitial }); return true; } return false; }, // Drag handleDragEvent: function(evt) { var res = evt.frameState.viewState.resolution; var coordinate = [evt.coordinate[0] + offset[0] * res, evt.coordinate[1] - offset[1] * res]; if (this._dragging) { coordinate = [coordinate[0] - this._dragging.offsetClick[0], coordinate[1] - this._dragging.offsetClick[1]]; this._dragging.setPosition(coordinate, true); this.dispatchEvent({ type: "dragging", overlay: this._dragging, originalEvent: evt.originalEvent, frameState: evt.frameState, coordinate }); } }, // Stop dragging handleUpEvent: function(evt) { var res = evt.frameState.viewState.resolution; var coordinate = [evt.coordinate[0] + offset[0] * res, evt.coordinate[1] - offset[1] * res]; if (this._dragging) { coordinate = [coordinate[0] - this._dragging.offsetClick[0], coordinate[1] - this._dragging.offsetClick[1]]; this.dispatchEvent({ type: "dragend", overlay: this._dragging, originalEvent: evt.originalEvent, frameState: evt.frameState, coordinate }); this._dragging = false; return true; } return false; } }); this._overlays = []; if (!(options.overlays instanceof Array)) options.overlays = [options.overlays]; options.overlays.forEach(this.addOverlay.bind(this)); } /** Add an overlay to the interacton * @param {ol.Overlay} ov */ addOverlay(ov) { for (var i = 0, o; o = this._overlays[i]; i++) { if (o === ov) return; } var element = ov.getElement(); if (element.parentElement && element.parentElement.classList.contains("ol-overlaycontainer-stopevent")) { console.warn("[DragOverlay.addOverlay] overlay must be created with stopEvent set to false!"); return; } var handler = (function() { if (this.getMap() === ov.getMap()) { this._dragging = ov; } }).bind(this); this._overlays.push({ overlay: ov, listener: handler }); element.parentNode.addEventListener("pointerdown", handler); } /** Remove an overlay from the interacton * @param {ol.Overlay} ov */ removeOverlay(ov) { for (var i = 0, o; o = this._overlays[i]; i++) { if (o.overlay === ov) { var l = this._overlays.splice(i, 1)[0]; ov.getElement().parentNode.removeEventListener("pointerdown", l.listener); break; } } } }; var DragOverlay_default = ol_interaction_DragOverlay; // node_modules/ol-ext/overlay/Fixed.js var ol_Overlay_Fixed = class olOverlayFixed extends Overlay_default { constructor(options) { super(options); } /** Prevent modifying position and use a force argument to force positionning. * @param {ol.coordinate} position * @param {boolean} force true to change the position, default false */ setPosition(position, force) { if (this.getMap() && position) { this._pixel = this.getMap().getPixelFromCoordinate(position); } super.setPosition(position); if (force) { super.updatePixelPosition(); } } /** Update position according the pixel position */ updatePixelPosition() { if (this.getMap() && this._pixel && this.getPosition()) { var pixel = this.getMap().getPixelFromCoordinate(this.getPosition()); if (Math.round(pixel[0] * 1e3) !== Math.round(this._pixel[0] * 1e3) || Math.round(pixel[0] * 1e3) !== Math.round(this._pixel[0] * 1e3)) { this.setPosition(this.getMap().getCoordinateFromPixel(this._pixel)); } } } }; var Fixed_default = ol_Overlay_Fixed; // node_modules/ol-ext/interaction/TouchCursor.js var ol_interaction_TouchCursor = class olinteractionTouchCursor extends DragOverlay_default { constructor(options) { options = options || {}; var overlay = new Fixed_default({ className: ("ol-touch-cursor " + (options.className || "")).trim(), positioning: "top-left", element: element_default.create("DIV", {}), stopEvent: false }); super({ centerOnClick: false, //offset: [-20,-20], overlays: overlay }); this.overlay = overlay; this.setAnchor(options.anchor || "left"); this._listeners = {}; this.ctouch = new Interaction_default({ handleEvent: (function(e) { if (!/drag/.test(e.type) && this.getMap()) { e.coordinate = this.overlay.getPosition(); e.pixel = this.getMap().getPixelFromCoordinate(e.coordinate); this._lastEvent = e; } else { var res = e.frameState.viewState.resolution; var cosa = Math.cos(e.frameState.viewState.rotation); var sina = Math.sin(e.frameState.viewState.rotation); var width = this.getOverlayElement().clientWidth / 2; var style = getComputedStyle(this.getOverlayElement()); var offset = [-width - parseInt(style.marginLeft), -width - parseInt(style.marginTop)]; if (this._anchor === "center") offset[0] = 0; e.coordinate = [ e.coordinate[0] + cosa * offset[0] * res + sina * offset[1] * res, e.coordinate[1] + sina * offset[0] * res - cosa * offset[1] * res ]; e.pixel = this.getMap().getPixelFromCoordinate(e.coordinate); } return true; }).bind(this) }); this.ctouch.set("onTop", true); this.setPosition(options.coordinate, true); this.set("maxButtons", options.maxButtons || 5); if (options.buttons) { if (options.buttons.length > this.get("maxButtons")) { this.set("maxButtons", options.buttons.length); } var elt = this.overlay.element; var begin = options.buttons.length > 4 ? 0 : 1; options.buttons.forEach((function(b, i) { if (i < 5) { element_default.create("DIV", { className: ((b.className || "") + " ol-button ol-button-" + (i + begin)).trim(), html: element_default.create("DIV", { html: b.html }), click: b.click, on: b.on, parent: elt }); } })); } var dragging = false; var start = false; this.on("dragstart", function(e) { this._pixel = this.getMap().getPixelFromCoordinate(this.overlay.getPosition()); start = e; return !e.overlay; }); this.on("dragend", (function(e) { this._pixel = this.getMap().getPixelFromCoordinate(this.overlay.getPosition()); if (!e.overlay) return true; if (dragging) { this.dispatchEvent({ type: "dragend", dragging, originalEvent: e.originalEvent, frameState: e.frameState, pixel: this._pixel, coordinate: this.overlay.getPosition() }); dragging = false; } else { if (e.originalEvent.target === this.overlay.element) { this.dispatchEvent({ type: "click", dragging, originalEvent: e.originalEvent, frameState: e.frameState, pixel: this._pixel, coordinate: this.overlay.getPosition() }); } } return false; }).bind(this)); this.on("dragging", (function(e) { this._pixel = this.getMap().getPixelFromCoordinate(this.overlay.getPosition()); if (!e.overlay) { return true; } dragging = true; if (start) { this.dispatchEvent({ type: "dragstart", dragging, originalEvent: start.originalEvent, frameState: e.frameState, pixel: this._pixel, coordinate: start.coordinate }); start = false; } this.dispatchEvent({ type: "dragging", dragging, originalEvent: e.originalEvent, frameState: e.frameState, pixel: this._pixel, coordinate: this.overlay.getPosition() }); return false; }).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.ctouch); if (this.getActive()) this.getMap().removeOverlay(this.overlay); } for (let l in this._listeners) { unByKey(this._listeners[l]); } this._listeners = {}; super.setMap(map); if (map) { if (this.getActive()) { map.addOverlay(this.overlay); setTimeout((function() { this.setPosition(this.getPosition() || map.getView().getCenter()); }).bind(this)); } map.addInteraction(this.ctouch); this._listeners.addInteraction = map.getInteractions().on("add", (function(e) { if (!e.element.get("onTop")) { map.removeInteraction(this.ctouch); map.addInteraction(this.ctouch); } }).bind(this)); } } /** Set anchor position * @param {string} pos "left", "center" or "right" * @api */ setAnchor(pos) { var positions = ["left", "right", "center"]; if (positions.indexOf(pos) >= 0) { positions.forEach((function(k) { this.getOverlayElement().classList.remove("ol-touch-cursor-" + k); }).bind(this)); this.getOverlayElement().classList.add("ol-touch-cursor-" + pos); this._anchor = pos; } } /** * Activate or deactivate the interaction. * @param {boolean} active Active. * @param {ol.coordinate|null} position position of the cursor (when activating), default viewport center. * @observable * @api */ setActive(b, position) { if (b !== this.getActive()) { if (this.ctouch) this.ctouch.setActive(b); if (!b) { this.setPosition(); this.overlay.element.classList.remove("active"); if (this._activate) clearTimeout(this._activate); if (this.getMap()) this.getMap().removeOverlay(this.overlay); } else { if (this.getMap()) { this.getMap().addOverlay(this.overlay); } if (position) { this.setPosition(position); } else if (this.getMap()) { this.setPosition(this.getMap().getView().getCenter()); } this._activate = setTimeout((function() { this.overlay.element.classList.add("active"); }).bind(this), 100); } super.setActive(b); } else if (position) { this.setPosition(position); } else if (this.getMap()) { this.setPosition(this.getMap().getView().getCenter()); } } /** Set the position of the target * @param {ol.coordinate} coord */ setPosition(coord) { this.overlay.setPosition(coord, true); if (this.getMap() && coord) { this._pixel = this.getMap().getPixelFromCoordinate(coord); } } /** Offset the target position * @param {ol.coordinate} coord */ offsetPosition(coord) { var pos = this.overlay.getPosition(); if (pos) { this.overlay.setPosition([pos[0] + coord[0], pos[1] + coord[1]]); } } /** Get the position of the target * @return {ol.coordinate} */ getPosition() { return this.overlay.getPosition(); } /** Get pixel position * @return {ol.pixel} */ getPixel() { if (this.getMap()) { return this.getMap().getPixelFromCoordinate(this.getPosition()); } } /** Get cursor overlay * @return {ol.Overlay} */ getOverlay() { return this.overlay; } /** Get cursor overlay element * @return {Element} */ getOverlayElement() { return this.overlay.element; } /** Get cursor button element * @param {string|number} button the button className or the button index * @return {Element} */ getButtonElement(button) { if (typeof button === "number") return this.getOverlayElement().getElementsByClassName("ol-button")[button]; return this.getOverlayElement().getElementsByClassName(button)[0]; } /** Remove a button element * @param {string|number|undefined} button the button className or the button index, if undefined remove all buttons, default remove all * @return {Element} */ removeButton(button) { if (button === void 0) { var buttons = this.getOverlayElement().getElementsByClassName("ol-button"); for (var i = buttons.length - 1; i >= 0; i--) { this.getOverlayElement().removeChild(buttons[i]); } } else { var elt = this.getButtonElement(button); if (elt) this.getOverlayElement().removeChild(elt); } } /** Add a button element * @param {*} button * @param {string} options.className button class name * @param {DOMElement|string} options.html button content * @param {function} options.click onclick function * @param {*} options.on an object with * @param {boolean} options.before */ addButton(b) { var buttons = this.getOverlayElement().getElementsByClassName("ol-button"); var max = this.get("maxButtons") || 5; if (buttons.length >= max) { console.error("[ol/interaction/TouchCursor~addButton] too many button on the cursor (max=" + max + ")..."); return; } var button = element_default.create("DIV", { className: ((b.className || "") + " ol-button").trim(), html: element_default.create("DIV", { html: b.html }), click: b.click, on: b.on }); if (!b.before || buttons.length === 0) { this.getOverlayElement().appendChild(button); } else { this.getOverlayElement().insertBefore(button, buttons[0]); } var start = buttons.length >= max ? 0 : 1; for (let i = 0; i < buttons.length; i++) { buttons[i].className = buttons[i].className.replace(/ol-button-\d/g, "").trim() + " ol-button-" + (i + start); } } }; var TouchCursor_default = ol_interaction_TouchCursor; export { TouchCursor_default as default }; //# sourceMappingURL=ol-ext_interaction_TouchCursor.js.map