@3clear/basegis 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,690 @@
1
+ import k from "leaflet";
2
+ import { P as A, C as E, S as D, T as V, a as j, l as L } from "./pixi-vendor-BFDHT3Bf.js";
3
+ let C = null;
4
+ function u(h, t = 0) {
5
+ const e = Number(h);
6
+ return Number.isFinite(e) ? e : t;
7
+ }
8
+ function b(h, t = []) {
9
+ var e, i, r;
10
+ for (let s = 0; s < t.length; s += 1) {
11
+ const l = t[s];
12
+ if ((h == null ? void 0 : h[l]) !== void 0 && (h == null ? void 0 : h[l]) !== null && (h == null ? void 0 : h[l]) !== "")
13
+ return h[l];
14
+ if (((e = h == null ? void 0 : h.properties) == null ? void 0 : e[l]) !== void 0 && ((i = h == null ? void 0 : h.properties) == null ? void 0 : i[l]) !== null && ((r = h == null ? void 0 : h.properties) == null ? void 0 : r[l]) !== "")
15
+ return h.properties[l];
16
+ }
17
+ }
18
+ function W(h) {
19
+ var t;
20
+ return Array.isArray(h) ? h : Array.isArray(h == null ? void 0 : h.coordinates) ? h.coordinates : Array.isArray(h == null ? void 0 : h.position) ? h.position : Array.isArray((t = h == null ? void 0 : h.geometry) == null ? void 0 : t.coordinates) ? h.geometry.coordinates : null;
21
+ }
22
+ function U(h) {
23
+ return Array.isArray(h) ? h : Array.isArray(h == null ? void 0 : h.features) ? h.features : [];
24
+ }
25
+ function v(h, t) {
26
+ return String(h ?? t);
27
+ }
28
+ function x(h) {
29
+ return String(h ?? "").replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
30
+ }
31
+ function f(h) {
32
+ return Object.prototype.toString.call(h) === "[object Object]";
33
+ }
34
+ function S(h) {
35
+ return typeof window < "u" && typeof window.requestAnimationFrame == "function" ? window.requestAnimationFrame(h) : setTimeout(h, 16);
36
+ }
37
+ function F(h) {
38
+ if (h) {
39
+ if (typeof window < "u" && typeof window.cancelAnimationFrame == "function") {
40
+ window.cancelAnimationFrame(h);
41
+ return;
42
+ }
43
+ clearTimeout(h);
44
+ }
45
+ }
46
+ function $() {
47
+ return k.pixiOverlay ? Promise.resolve() : (C || (typeof window < "u" && (window.PIXI = L), C = import("./leaflet-pixi-overlay-BSJNo_DO.js").then((h) => h.L).then(() => {
48
+ })), C);
49
+ }
50
+ function z(h, t = []) {
51
+ return t.some((e) => Object.prototype.hasOwnProperty.call(h, e));
52
+ }
53
+ function q(h = {}) {
54
+ const {
55
+ field: t,
56
+ key: e,
57
+ operator: i,
58
+ op: r,
59
+ value: s,
60
+ compareValue: l,
61
+ values: o,
62
+ min: a,
63
+ max: n,
64
+ gt: d,
65
+ gte: c,
66
+ lt: g,
67
+ lte: p,
68
+ when: m,
69
+ default: y,
70
+ style: w,
71
+ highlightStyle: I,
72
+ ..._
73
+ } = h;
74
+ return _;
75
+ }
76
+ class G {
77
+ constructor(t, e = {}) {
78
+ this.map = t, this.layerId = e.layerId || e.id || `point-large-${Date.now()}`, this.points = [], this.records = [], this.sprites = [], this.renderedCount = 0, this.visible = e.visible !== !1, this.destroyed = !1, this.defaultImage = null, this.defaultHighlightImage = null, this._pixiContainer = null, this._pixiOverlay = null, this._textureByImage = /* @__PURE__ */ new Map(), this._spriteById = /* @__PURE__ */ new Map(), this._recordById = /* @__PURE__ */ new Map(), this._tooltip = null, this._tooltipRecordKey = "", this._highlightedKey = "", this._hoveredKey = "", this._moveTimer = null, this._lastMove = null, this._buildTimer = null, this._buildVersion = 0, this._isBuilding = !1, this._needsBuild = !1, this._ready = !1, this._latestInvScale = 1, this._previousCursor = "", this._eventsBound = !1, this._boundMouseMove = (s) => this.scheduleHoverPick(s), this._boundMouseOut = () => {
79
+ this.handleHoverOut(), this.hideTooltip(), this.restoreCursor();
80
+ }, this._boundClick = (s) => this.handleClick(s), this.options = this.normalizeOptions(e), this._readyPromise = $().then(() => {
81
+ this._ready = !0, !this.destroyed && (this.bindEvents(), this._needsBuild && (this._needsBuild = !1, this.rebuildSprites()));
82
+ }).catch((s) => {
83
+ console.warn("[PointLargeLayer] Leaflet.PixiOverlay 加载失败。", s);
84
+ });
85
+ const i = z(e, ["points", "data", "items"]), r = e.points || e.data || e.items;
86
+ i ? this.setData(r) : this.bindEvents();
87
+ }
88
+ normalizeOptions(t = {}) {
89
+ return {
90
+ longitudeKeys: t.longitudeKeys || ["longitude", "lon", "lng", "x"],
91
+ latitudeKeys: t.latitudeKeys || ["latitude", "lat", "y"],
92
+ heightKeys: t.heightKeys || ["height", "altitude", "z"],
93
+ idKey: t.idKey || "id",
94
+ image: t.image || t.icon || t.iconUrl || t.imageUrl || "",
95
+ highlightImage: t.highlightImage || t.highlightIcon || t.highlightIconUrl || t.highlightImageUrl || "",
96
+ imageCallback: typeof t.imageCallback == "function" ? t.imageCallback : null,
97
+ styleCallback: typeof t.styleCallback == "function" ? t.styleCallback : null,
98
+ highlightStyleCallback: typeof t.highlightStyleCallback == "function" ? t.highlightStyleCallback : null,
99
+ styleField: t.styleField || t.valueKey || "value",
100
+ styleRules: Array.isArray(t.styleRules) ? t.styleRules : [],
101
+ width: Math.max(u(t.width, 32), 1),
102
+ height: Math.max(u(t.height, 32), 1),
103
+ scale: Math.max(u(t.scale, 1), 0.01),
104
+ color: t.color || "#1e88e5",
105
+ outlineColor: t.outlineColor || "#ffffff",
106
+ outlineWidth: Math.max(u(t.outlineWidth, 2), 0),
107
+ highlightColor: t.highlightColor || "#ffcc00",
108
+ highlightOutlineColor: t.highlightOutlineColor || "#ffffff",
109
+ highlightOutlineWidth: Math.max(u(t.highlightOutlineWidth, 3), 0),
110
+ highlightWidth: Math.max(u(t.highlightWidth, t.width || 36), 1),
111
+ highlightHeight: Math.max(u(t.highlightHeight, t.height || 36), 1),
112
+ highlightScale: Math.max(
113
+ u(t.highlightScale, Math.max(u(t.scale, 1), 0.01) * 1.35),
114
+ 0.01
115
+ ),
116
+ clampToGround: !!t.clampToGround,
117
+ disableDepthTestDistance: u(
118
+ t.disableDepthTestDistance,
119
+ Number.POSITIVE_INFINITY
120
+ ),
121
+ pixelOffset: t.pixelOffset || null,
122
+ eyeOffset: t.eyeOffset || null,
123
+ scaleByDistance: t.scaleByDistance || null,
124
+ translucencyByDistance: t.translucencyByDistance || null,
125
+ distanceDisplayCondition: t.distanceDisplayCondition || null,
126
+ keepSize: t.keepSize !== !1,
127
+ pickRadius: Math.max(u(t.pickRadius, 10), 1),
128
+ chunkSize: Math.max(u(t.chunkSize, 5e3), 0),
129
+ chunkFrameBudget: Math.max(u(t.chunkFrameBudget, 10), 1),
130
+ // ParticleContainer 速度更快,但只适合单纹理或少量静态属性;
131
+ // 默认使用普通 Container,保证单点 icon / highlightIcon 条件样式与 Cesium 行为一致。
132
+ useParticleContainer: t.useParticleContainer === !0,
133
+ showTooltip: t.showTooltip !== !1,
134
+ tooltipClassName: t.tooltipClassName || "leaflet-point-large-tooltip",
135
+ tooltipOffset: t.tooltipOffset || [14, 14],
136
+ tooltipFormatter: typeof t.tooltipFormatter == "function" ? t.tooltipFormatter : null,
137
+ cursor: t.cursor || "pointer",
138
+ onClick: typeof t.onClick == "function" ? t.onClick : null,
139
+ onHover: typeof t.onHover == "function" ? t.onHover : null,
140
+ onHoverIn: typeof t.onHoverIn == "function" ? t.onHoverIn : null,
141
+ onHoverOut: typeof t.onHoverOut == "function" ? t.onHoverOut : null,
142
+ pixiOptions: f(t.pixiOptions) ? t.pixiOptions : {}
143
+ };
144
+ }
145
+ update(t = {}) {
146
+ const e = Array.isArray(t) || Array.isArray(t == null ? void 0 : t.features) ? { points: t } : t || {}, i = {
147
+ ...this.options,
148
+ ...e
149
+ };
150
+ [
151
+ "color",
152
+ "outlineColor",
153
+ "outlineWidth",
154
+ "highlightColor",
155
+ "highlightOutlineColor",
156
+ "highlightOutlineWidth"
157
+ ].some((o) => Object.prototype.hasOwnProperty.call(e, o)) && (this.defaultImage = null, this.defaultHighlightImage = null), this.options = this.normalizeOptions(i), "visible" in e && this.setVisible(e.visible);
158
+ const s = z(e, ["points", "data", "items"]), l = e.points || e.data || e.items;
159
+ s ? this.setData(l) : this.shouldRenormalizeByOptions(e) ? (this.records = this.normalizePoints(this.points), this.rebuildSprites()) : this.shouldRebuildByOptions(e) ? this.rebuildSprites() : this.shouldRestyleByOptions(e) && this.restyleSprites(), Object.prototype.hasOwnProperty.call(e, "highlightId") && this.setHighlight(e.highlightId), this.bindEvents(), Object.prototype.hasOwnProperty.call(e, "showTooltip") && !e.showTooltip && this.hideTooltip(), this.redraw();
160
+ }
161
+ shouldRenormalizeByOptions(t = {}) {
162
+ return [
163
+ "longitudeKeys",
164
+ "latitudeKeys",
165
+ "heightKeys",
166
+ "idKey"
167
+ ].some((e) => Object.prototype.hasOwnProperty.call(t, e));
168
+ }
169
+ shouldRebuildByOptions(t = {}) {
170
+ return [
171
+ "chunkSize",
172
+ "chunkFrameBudget",
173
+ "useParticleContainer",
174
+ "pixiOptions"
175
+ ].some((e) => Object.prototype.hasOwnProperty.call(t, e));
176
+ }
177
+ shouldRestyleByOptions(t = {}) {
178
+ return [
179
+ "image",
180
+ "highlightImage",
181
+ "width",
182
+ "height",
183
+ "scale",
184
+ "color",
185
+ "outlineColor",
186
+ "outlineWidth",
187
+ "highlightColor",
188
+ "highlightOutlineColor",
189
+ "highlightOutlineWidth",
190
+ "highlightWidth",
191
+ "highlightHeight",
192
+ "highlightScale",
193
+ "styleField",
194
+ "valueKey",
195
+ "styleRules",
196
+ "keepSize",
197
+ "pickRadius",
198
+ "imageCallback",
199
+ "styleCallback",
200
+ "highlightStyleCallback"
201
+ ].some((e) => Object.prototype.hasOwnProperty.call(t, e));
202
+ }
203
+ setData(t = []) {
204
+ this.points = U(t), this.records = this.normalizePoints(this.points), this.rebuildSprites();
205
+ }
206
+ normalizePoints(t = []) {
207
+ var i;
208
+ const e = [];
209
+ for (let r = 0; r < t.length; r += 1) {
210
+ const s = t[r], l = W(s), o = Number(l ? l[0] : b(s, this.options.longitudeKeys)), a = Number(l ? l[1] : b(s, this.options.latitudeKeys)), n = u(l ? l[2] : b(s, this.options.heightKeys), 0);
211
+ if (!Number.isFinite(o) || !Number.isFinite(a))
212
+ continue;
213
+ const d = (s == null ? void 0 : s[this.options.idKey]) ?? ((i = s == null ? void 0 : s.properties) == null ? void 0 : i[this.options.idKey]) ?? r, c = v(d, r);
214
+ e.push({
215
+ raw: s,
216
+ id: d,
217
+ key: c,
218
+ index: r,
219
+ longitude: o,
220
+ latitude: a,
221
+ height: n,
222
+ sprite: null,
223
+ pickRadius: this.options.pickRadius
224
+ });
225
+ }
226
+ return e;
227
+ }
228
+ rebuildSprites() {
229
+ if (this.destroyed || !this.map)
230
+ return;
231
+ if (!this._ready || !k.pixiOverlay) {
232
+ this._needsBuild = !0;
233
+ return;
234
+ }
235
+ this.cancelBuild(), this.destroyPixiObjects(), this.renderedCount = 0, this._spriteById.clear(), this._recordById.clear();
236
+ const t = this._buildVersion + 1;
237
+ this._buildVersion = t, this._isBuilding = !0, this._pixiContainer = this.createPixiContainer(this.records.length), this._pixiContainer.visible = this.visible;
238
+ let e = !1, i = 0;
239
+ this._pixiOverlay = k.pixiOverlay((r, s = {}) => {
240
+ const l = r.getContainer(), o = r.getRenderer(), a = s == null ? void 0 : s.zoom, n = this.options.keepSize ? 1 / r.getScale(a) : 1, d = Math.abs(n - this._latestInvScale) > 1e-6;
241
+ this._latestInvScale = n, !e && s.type === "add" && (e = !0, this.scheduleBuildChunks({
242
+ version: t,
243
+ project: r.latLngToLayerPoint,
244
+ getBuildIndex: () => i,
245
+ setBuildIndex: (c) => {
246
+ i = c;
247
+ }
248
+ })), d && this.updateSpriteScales(), o.render(l);
249
+ }, this._pixiContainer, {
250
+ destroyInteractionManager: !0,
251
+ ...this.options.pixiOptions
252
+ }), this._pixiOverlay.addTo(this.map), this.bindEvents();
253
+ }
254
+ createPixiContainer(t) {
255
+ return this.options.useParticleContainer && A ? new A(Math.max(t, 1), {
256
+ // 这些属性会随 hover、缩放和样式更新变化,必须让 ParticleContainer 参与同步。
257
+ vertices: !0,
258
+ position: !0,
259
+ rotation: !1,
260
+ uvs: !0,
261
+ tint: !0,
262
+ alpha: !0
263
+ }) : new E();
264
+ }
265
+ scheduleBuildChunks({ version: t, project: e, getBuildIndex: i, setBuildIndex: r }) {
266
+ const s = () => {
267
+ if (this.destroyed || t !== this._buildVersion || !this._pixiOverlay || !this._pixiContainer) {
268
+ this._isBuilding = !1, this._buildTimer = null;
269
+ return;
270
+ }
271
+ const l = performance.now();
272
+ let o = i(), a = 0;
273
+ const n = this.options.chunkSize, d = this.options.chunkFrameBudget;
274
+ for (; o < this.records.length && (n <= 0 || a < n) && performance.now() - l < d; ) {
275
+ const c = this.records[o], g = this.createSprite(c, e);
276
+ this._pixiContainer.addChild(g), this.sprites.push(g), this._spriteById.set(c.key, g), this._recordById.set(c.key, c), o += 1, a += 1;
277
+ }
278
+ if (r(o), this.renderedCount = o, this.redraw({ type: "chunk" }), o < this.records.length) {
279
+ this._buildTimer = S(s);
280
+ return;
281
+ }
282
+ this._isBuilding = !1, this._buildTimer = null, this._highlightedKey && this.applyHighlight(this._highlightedKey), this.redraw({ type: "chunk-complete" });
283
+ };
284
+ this._buildTimer = S(s);
285
+ }
286
+ createSprite(t, e) {
287
+ const i = this.resolveSpriteStyle(t, !1), r = new D(this.getTexture(i.image)), s = e([t.latitude, t.longitude]);
288
+ return r.x = s.x, r.y = s.y, r.anchor.set(0.5, 0.5), r.__pointLargeKey = t.key, t.sprite = r, this.applySpriteStyle(t, i), r;
289
+ }
290
+ resolveSpriteStyle(t, e = !1) {
291
+ var y, w, I, _, O, B, P, T, K, M, H, N, R;
292
+ const i = ((y = t.raw) == null ? void 0 : y.properties) || {}, r = this.resolveRuleStyle(t, e), s = this.options.styleCallback ? this.options.styleCallback(t.raw, t.index, { highlighted: e }) || {} : {}, l = e && this.options.highlightStyleCallback ? this.options.highlightStyleCallback(t.raw, t.index) || {} : {}, o = f((w = t.raw) == null ? void 0 : w.style) ? t.raw.style : f(i.style) ? i.style : {}, a = f((I = t.raw) == null ? void 0 : I.highlightStyle) ? t.raw.highlightStyle : f(i.highlightStyle) ? i.highlightStyle : {}, n = e ? { ...r, ...o, ...a, ...s, ...l } : { ...r, ...o, ...s }, d = n.image || n.icon || n.iconUrl || n.imageUrl || ((O = (_ = this.options).imageCallback) == null ? void 0 : O.call(_, t.raw, t.index)) || ((B = t.raw) == null ? void 0 : B.image) || ((P = t.raw) == null ? void 0 : P.icon) || ((T = t.raw) == null ? void 0 : T.iconUrl) || ((K = t.raw) == null ? void 0 : K.imageUrl) || i.image || i.icon || i.iconUrl || i.imageUrl || this.options.image || this.getDefaultImage(!1), c = e ? n.highlightImage || n.highlightIcon || n.highlightIconUrl || n.highlightImageUrl || ((M = t.raw) == null ? void 0 : M.highlightImage) || ((H = t.raw) == null ? void 0 : H.highlightIcon) || ((N = t.raw) == null ? void 0 : N.highlightIconUrl) || ((R = t.raw) == null ? void 0 : R.highlightImageUrl) || i.highlightImage || i.highlightIcon || i.highlightIconUrl || i.highlightImageUrl || this.options.highlightImage || (d !== this.defaultImage ? d : this.getDefaultImage(!0)) : d, g = e ? u(n.width, this.options.highlightWidth) : u(n.width, this.options.width), p = e ? u(n.height, this.options.highlightHeight) : u(n.height, this.options.height), m = e ? u(n.scale, this.options.highlightScale) : u(n.scale, this.options.scale);
293
+ return {
294
+ image: c,
295
+ width: Math.max(g, 1),
296
+ height: Math.max(p, 1),
297
+ scale: Math.max(m, 0.01),
298
+ tint: this.toTint(n.tintColor || n.color || n.billboardColor || "#ffffff"),
299
+ alpha: Math.min(Math.max(u(n.alpha, 1), 0), 1)
300
+ };
301
+ }
302
+ resolveRuleStyle(t, e = !1) {
303
+ const i = this.findMatchedStyleRule(t);
304
+ if (!i)
305
+ return {};
306
+ const r = f(i.style) ? i.style : q(i), s = e && f(i.highlightStyle) ? i.highlightStyle : {};
307
+ return {
308
+ ...r,
309
+ ...s
310
+ };
311
+ }
312
+ findMatchedStyleRule(t) {
313
+ const e = this.options.styleRules || [];
314
+ for (let i = 0; i < e.length; i += 1) {
315
+ const r = e[i];
316
+ if (this.matchStyleRule(r, t))
317
+ return r;
318
+ }
319
+ return null;
320
+ }
321
+ matchStyleRule(t = {}, e) {
322
+ if (typeof t.when == "function")
323
+ return !!t.when(e.raw, e.index, e);
324
+ if (t.default)
325
+ return !0;
326
+ const i = t.field || t.key || this.options.styleField, r = b(e.raw, [i]), s = Number(r);
327
+ if (t.gt !== void 0 && !(s > Number(t.gt)) || t.gte !== void 0 && !(s >= Number(t.gte)) || t.lt !== void 0 && !(s < Number(t.lt)) || t.lte !== void 0 && !(s <= Number(t.lte)) || t.min !== void 0 && !(s >= Number(t.min)) || t.max !== void 0 && !(s <= Number(t.max)))
328
+ return !1;
329
+ if (Array.isArray(t.values))
330
+ return t.values.includes(r);
331
+ const l = t.operator || t.op;
332
+ if (!l)
333
+ return t.value !== void 0 || t.compareValue !== void 0 ? r === (t.value ?? t.compareValue) : !0;
334
+ const o = t.value ?? t.compareValue;
335
+ switch (l) {
336
+ case ">":
337
+ return s > Number(o);
338
+ case ">=":
339
+ return s >= Number(o);
340
+ case "<":
341
+ return s < Number(o);
342
+ case "<=":
343
+ return s <= Number(o);
344
+ case "!=":
345
+ case "!==":
346
+ return r !== o;
347
+ case "in":
348
+ return Array.isArray(o) && o.includes(r);
349
+ case "==":
350
+ case "===":
351
+ default:
352
+ return r === o;
353
+ }
354
+ }
355
+ applySpriteStyle(t, e = null) {
356
+ var o, a;
357
+ const i = t == null ? void 0 : t.sprite;
358
+ if (!i)
359
+ return;
360
+ const r = t.key === this._highlightedKey || t.key === this._hoveredKey, s = e || this.resolveSpriteStyle(t, r), l = this.getTexture(s.image);
361
+ (o = l.orig) != null && o.width || l.width || s.width, (a = l.orig) != null && a.height || l.height || s.height, i.texture = l, i.tint = s.tint, i.alpha = s.alpha, t._activeStyle = s, this.updateSpriteScale(t);
362
+ }
363
+ updateSpriteScale(t) {
364
+ var a, n;
365
+ const e = t == null ? void 0 : t.sprite, i = t == null ? void 0 : t._activeStyle;
366
+ if (!e || !i)
367
+ return;
368
+ const r = e.texture || this.getTexture(i.image), s = ((a = r.orig) == null ? void 0 : a.width) || r.width || i.width, l = ((n = r.orig) == null ? void 0 : n.height) || r.height || i.height, o = this.options.keepSize ? this._latestInvScale : 1;
369
+ e.scale.set(
370
+ i.width / s * i.scale * o,
371
+ i.height / l * i.scale * o
372
+ ), t.pickRadius = Math.max(
373
+ this.options.pickRadius,
374
+ Math.max(i.width, i.height) * i.scale / 2
375
+ );
376
+ }
377
+ updateSpriteScales() {
378
+ this.sprites.forEach((t) => {
379
+ const e = this._recordById.get(t.__pointLargeKey);
380
+ e && this.updateSpriteScale(e);
381
+ });
382
+ }
383
+ restyleSprites(t = !0) {
384
+ this.sprites.forEach((e) => {
385
+ const i = this._recordById.get(e.__pointLargeKey);
386
+ i && this.applySpriteStyle(i);
387
+ }), t && this.redraw({ type: "restyle" });
388
+ }
389
+ getTexture(t) {
390
+ const e = t || this.getDefaultImage(!1);
391
+ return this._textureByImage.has(e) || this._textureByImage.set(e, V.from(e)), this._textureByImage.get(e);
392
+ }
393
+ getDefaultImage(t = !1) {
394
+ if (t && this.defaultHighlightImage)
395
+ return this.defaultHighlightImage;
396
+ if (!t && this.defaultImage)
397
+ return this.defaultImage;
398
+ if (typeof document > "u")
399
+ return "";
400
+ const e = Math.ceil(t ? this.options.highlightWidth : this.options.width), i = Math.ceil(t ? this.options.highlightHeight : this.options.height), r = t ? this.options.highlightOutlineWidth : this.options.outlineWidth, s = document.createElement("canvas");
401
+ s.width = Math.max(e, 1), s.height = Math.max(i, 1);
402
+ const l = s.getContext("2d");
403
+ if (!l)
404
+ return "";
405
+ const o = s.width / 2, a = s.height / 2, n = Math.max(Math.min(s.width, s.height) / 2 - r, 1);
406
+ l.fillStyle = t ? this.options.highlightColor : this.options.color, l.strokeStyle = t ? this.options.highlightOutlineColor : this.options.outlineColor, l.lineWidth = r, l.beginPath(), l.arc(o, a, n, 0, Math.PI * 2), l.fill(), r > 0 && l.stroke();
407
+ const d = s.toDataURL("image/png");
408
+ return t ? this.defaultHighlightImage = d : this.defaultImage = d, d;
409
+ }
410
+ setHighlight(t) {
411
+ const e = t == null || t === "" ? "" : v(t, "");
412
+ return this.clearHighlight(), this._highlightedKey = e, e ? this.applyHighlight(e) : !1;
413
+ }
414
+ setHighlighted(t) {
415
+ return this.setHighlight(t);
416
+ }
417
+ highlight(t) {
418
+ return this.setHighlight(t);
419
+ }
420
+ applyHighlight(t) {
421
+ const e = this._recordById.get(t);
422
+ return e ? (this._highlightedKey = t, this.applySpriteStyle(e), this.redraw({ type: "highlight" }), !0) : !1;
423
+ }
424
+ clearHighlight() {
425
+ if (!this._highlightedKey)
426
+ return;
427
+ const t = this._highlightedKey;
428
+ this._highlightedKey = "";
429
+ const e = this._recordById.get(t);
430
+ e && this.applySpriteStyle(e), this.redraw({ type: "highlight-clear" });
431
+ }
432
+ clearHighlighted() {
433
+ this.clearHighlight();
434
+ }
435
+ removePoint(t) {
436
+ const e = this.resolveInputKey(t), i = this._recordById.get(e) || this.records.find((r) => r.key === e);
437
+ return i ? this._isBuilding ? (this.cancelBuild(), this.records = this.records.filter((r) => r.key !== e), this.points = this.records.map((r) => r.raw), this.rebuildSprites(), !0) : (this.removeRecord(i), this.redraw({ type: "delete" }), !0) : !1;
438
+ }
439
+ removePoints(t = []) {
440
+ if (!Array.isArray(t))
441
+ return this.removePoint(t);
442
+ const e = new Set(t.map((r) => this.resolveInputKey(r)));
443
+ let i = 0;
444
+ if (this._isBuilding) {
445
+ this.cancelBuild();
446
+ const r = this.records.length;
447
+ return this.records = this.records.filter((s) => !e.has(s.key)), i = r - this.records.length, this.points = this.records.map((s) => s.raw), i > 0 && this.rebuildSprites(), i;
448
+ }
449
+ return e.forEach((r) => {
450
+ const s = this._recordById.get(r) || this.records.find((l) => l.key === r);
451
+ s && (this.removeRecord(s), i += 1);
452
+ }), i > 0 && this.redraw({ type: "delete" }), i;
453
+ }
454
+ resolveInputKey(t) {
455
+ var e;
456
+ if (f(t)) {
457
+ const i = t.key ?? t.id ?? t[this.options.idKey] ?? ((e = t.properties) == null ? void 0 : e[this.options.idKey]);
458
+ return v(i, "");
459
+ }
460
+ return v(t, "");
461
+ }
462
+ removeRecord(t) {
463
+ var s, l, o;
464
+ const e = t.key, i = t.sprite;
465
+ this._hoveredKey === e && (this._hoveredKey = "", (l = (s = this.options).onHoverOut) == null || l.call(s, this.createPointEvent(t)), this.hideTooltip(), this.restoreCursor()), i && ((o = this._pixiContainer) == null || o.removeChild(i), i.destroy({
466
+ children: !1,
467
+ texture: !1,
468
+ baseTexture: !1
469
+ }), t.sprite = null), this.sprites = this.sprites.filter((a) => a !== i), this.records = this.records.filter((a) => a.key !== e), this.points = this.records.map((a) => a.raw), this._spriteById.delete(e), this._recordById.delete(e), this.renderedCount = this._recordById.size, this._highlightedKey === e && (this._highlightedKey = "");
470
+ }
471
+ removeById(t) {
472
+ return this.removePoint(t);
473
+ }
474
+ removeByIds(t = []) {
475
+ return this.removePoints(t);
476
+ }
477
+ remove(t) {
478
+ return this.removePoint(t);
479
+ }
480
+ deletePoint(t) {
481
+ return this.removePoint(t);
482
+ }
483
+ deletePoints(t = []) {
484
+ return this.removePoints(t);
485
+ }
486
+ clear() {
487
+ this.cancelBuild(), this.destroyPixiObjects(), this.points = [], this.records = [], this.sprites = [], this.renderedCount = 0, this._spriteById.clear(), this._recordById.clear(), this._highlightedKey = "", this._hoveredKey = "", this.hideTooltip();
488
+ }
489
+ bindEvents() {
490
+ if (!this.map || !this._ready)
491
+ return;
492
+ this.unbindEvents();
493
+ const t = this.options.showTooltip || this.options.onHover || this.options.onHoverIn || this.options.onHoverOut, e = this.options.onClick;
494
+ t && (this.map.on("mousemove", this._boundMouseMove), this.map.on("mouseout", this._boundMouseOut), this._eventsBound = !0), e && (this.map.on("click", this._boundClick), this._eventsBound = !0);
495
+ }
496
+ unbindEvents() {
497
+ !this.map || !this._eventsBound || (this.map.off("mousemove", this._boundMouseMove), this.map.off("mouseout", this._boundMouseOut), this.map.off("click", this._boundClick), this._eventsBound = !1);
498
+ }
499
+ scheduleHoverPick(t) {
500
+ this.destroyed || !this.visible || (this._lastMove = t, !this._moveTimer && (this._moveTimer = S(() => {
501
+ this._moveTimer = null, this.handleHover(this._lastMove);
502
+ })));
503
+ }
504
+ handleHover(t) {
505
+ var l, o, a, n;
506
+ const e = this.pickPoint(t == null ? void 0 : t.containerPoint);
507
+ if (!e) {
508
+ this._hoveredKey && this.handleHoverOut(), this.hideTooltip(), this.restoreCursor();
509
+ return;
510
+ }
511
+ const { record: i, sprite: r } = e, s = this.createPointEvent(i, {
512
+ sprite: r,
513
+ originalEvent: t,
514
+ containerPoint: t == null ? void 0 : t.containerPoint,
515
+ latlng: t == null ? void 0 : t.latlng
516
+ });
517
+ this._hoveredKey !== i.key && (this._hoveredKey && this.handleHoverOut(), this._hoveredKey = i.key, this.applySpriteStyle(i), (o = (l = this.options).onHoverIn) == null || o.call(l, s), this.redraw({ type: "hover-in" })), (n = (a = this.options).onHover) == null || n.call(a, s), this.showTooltip(s, t), this.setCursor();
518
+ }
519
+ handleHoverOut(t = null) {
520
+ var r, s;
521
+ const e = t || this._recordById.get(this._hoveredKey), i = this._hoveredKey;
522
+ this._hoveredKey = "", e && (this.applySpriteStyle(e), (s = (r = this.options).onHoverOut) == null || s.call(r, this.createPointEvent(e))), i && this.redraw({ type: "hover-out" });
523
+ }
524
+ handleClick(t) {
525
+ if (this.destroyed || !this.visible || !this.options.onClick)
526
+ return;
527
+ const e = this.pickPoint(t == null ? void 0 : t.containerPoint);
528
+ e && this.options.onClick(this.createPointEvent(e.record, {
529
+ sprite: e.sprite,
530
+ originalEvent: t,
531
+ containerPoint: t == null ? void 0 : t.containerPoint,
532
+ latlng: t == null ? void 0 : t.latlng
533
+ }));
534
+ }
535
+ pickPoint(t) {
536
+ if (!t || !this.map || this.sprites.length === 0)
537
+ return null;
538
+ let e = null, i = null, r = Number.POSITIVE_INFINITY;
539
+ for (let s = 0; s < this.sprites.length; s += 1) {
540
+ const l = this.sprites[s], o = this._recordById.get(l.__pointLargeKey);
541
+ if (!o)
542
+ continue;
543
+ const a = this.map.latLngToContainerPoint([o.latitude, o.longitude]), n = o.pickRadius, d = t.x - a.x, c = t.y - a.y;
544
+ if (Math.abs(d) > n || Math.abs(c) > n)
545
+ continue;
546
+ const g = d * d + c * c;
547
+ g < r && (r = g, e = o, i = l);
548
+ }
549
+ return e ? {
550
+ record: e,
551
+ sprite: i
552
+ } : null;
553
+ }
554
+ createPointEvent(t, e = {}) {
555
+ return {
556
+ layerId: this.layerId,
557
+ id: t == null ? void 0 : t.id,
558
+ key: t == null ? void 0 : t.key,
559
+ index: t == null ? void 0 : t.index,
560
+ data: t == null ? void 0 : t.raw,
561
+ record: t,
562
+ layer: this,
563
+ ...e
564
+ };
565
+ }
566
+ showTooltip(t, e) {
567
+ var n, d, c, g, p, m;
568
+ if (!this.options.showTooltip || !e)
569
+ return;
570
+ const i = this.resolveTooltipHtml(t);
571
+ if (!i) {
572
+ this.hideTooltip();
573
+ return;
574
+ }
575
+ const r = this.getTooltip(), s = Array.isArray(this.options.tooltipOffset) ? this.options.tooltipOffset : [14, 14], l = e.originalEvent || {};
576
+ let o = u(l.clientX, Number.NaN), a = u(l.clientY, Number.NaN);
577
+ if (!Number.isFinite(o) || !Number.isFinite(a)) {
578
+ const y = (g = (d = (n = this.map) == null ? void 0 : n.getContainer) == null ? void 0 : (c = d.call(n)).getBoundingClientRect) == null ? void 0 : g.call(c);
579
+ o = ((y == null ? void 0 : y.left) || 0) + u((p = e.containerPoint) == null ? void 0 : p.x, 0), a = ((y == null ? void 0 : y.top) || 0) + u((m = e.containerPoint) == null ? void 0 : m.y, 0);
580
+ }
581
+ r.innerHTML = i, r.style.display = "block", r.style.left = `${o + u(s[0], 14)}px`, r.style.top = `${a + u(s[1], 14)}px`, this._tooltipRecordKey = t.key;
582
+ }
583
+ resolveTooltipHtml(t) {
584
+ var l;
585
+ if (this.options.tooltipFormatter)
586
+ return this.options.tooltipFormatter(t);
587
+ const e = ((l = t.data) == null ? void 0 : l.properties) || t.data || {};
588
+ if (!f(e))
589
+ return `<div class="point-large-tooltip__line">${x(e)}</div>`;
590
+ const i = e.name || e.title || e.label || `点位 ${t.id ?? t.index}`, s = Object.entries(e).filter(([o, a]) => !["geometry", "coordinates", "position", "style", "highlightStyle", "image"].includes(o) && a !== void 0 && a !== null && typeof a != "object").slice(0, 8).map(([o, a]) => `<div class="point-large-tooltip__row"><span>${x(o)}</span><b>${x(a)}</b></div>`).join("");
591
+ return `
592
+ <div class="point-large-tooltip__title">${x(i)}</div>
593
+ ${s}
594
+ `;
595
+ }
596
+ getTooltip() {
597
+ if (this._tooltip)
598
+ return this._tooltip;
599
+ const t = document.createElement("div");
600
+ return t.className = this.options.tooltipClassName, t.style.cssText = [
601
+ "position: fixed",
602
+ "z-index: 9999",
603
+ "display: none",
604
+ "max-width: 260px",
605
+ "padding: 8px 10px",
606
+ "border: 1px solid rgba(110, 160, 255, 0.45)",
607
+ "border-radius: 4px",
608
+ "background: rgba(10, 22, 42, 0.92)",
609
+ "box-shadow: 0 8px 24px rgba(0, 0, 0, 0.24)",
610
+ "color: #fff",
611
+ "font-size: 12px",
612
+ "line-height: 1.5",
613
+ "pointer-events: none",
614
+ "white-space: normal"
615
+ ].join(";"), document.body.appendChild(t), this._tooltip = t, t;
616
+ }
617
+ hideTooltip() {
618
+ this._tooltip && (this._tooltip.style.display = "none", this._tooltipRecordKey = "");
619
+ }
620
+ destroyTooltip() {
621
+ this._tooltip && (this._tooltip.remove(), this._tooltip = null, this._tooltipRecordKey = "");
622
+ }
623
+ setCursor() {
624
+ var e, i;
625
+ const t = (i = (e = this.map) == null ? void 0 : e.getContainer) == null ? void 0 : i.call(e);
626
+ !t || !this.options.cursor || (this._previousCursor || (this._previousCursor = t.style.cursor || ""), t.style.cursor = this.options.cursor);
627
+ }
628
+ restoreCursor() {
629
+ var e, i;
630
+ const t = (i = (e = this.map) == null ? void 0 : e.getContainer) == null ? void 0 : i.call(e);
631
+ t && (t.style.cursor = this._previousCursor, this._previousCursor = "");
632
+ }
633
+ setVisible(t) {
634
+ this.visible = !!t, this._pixiContainer && (this._pixiContainer.visible = this.visible), this.visible || (this.handleHoverOut(), this.hideTooltip(), this.restoreCursor()), this.redraw({ type: this.visible ? "show" : "hide" });
635
+ }
636
+ show() {
637
+ this.setVisible(!0);
638
+ }
639
+ hide() {
640
+ this.setVisible(!1);
641
+ }
642
+ toTint(t) {
643
+ if (typeof t == "number" && Number.isFinite(t))
644
+ return t;
645
+ if (Array.isArray(t)) {
646
+ const e = Math.min(Math.max(Math.round(u(t[0], 255)), 0), 255), i = Math.min(Math.max(Math.round(u(t[1], 255)), 0), 255), r = Math.min(Math.max(Math.round(u(t[2], 255)), 0), 255);
647
+ return (e << 16) + (i << 8) + r;
648
+ }
649
+ try {
650
+ return new j(t || "#ffffff").toNumber();
651
+ } catch {
652
+ return 16777215;
653
+ }
654
+ }
655
+ redraw(t = { type: "redraw" }) {
656
+ var e, i;
657
+ (i = (e = this._pixiOverlay) == null ? void 0 : e.redraw) == null || i.call(e, t);
658
+ }
659
+ cancelBuild() {
660
+ this._buildVersion += 1, this._buildTimer && (F(this._buildTimer), this._buildTimer = null), this._isBuilding = !1;
661
+ }
662
+ destroyPixiObjects() {
663
+ var t, e;
664
+ this._moveTimer && (F(this._moveTimer), this._moveTimer = null), this.sprites.forEach((i) => {
665
+ i.destroy({
666
+ children: !1,
667
+ texture: !1,
668
+ baseTexture: !1
669
+ });
670
+ }), this.sprites = [], this._pixiOverlay && ((e = (t = this._pixiOverlay).destroy) == null || e.call(t), this._pixiOverlay = null), this._pixiContainer = null;
671
+ }
672
+ destroy() {
673
+ this.destroyed = !0, this.cancelBuild(), this.unbindEvents(), this.handleHoverOut(), this.hideTooltip(), this.restoreCursor(), this.destroyTooltip(), this.destroyPixiObjects(), this.points = [], this.records = [], this.renderedCount = 0, this._spriteById.clear(), this._recordById.clear(), this._textureByImage.clear(), this._highlightedKey = "", this._hoveredKey = "";
674
+ }
675
+ getState() {
676
+ var t;
677
+ return {
678
+ layerId: this.layerId,
679
+ visible: this.visible,
680
+ total: this.records.length,
681
+ renderedCount: this.renderedCount,
682
+ highlightedId: ((t = this._recordById.get(this._highlightedKey)) == null ? void 0 : t.id) ?? null,
683
+ building: this._isBuilding,
684
+ destroyed: this.destroyed
685
+ };
686
+ }
687
+ }
688
+ export {
689
+ G as PointLargeLayer
690
+ };