pwaLUPMIS2/node_modules/.vite/deps/chunk-NNBJMTCH.js
2026-03-04 12:59:40 +01:00

161 lines
4.4 KiB
JavaScript

import {
Button_default
} from "./chunk-VCBXDRBT.js";
// node_modules/ol-ext/control/Toggle.js
var ol_control_Toggle = class olcontrolToggle extends Button_default {
constructor(options) {
options = options || {};
if (options.toggleFn) {
options.onToggle = options.toggleFn;
}
options.handleClick = function() {
self.toggle();
if (options.onToggle) {
options.onToggle.call(self, self.getActive());
}
};
options.className = (options.className || "") + " ol-toggle";
super(options);
var self = this;
this.interaction_ = options.interaction;
if (this.interaction_) {
this.interaction_.setActive(options.active);
this.interaction_.on("change:active", function() {
self.setActive(self.interaction_.getActive());
});
}
this.set("title", options.title);
this.set("autoActivate", options.autoActivate);
if (options.bar) {
this.setSubBar(options.bar);
}
this.setActive(options.active);
this.setDisable(options.disable);
}
/**
* Set the map instance the control is associated with
* and add interaction attached to it to this map.
* @param {_ol_Map_} map The map instance.
*/
setMap(map) {
if (!map && this.getMap()) {
if (this.interaction_) {
this.getMap().removeInteraction(this.interaction_);
}
if (this.subbar_)
this.getMap().removeControl(this.subbar_);
}
super.setMap(map);
if (map) {
if (this.interaction_)
map.addInteraction(this.interaction_);
if (this.subbar_)
map.addControl(this.subbar_);
}
}
/** Get the subbar associated with a control
* @return {ol_control_Bar}
*/
getSubBar() {
return this.subbar_;
}
/** Set the subbar associated with a control
* @param {ol_control_Bar} [bar] a subbar if none remove the current subbar
*/
setSubBar(bar) {
var map = this.getMap();
if (map && this.subbar_) {
map.removeControl(this.subbar_);
}
this.subbar_ = bar;
if (bar) {
this.subbar_.setTarget(this.element);
this.subbar_.element.classList.add("ol-option-bar");
if (map) {
map.addControl(this.subbar_);
}
if (bar.element.id) {
this.getButtonElement().setAttribute("aria-controls", bar.element.id);
bar.element.setAttribute("aria-labelledby", this.getButtonElement().id);
this.on("change:active", (function(e) {
this.getButtonElement().setAttribute("aria-expanded", !!e.active);
}).bind(this));
}
}
}
/**
* Test if the control is disabled.
* @return {bool}
* @api stable
*/
getDisable() {
var button = this.element.querySelector("button");
return button && button.disabled;
}
/** Disable the control. If disable, the control will be deactivated too.
* @param {bool} b disable (or enable) the control, default false (enable)
*/
setDisable(b) {
if (this.getDisable() == b) return;
this.element.querySelector("button").disabled = b;
if (b && this.getActive()) this.setActive(false);
this.dispatchEvent({ type: "change:disable", key: "disable", oldValue: !b, disable: b });
}
/**
* Test if the control is active.
* @return {bool}.
* @api stable
*/
getActive() {
return this.element.classList.contains("ol-active");
}
/** Toggle control state active/deactive
*/
toggle() {
if (this.getActive())
this.setActive(false);
else
this.setActive(true);
}
/** Change control state
* @param {bool} b activate or deactivate the control, default false
*/
setActive(b) {
if (this.interaction_) {
this.interaction_.setActive(b);
}
if (this.subbar_) {
this.subbar_.setActive(b);
}
if (this.getActive() === b) {
return;
}
if (b) {
this.element.classList.add("ol-active");
} else {
this.element.classList.remove("ol-active");
}
this.button_.setAttribute("aria-pressed", b);
this.dispatchEvent({ type: "change:active", key: "active", oldValue: !b, active: b });
}
/** Set the control interaction
* @param {_ol_interaction_} i interaction to associate with the control
*/
setInteraction(i) {
this.interaction_ = i;
}
/** Get the control interaction
* @return {_ol_interaction_} interaction associated with the control
*/
getInteraction() {
return this.interaction_;
}
};
var Toggle_default = ol_control_Toggle;
export {
Toggle_default
};
//# sourceMappingURL=chunk-NNBJMTCH.js.map