gisviewer-vue3-arcgis
Version:
在应用中引入私服的包, 项目根目录下 新建文件 .npmrc 在 .npmrc 中对包源进行配置:
191 lines (190 loc) • 5.19 kB
JavaScript
import a from "ol/style/Fill";
import u from "ol/style/Stroke";
import d from "ol/style/Style";
import v from "ol/style/Text";
import { getLineDashByStyle as x } from "./line-style.mjs";
const f = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map();
let p = null;
function J(e, n) {
return e ? Array.isArray(e) ? e.map((l) => {
if (l.type === "text" && l.field) {
const c = (n == null ? void 0 : n[l.field]) ?? "";
return JSON.stringify({ ...l, __textContent__: c });
}
return JSON.stringify(l);
}).join("|") : JSON.stringify(e) : "__default__";
}
function w() {
return p || (p = new d({
fill: new a({
color: "rgba(37, 99, 235, 0.3)"
}),
stroke: new u({
color: "#2563eb",
width: 2
})
})), p;
}
function g(e) {
return new d({
fill: e.fillColor ? new a({ color: e.fillColor }) : void 0,
stroke: new u({
color: e.strokeColor ?? "#2563eb",
width: e.strokeWidth ?? 2,
lineCap: e.lineCap ?? "round",
lineJoin: e.lineJoin ?? "round",
lineDash: e.lineDash,
lineDashOffset: e.lineDashOffset ?? 0
})
});
}
function O(e, n) {
switch (e) {
case "solid":
return new a({ color: n ?? [0, 0, 0, 0.5] });
case "none":
case "null":
return;
case "horizontal":
case "vertical":
case "cross":
case "forward-diagonal":
case "backward-diagonal":
case "diagonal-cross":
return new a({ color: n ?? [0, 0, 0, 0.3] });
default:
return new a({ color: n ?? [0, 0, 0, 0.5] });
}
}
function S(e) {
const n = e.style ?? "solid", r = O(n, e.color);
let l;
if (e.outline) {
const c = e.outline.width ?? 1, t = e.outline.style ?? "solid", i = x(t, c);
l = new u({
color: e.outline.color ?? [0, 0, 0, 1],
width: c,
lineCap: e.outline.cap ?? "round",
lineJoin: e.outline.join ?? "round",
lineDash: i
});
}
return new d({
fill: r,
stroke: l
});
}
function A(e, n) {
const r = e.width ?? 32, l = e.height ?? 32, c = `${e.url}|${r}|${l}`;
let t = s.get(c);
if (t != null && t.pattern)
return t.pattern;
if (t) {
n && t.callbacks.add(n);
return;
}
t = { callbacks: /* @__PURE__ */ new Set() }, n && t.callbacks.add(n), s.set(c, t);
const i = new Image();
i.crossOrigin = "anonymous", i.onload = () => {
const o = document.createElement("canvas");
o.width = r, o.height = l;
const h = o.getContext("2d");
h && (h.drawImage(i, 0, 0, r, l), t.pattern = h.createPattern(o, "repeat") ?? void 0), W(), t.callbacks.forEach((D) => D()), t.callbacks.clear();
}, i.onerror = () => {
t.callbacks.clear();
}, i.src = e.url;
}
function k(e, n) {
const r = A(e, n), l = new a({
color: r ?? e.color ?? "rgba(128, 128, 128, 0.3)"
});
let c;
if (e.outline) {
const t = e.outline.width ?? 1, i = e.outline.style ?? "solid", o = x(i, t);
c = new u({
color: e.outline.color ?? [0, 0, 0, 1],
width: t,
lineDash: o
});
}
return new d({
fill: l,
stroke: c
});
}
function C(e) {
const n = new d({
stroke: new u({
color: e.borderColor ?? "#000000",
width: (e.strokeWidth ?? 2) + (e.borderWidth ?? 2) * 2,
lineCap: e.lineCap ?? "round",
lineJoin: e.lineJoin ?? "round",
lineDash: e.lineDash,
lineDashOffset: e.lineDashOffset ?? 0
})
}), r = new d({
fill: e.fillColor ? new a({ color: e.fillColor }) : void 0,
stroke: new u({
color: e.strokeColor ?? "#2563eb",
width: e.strokeWidth ?? 2,
lineCap: e.lineCap ?? "round",
lineJoin: e.lineJoin ?? "round",
lineDash: e.lineDash,
lineDashOffset: e.lineDashOffset ?? 0
})
});
return [n, r];
}
function _(e, n) {
const r = new v({
text: String(n),
font: e.font ?? "14px Arial Unicode MS",
fill: new a({
color: e.fillColor ?? [0, 0, 0]
}),
stroke: new u({
color: e.strokeColor ?? [255, 255, 255],
width: e.strokeWidth ?? 3
}),
offsetX: e.offsetX ?? 0,
offsetY: e.offsetY ?? 0,
textAlign: e.textAlign ?? "center",
textBaseline: e.textBaseline ?? "middle",
overflow: e.overflow ?? !1
});
return new d({ text: r });
}
function W() {
f.clear();
}
function M(e, n, r) {
if (!e)
return w();
const l = J(e, n), c = f.get(l);
if (c)
return c;
let t;
if (Array.isArray(e) && e.length > 0) {
const i = [];
if (e.forEach((o) => {
if (o.type === "polygon")
i.push(g(o));
else if (o.type === "simple-fill")
i.push(S(o));
else if (o.type === "picture-fill")
i.push(k(o, r));
else if (o.type === "bordered")
i.push(...C(o));
else if (o.type === "text" && o.field) {
const h = (n == null ? void 0 : n[o.field]) ?? "";
h && i.push(_(o, h));
}
}), i.length > 0)
return t = i, f.set(l, t), t;
}
return e && e.type === "bordered" ? (t = C(e), f.set(l, t), t) : e && e.type === "simple-fill" ? (t = S(e), f.set(l, t), t) : e && e.type === "picture-fill" ? (t = k(e, r), f.set(l, t), t) : e ? (t = g(e), f.set(l, t), t) : w();
}
export {
W as clearStyleCache,
M as getPolygonStyle
};