maplibre-gl-opacity
Version:
maplibre-gl-opacity is a MapLibre GL JS plugin that makes multiple tile layers transparent.
76 lines (75 loc) • 3.62 kB
JavaScript
var L = (n) => {
throw TypeError(n);
};
var b = (n, t, i) => t.has(n) || L("Cannot " + i);
var e = (n, t, i) => (b(n, t, "read from private field"), i ? i.call(n) : t.get(n)), d = (n, t, i) => t.has(n) ? L("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(n) : t.set(n, i), p = (n, t, i, s) => (b(n, t, "write to private field"), s ? s.call(n, i) : t.set(n, i), i), m = (n, t, i) => (b(n, t, "access private method"), i);
const v = {
baseLayers: {},
overLayers: {},
opacityControl: !1
};
var r, o, a, h, u, c, g, E, f, k;
class P {
constructor(t) {
d(this, c);
d(this, r);
d(this, o);
d(this, a);
d(this, h);
d(this, u);
p(this, a, t.baseLayers ?? v.baseLayers), p(this, h, t.overLayers ?? v.overLayers), p(this, u, t.opacityControl ?? v.opacityControl);
}
onAdd(t) {
return p(this, r, t), m(this, c, k).call(this), e(this, o);
}
onRemove() {
e(this, o).parentNode.removeChild(e(this, o)), p(this, r, void 0);
}
}
r = new WeakMap(), o = new WeakMap(), a = new WeakMap(), h = new WeakMap(), u = new WeakMap(), c = new WeakSet(), // ラジオボタン作成
g = function(t) {
const i = Object.keys(e(this, a))[0], s = document.createElement("input");
s.setAttribute("type", "radio"), s.id = t, t === i ? (s.checked = !0, e(this, r).setLayoutProperty(t, "visibility", "visible")) : e(this, r).setLayoutProperty(t, "visibility", "none"), e(this, o).appendChild(s), s.addEventListener("change", (C) => {
C.target.checked = !0, e(this, r).setLayoutProperty(t, "visibility", "visible"), Object.keys(e(this, a)).map((y) => {
y !== C.target.id && (document.getElementById(y).checked = !1, e(this, r).setLayoutProperty(y, "visibility", "none"));
});
});
const l = document.createElement("label");
l.htmlFor = t, l.appendChild(document.createTextNode(e(this, a)[t])), e(this, o).appendChild(l);
}, // チェックボックス作成
E = function(t) {
const i = document.createElement("input");
i.setAttribute("type", "checkbox"), i.id = t, e(this, r).setLayoutProperty(t, "visibility", "none"), e(this, o).appendChild(i), i.addEventListener("change", (l) => {
l.target.checked ? e(this, r).setLayoutProperty(t, "visibility", "visible") : e(this, r).setLayoutProperty(t, "visibility", "none");
});
const s = document.createElement("label");
s.htmlFor = t, s.appendChild(document.createTextNode(e(this, h)[t])), e(this, o).appendChild(s);
}, // スライドバー作成
f = function(t) {
const i = document.createElement("input");
i.type = "range", i.min = String(0), i.max = String(100), i.value = String(100), e(this, o).appendChild(i), i.addEventListener("input", (s) => {
e(this, r).setPaintProperty(
t,
"raster-opacity",
// @ts-ignore
Number(s.target.value / 100)
);
});
}, // コントロール作成
k = function() {
if (p(this, o, document.createElement("div")), e(this, o).className = "maplibregl-ctrl maplibregl-ctrl-group", e(this, o).id = "opacity-control", e(this, a) && Object.keys(e(this, a)).map((t) => {
const i = t, s = document.createElement("br");
m(this, c, g).call(this, i), e(this, o).appendChild(s);
}), e(this, a) && e(this, h)) {
const t = document.createElement("hr");
e(this, o).appendChild(t);
}
e(this, h) && Object.keys(e(this, h)).map((t) => {
const i = t, s = document.createElement("br");
m(this, c, E).call(this, i), e(this, o).appendChild(s), e(this, u) && (m(this, c, f).call(this, i), e(this, o).appendChild(s));
});
};
export {
P as default
};
//# sourceMappingURL=maplibre-gl-opacity.mjs.map