UNPKG

gisviewer-vue3-arcgis

Version:

在应用中引入私服的包, 项目根目录下 新建文件 .npmrc 在 .npmrc 中对包源进行配置:

207 lines (206 loc) 5.36 kB
import h from "ol/style/Circle"; import p from "ol/style/Fill"; import M from "ol/style/Icon"; import u from "ol/style/RegularShape"; import d from "ol/style/Stroke"; import f from "ol/style/Style"; import P from "ol/style/Text"; const c = /* @__PURE__ */ new Map(); let w = null; function U(e, t) { return e ? Array.isArray(e) ? e.map((a) => { if (a.type === "text" && a.field) { const n = (t == null ? void 0 : t[a.field]) ?? ""; return JSON.stringify({ ...a, __textContent__: n }); } return JSON.stringify(a); }).join("|") : JSON.stringify(e) : "__default__"; } function k() { return w || (w = new f({ image: new h({ radius: 6, fill: new p({ color: "#2563eb" }), stroke: new d({ color: "#ffffff", width: 1.5 }) }) })), w; } function S(e) { const t = new M({ src: e.url, scale: e.scale ?? 1, anchor: e.anchor ?? [0.5, 0.5], anchorXUnits: e.anchorXUnits ?? "fraction", anchorYUnits: e.anchorYUnits ?? "fraction", rotation: e.rotation ?? 0 }); return new f({ image: t }); } function x(e) { const t = new h({ radius: e.radius ?? 6, fill: new p({ color: e.fillColor ?? "#2563eb" }), stroke: new d({ color: e.strokeColor ?? "#ffffff", width: e.strokeWidth ?? 1.5 }) }); return new f({ image: t }); } function C(e) { const t = new u({ points: e.points ?? 4, radius: e.radius ?? 10, radius2: e.radius2, angle: e.angle ?? 0, rotation: e.rotation ?? 0, fill: e.fillColor ? new p({ color: e.fillColor }) : void 0, stroke: new d({ color: e.strokeColor ?? "#000000", width: e.strokeWidth ?? 1 }) }); return new f({ image: t }); } function _(e) { const t = e.width != null || e.height != null, i = { src: e.url, anchor: e.anchor ?? [0.5, 0.5], anchorXUnits: "fraction", anchorYUnits: "fraction", rotation: (e.angle ?? 0) * Math.PI / 180, // ArcGIS angle 是角度,转换为弧度 displacement: [e.xoffset ?? 0, -(e.yoffset ?? 0)] // yoffset 取反以匹配 ArcGIS 方向 }; t ? (e.width != null && (i.width = e.width), e.height != null && (i.height = e.height)) : e.scale != null && (i.scale = e.scale); const a = new M(i); return new f({ image: a }); } function A(e) { var s, g; const t = e.size ?? 12, i = e.color ?? [0, 0, 0, 1], a = ((s = e.outline) == null ? void 0 : s.color) ?? [255, 255, 255, 1], n = ((g = e.outline) == null ? void 0 : g.width) ?? 1, o = new p({ color: i }), r = new d({ color: a, width: n }); let l; switch (e.style) { case "circle": l = new h({ radius: t / 2, fill: o, stroke: r }); break; case "square": l = new u({ points: 4, radius: t / 2, angle: Math.PI / 4, // 旋转45度使其成为正方形 fill: o, stroke: r }); break; case "diamond": l = new u({ points: 4, radius: t / 2, angle: 0, // 不旋转,呈菱形 fill: o, stroke: r }); break; case "triangle": l = new u({ points: 3, radius: t / 2, angle: 0, fill: o, stroke: r }); break; case "cross": l = new u({ points: 4, radius: t / 2, radius2: 0, angle: 0, stroke: r }); break; case "x": l = new u({ points: 4, radius: t / 2, radius2: 0, angle: Math.PI / 4, // 旋转45度成为 X stroke: r }); break; case "path": l = new h({ radius: t / 2, fill: o, stroke: r }); break; default: l = new h({ radius: t / 2, fill: o, stroke: r }); break; } return new f({ image: l }); } function I(e, t) { const i = new P({ text: String(t), font: e.font ?? "14px Arial Unicode MS", fill: new p({ color: e.fillColor ?? [0, 0, 0] }), stroke: new d({ 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" }); return new f({ text: i }); } function B(e, t) { if (!e) return k(); const i = U(e, t), a = c.get(i); if (a) return a; let n; if (Array.isArray(e) && e.length > 0) { const o = []; if (e.forEach((r) => { if (r.type === "icon" && r.url) o.push(S(r)); else if (r.type === "picture-marker" && r.url) o.push(_(r)); else if (r.type === "simple-marker") o.push(A(r)); else if (r.type === "circle") o.push(x(r)); else if (r.type === "shape") o.push(C(r)); else if (r.type === "text" && r.field) { const l = (t == null ? void 0 : t[r.field]) ?? ""; l && o.push(I(r, l)); } }), o.length > 0) return n = o, c.set(i, n), n; } return e && e.url ? (n = S(e), c.set(i, n), n) : e && e.type === "picture-marker" && e.url ? (n = _(e), c.set(i, n), n) : e && e.type === "simple-marker" ? (n = A(e), c.set(i, n), n) : e && e.type === "circle" ? (n = x(e), c.set(i, n), n) : e && e.type === "shape" ? (n = C(e), c.set(i, n), n) : k(); } export { B as getPointStyle };