jgis 1.0.1 → 1.0.3

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.
package/dist/2d/index.mjs CHANGED
@@ -1,43 +1,44 @@
1
- var re = Object.defineProperty, ne = Object.defineProperties;
2
- var oe = Object.getOwnPropertyDescriptors;
3
- var Z = Object.getOwnPropertySymbols;
4
- var se = Object.prototype.hasOwnProperty, ae = Object.prototype.propertyIsEnumerable;
5
- var C = (e, t, r) => t in e ? re(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, A = (e, t) => {
1
+ var se = Object.defineProperty, ae = Object.defineProperties;
2
+ var ce = Object.getOwnPropertyDescriptors;
3
+ var B = Object.getOwnPropertySymbols;
4
+ var ie = Object.prototype.hasOwnProperty, le = Object.prototype.propertyIsEnumerable;
5
+ var V = (e, t, r) => t in e ? se(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, R = (e, t) => {
6
6
  for (var r in t || (t = {}))
7
- se.call(t, r) && C(e, r, t[r]);
8
- if (Z)
9
- for (var r of Z(t))
10
- ae.call(t, r) && C(e, r, t[r]);
7
+ ie.call(t, r) && V(e, r, t[r]);
8
+ if (B)
9
+ for (var r of B(t))
10
+ le.call(t, r) && V(e, r, t[r]);
11
11
  return e;
12
- }, k = (e, t) => ne(e, oe(t));
13
- var v = (e, t, r) => new Promise((n, o) => {
14
- var s = (c) => {
12
+ }, O = (e, t) => ae(e, ce(t));
13
+ var T = (e, t, r) => new Promise((o, n) => {
14
+ var s = (i) => {
15
15
  try {
16
- a(r.next(c));
17
- } catch (u) {
18
- o(u);
16
+ c(r.next(i));
17
+ } catch (l) {
18
+ n(l);
19
19
  }
20
- }, i = (c) => {
20
+ }, a = (i) => {
21
21
  try {
22
- a(r.throw(c));
23
- } catch (u) {
24
- o(u);
22
+ c(r.throw(i));
23
+ } catch (l) {
24
+ n(l);
25
25
  }
26
- }, a = (c) => c.done ? n(c.value) : Promise.resolve(c.value).then(s, i);
27
- a((r = r.apply(e, t)).next());
26
+ }, c = (i) => i.done ? o(i.value) : Promise.resolve(i.value).then(s, a);
27
+ c((r = r.apply(e, t)).next());
28
28
  });
29
- import { Map as ce, View as ie } from "ol";
30
- import { Tile as O, Vector as F } from "ol/layer";
31
- import { Vector as T, TileWMS as j, XYZ as V, ImageWMS as U } from "ol/source";
32
- import { GeoJSON as p } from "ol/format";
33
- import le from "ol/Overlay";
34
- import { Polygon as ue, MultiPolygon as fe, MultiLineString as ye, LineString as ge, Point as me } from "ol/geom";
35
- import de from "ol/Feature";
29
+ import { Map as ue, View as fe } from "ol";
30
+ import { Tile as j, Vector as E } from "ol/layer";
31
+ import { Vector as M, TileWMS as N, XYZ as G, ImageWMS as W } from "ol/source";
32
+ import { GeoJSON as I } from "ol/format";
33
+ import ye from "ol/Overlay";
34
+ import { Geometry as ge, Polygon as me, MultiPolygon as de, MultiLineString as we, LineString as he, Point as be } from "ol/geom";
35
+ import Le from "ol/Feature";
36
36
  import "ol/extent";
37
- import { Style as we, Circle as he, Fill as be } from "ol/style";
38
- import { click as Me } from "ol/events/condition.js";
39
- import Pe from "ol/interaction/Select";
40
- var g = 63710088e-1, Ee = {
37
+ import { Style as Fe, Circle as Se, Fill as xe } from "ol/style";
38
+ import { defaults as Pe } from "ol/control";
39
+ import { click as ve } from "ol/events/condition.js";
40
+ import Ee from "ol/interaction/Select";
41
+ var g = 63710088e-1, Me = {
41
42
  centimeters: g * 100,
42
43
  centimetres: g * 100,
43
44
  degrees: 360 / (2 * Math.PI),
@@ -54,57 +55,57 @@ var g = 63710088e-1, Ee = {
54
55
  radians: 1,
55
56
  yards: g * 1.0936
56
57
  };
57
- function W(e, t, r = {}) {
58
- const n = { type: "Feature" };
59
- return (r.id === 0 || r.id) && (n.id = r.id), r.bbox && (n.bbox = r.bbox), n.properties = t || {}, n.geometry = e, n;
58
+ function H(e, t, r = {}) {
59
+ const o = { type: "Feature" };
60
+ return (r.id === 0 || r.id) && (o.id = r.id), r.bbox && (o.bbox = r.bbox), o.properties = t || {}, o.geometry = e, o;
60
61
  }
61
- function $(e, t, r = {}) {
62
+ function q(e, t, r = {}) {
62
63
  if (!e)
63
64
  throw new Error("coordinates is required");
64
65
  if (!Array.isArray(e))
65
66
  throw new Error("coordinates must be an Array");
66
67
  if (e.length < 2)
67
68
  throw new Error("coordinates must be at least 2 numbers long");
68
- if (!B(e[0]) || !B(e[1]))
69
+ if (!D(e[0]) || !D(e[1]))
69
70
  throw new Error("coordinates must contain numbers");
70
- return W({
71
+ return H({
71
72
  type: "Point",
72
73
  coordinates: e
73
74
  }, t, r);
74
75
  }
75
- function Le(e, t, r = {}) {
76
- for (const o of e) {
77
- if (o.length < 4)
76
+ function Te(e, t, r = {}) {
77
+ for (const n of e) {
78
+ if (n.length < 4)
78
79
  throw new Error(
79
80
  "Each LinearRing of a Polygon must have 4 or more Positions."
80
81
  );
81
- if (o[o.length - 1].length !== o[0].length)
82
+ if (n[n.length - 1].length !== n[0].length)
82
83
  throw new Error("First and last Position are not equivalent.");
83
- for (let s = 0; s < o[o.length - 1].length; s++)
84
- if (o[o.length - 1][s] !== o[0][s])
84
+ for (let s = 0; s < n[n.length - 1].length; s++)
85
+ if (n[n.length - 1][s] !== n[0][s])
85
86
  throw new Error("First and last Position are not equivalent.");
86
87
  }
87
- return W({
88
+ return H({
88
89
  type: "Polygon",
89
90
  coordinates: e
90
91
  }, t, r);
91
92
  }
92
- function Se(e, t = "kilometers") {
93
- const r = Ee[t];
93
+ function Ie(e, t = "kilometers") {
94
+ const r = Me[t];
94
95
  if (!r)
95
96
  throw new Error(t + " units is invalid");
96
97
  return e / r;
97
98
  }
98
- function G(e) {
99
+ function $(e) {
99
100
  return e % (2 * Math.PI) * 180 / Math.PI;
100
101
  }
101
- function R(e) {
102
+ function z(e) {
102
103
  return e % 360 * Math.PI / 180;
103
104
  }
104
- function B(e) {
105
+ function D(e) {
105
106
  return !isNaN(e) && e !== null && !Array.isArray(e);
106
107
  }
107
- function xe(e) {
108
+ function pe(e) {
108
109
  if (!e)
109
110
  throw new Error("coord is required");
110
111
  if (!Array.isArray(e)) {
@@ -117,65 +118,93 @@ function xe(e) {
117
118
  return [...e];
118
119
  throw new Error("coord must be GeoJSON Point or an Array of numbers");
119
120
  }
120
- function ve(e, t, r, n = {}) {
121
- const o = xe(e), s = R(o[0]), i = R(o[1]), a = R(r), c = Se(t, n.units), u = Math.asin(
122
- Math.sin(i) * Math.cos(c) + Math.cos(i) * Math.sin(c) * Math.cos(a)
121
+ function Ae(e, t, r, o = {}) {
122
+ const n = pe(e), s = z(n[0]), a = z(n[1]), c = z(r), i = Ie(t, o.units), l = Math.asin(
123
+ Math.sin(a) * Math.cos(i) + Math.cos(a) * Math.sin(i) * Math.cos(c)
123
124
  ), m = s + Math.atan2(
124
- Math.sin(a) * Math.sin(c) * Math.cos(i),
125
- Math.cos(c) - Math.sin(i) * Math.sin(u)
126
- ), L = G(m), l = G(u);
127
- return o[2] !== void 0 ? $([L, l, o[2]], n.properties) : $([L, l], n.properties);
128
- }
129
- function Fe(e, t, r = {}) {
130
- const n = r.steps || 64, o = r.properties ? r.properties : !Array.isArray(e) && e.type === "Feature" && e.properties ? e.properties : {}, s = [];
131
- for (let i = 0; i < n; i++)
125
+ Math.sin(c) * Math.sin(i) * Math.cos(a),
126
+ Math.cos(i) - Math.sin(a) * Math.sin(l)
127
+ ), x = $(m), u = $(l);
128
+ return n[2] !== void 0 ? q([x, u, n[2]], o.properties) : q([x, u], o.properties);
129
+ }
130
+ function ke(e, t, r = {}) {
131
+ const o = r.steps || 64, n = r.properties ? r.properties : !Array.isArray(e) && e.type === "Feature" && e.properties ? e.properties : {}, s = [];
132
+ for (let a = 0; a < o; a++)
132
133
  s.push(
133
- ve(e, t, i * -360 / n, r).geometry.coordinates
134
+ Ae(e, t, a * -360 / o, r).geometry.coordinates
134
135
  );
135
- return s.push(s[0]), Le([s], o);
136
+ return s.push(s[0]), Te([s], n);
136
137
  }
137
- function D(e) {
138
- return e.lttd && e.lgtd ? [Number(e.lgtd), Number(e.lttd)] : e.jd && e.wd ? [Number(e.jd), Number(e.wd)] : e.latitude && e.longitude ? [Number(e.longitude), Number(e.latitude)] : e.lon && e.lat ? [Number(e.lon), Number(e.lat)] : [0, 0];
138
+ function p(e, t) {
139
+ return typeof e != "object" || e === null ? null : e.lttd && e.lgtd ? [Number(e.lgtd), Number(e.lttd)] : e.jd && e.wd ? [Number(e.jd), Number(e.wd)] : e.latitude && e.longitude ? [Number(e.longitude), Number(e.latitude)] : e.lon && e.lat ? [Number(e.lon), Number(e.lat)] : null;
139
140
  }
140
- function q(e, t) {
141
- e.getLayers().getArray().forEach((n) => {
142
- n.get("name") == t && ("setSource" in n && n.setSource(null), "dispose" in n && n.dispose(), e.removeLayer(n));
141
+ function U(e, t) {
142
+ e.getLayers().getArray().forEach((o) => {
143
+ o.get("name") == t && ("setSource" in o && o.setSource(null), "dispose" in o && o.dispose(), e.removeLayer(o));
143
144
  });
144
145
  }
145
- function Te(e, t, r) {
146
- const n = [];
147
- let o;
146
+ function J(e, t, r, o = !1) {
147
+ const n = o ? r.style || r.getStyle(e, t) : void 0, s = o ? 999 : -1;
148
+ n && typeof n.setZIndex == "function" && n.setZIndex(s), t.setStyle(n);
149
+ }
150
+ function Re(e, t, r) {
151
+ if (!t) return;
152
+ const o = r.time || 300;
153
+ let n = Date.now(), s = !1, a = 0;
154
+ t.running = !0;
155
+ function c() {
156
+ if (!t.running) return;
157
+ const i = Date.now();
158
+ i - n >= o && (s = !s, n = i, J(e, t, r, s), t.changed()), a = requestAnimationFrame(c);
159
+ }
160
+ c(), t.clearFlash = () => {
161
+ t.running = !1, cancelAnimationFrame(a), t.setStyle(void 0);
162
+ };
163
+ }
164
+ function Oe(e, t, r) {
165
+ var a, c;
166
+ if (!r) return;
167
+ let o = p(r);
168
+ const n = (c = (a = Q(e, t)) == null ? void 0 : a.getFeatures) == null ? void 0 : c.call(a);
169
+ return n ? n.find(function(i) {
170
+ const l = i.getGeometry();
171
+ return l && l instanceof ge && typeof l.intersectsCoordinate == "function" ? l.intersectsCoordinate(o) : !1;
172
+ }) : void 0;
173
+ }
174
+ function ze(e, t, r) {
175
+ const o = [];
176
+ let n;
148
177
  const s = r.type || "Point";
149
- t.forEach((a) => {
178
+ t.forEach((c) => {
150
179
  switch (s) {
151
180
  case "Point":
152
- o = Ie(a);
181
+ n = Ne(c);
153
182
  break;
154
183
  case "LineString":
155
- o = Ae(a);
184
+ n = Ze(c);
156
185
  break;
157
186
  case "MultiLineString":
158
- o = ke(a);
187
+ n = _e(c);
159
188
  break;
160
189
  case "MultiPolygon":
161
- o = Re(a);
190
+ n = Ce(c);
162
191
  break;
163
192
  case "Polygon":
164
- o = Oe(a);
193
+ n = Be(c);
165
194
  break;
166
195
  }
167
- if (!o) return;
168
- const c = new de({
169
- geometry: o,
170
- data: a
196
+ if (!n) return;
197
+ const i = new Le({
198
+ geometry: n,
199
+ data: c
171
200
  });
172
- c.set("layerName", e), n.push(c);
201
+ i.set("layerName", e), o.push(i);
173
202
  });
174
- const i = new T();
175
- return n.length > 0 && i.addFeatures(n), i;
203
+ const a = new M();
204
+ return o.length > 0 && a.addFeatures(o), a;
176
205
  }
177
- function pe(e, t) {
178
- return t.cqlFilter && (t.cqlFilter ? t.CQL_FILTER += ` and ${t.cqlFilter}` : t.CQL_FILTER = t.cqlFilter), new j({
206
+ function je(e, t) {
207
+ return t.cqlFilter && (t.cqlFilter ? t.CQL_FILTER += ` and ${t.cqlFilter}` : t.CQL_FILTER = t.cqlFilter), new N({
179
208
  url: t.url,
180
209
  params: {
181
210
  LAYERS: t.layers,
@@ -185,255 +214,279 @@ function pe(e, t) {
185
214
  crossOrigin: "anonymous"
186
215
  });
187
216
  }
188
- function Ie(e) {
189
- const t = D(e);
217
+ function Q(e, t) {
218
+ const r = Z(e, t);
219
+ return r == null ? void 0 : r.getSource();
220
+ }
221
+ function Ne(e) {
222
+ const t = p(e);
190
223
  if (t)
191
- return new me(t);
224
+ return new be(t);
192
225
  }
193
- function Ae(e) {
194
- return new ge(e.coordinates);
226
+ function Ze(e) {
227
+ return new he(e.coordinates);
195
228
  }
196
- function ke(e) {
197
- return new ye(e.coordinates);
229
+ function _e(e) {
230
+ return new we(e.coordinates);
198
231
  }
199
- function Re(e) {
200
- return new fe(e.coordinates);
232
+ function Ce(e) {
233
+ return new de(e.coordinates);
201
234
  }
202
- function Oe(e) {
203
- return new ue(e.coordinates);
235
+ function Be(e) {
236
+ return new me(e.coordinates);
204
237
  }
205
- function z(e, t) {
238
+ function A(e, t) {
206
239
  let r = null;
207
- return t.style ? r = t.style : t.getStyle ? r = (n, o) => t.getStyle(e, n, o) : r = je(), r;
240
+ return t.style ? r = t.style : t.getStyle ? r = (o, n) => t.getStyle(e, o, n) : r = Ve(), r;
208
241
  }
209
- function je() {
210
- return (t, r) => new we({
211
- image: new he({
242
+ function Ve() {
243
+ return (t, r) => new Fe({
244
+ image: new Se({
212
245
  radius: 5,
213
- fill: new be({ color: "red" })
246
+ fill: new xe({ color: "red" })
214
247
  })
215
248
  });
216
249
  }
217
- function ze(e, t = {}) {
218
- const r = t.token || "dadcbbdb5206b626a29ca739686b3087", n = t.baseType || "img", o = t.noteType || "cia", s = new O({
250
+ function Ge(e, t = {}) {
251
+ const r = t.token || "dadcbbdb5206b626a29ca739686b3087", o = t.baseType || "img", n = t.noteType || "cia", s = new j({
219
252
  className: "tdt-base-layer",
220
- source: new V({
221
- url: `http://t0.tianditu.com/DataServer?T=${n}_w&x={x}&y={y}&l={z}&tk=${r}`,
253
+ source: new G({
254
+ url: `http://t0.tianditu.com/DataServer?T=${o}_w&x={x}&y={y}&l={z}&tk=${r}`,
222
255
  maxZoom: t.maxZoom || 18,
223
256
  minZoom: t.minZoom || 2
224
257
  }),
225
258
  zIndex: t.zIndex || 1
226
259
  });
227
260
  s.set("name", "tdt-base-layer");
228
- const i = new O({
261
+ const a = new j({
229
262
  className: "tdt-base-layer",
230
- source: new V({
231
- url: `http://t0.tianditu.com/DataServer?T=${o}_w&x={x}&y={y}&l={z}&tk=${r}`,
263
+ source: new G({
264
+ url: `http://t0.tianditu.com/DataServer?T=${n}_w&x={x}&y={y}&l={z}&tk=${r}`,
232
265
  maxZoom: t.maxZoom || 18,
233
266
  minZoom: t.minZoom || 2
234
267
  }),
235
268
  zIndex: t.zIndex ? t.zIndex + 1 : 2
236
269
  });
237
- return i.set("name", "tdt-baseNote-layer"), e.addLayer(s), e.addLayer(i), s;
270
+ return a.set("name", "tdt-baseNote-layer"), e.addLayer(s), e.addLayer(a), s;
238
271
  }
239
- function H(e, t, r, n) {
240
- (!n || !n.type) && (n = Object.assign({}, r, n));
241
- const o = n.type || "Point";
272
+ function X(e, t, r, o) {
273
+ (!o || !o.type) && (o = Object.assign({}, r, o));
274
+ const n = o.type || "Point";
242
275
  let s;
243
- switch (o) {
276
+ switch (n) {
244
277
  case "GeoJSON":
245
- s = Ne(t, r, e, n);
278
+ s = $e(t, r, e, o);
246
279
  break;
247
280
  case "Wms":
248
- s = Ze(t, e, n);
281
+ s = De(t, e, o);
249
282
  break;
250
283
  case "Point":
251
284
  case "LineString":
252
285
  case "MultiLineString":
253
286
  case "Polygon":
254
287
  case "MultiPolygon":
255
- s = Ce(t, r, e, n);
288
+ s = Ue(t, r, e, o);
256
289
  break;
257
290
  case "Circle":
258
- s = Ve(t, r, e, n);
291
+ s = We(t, r, e, o);
259
292
  break;
260
293
  case "Overlay":
261
- s = $e(t, r, e, n);
294
+ s = He(t, e, o);
262
295
  break;
263
296
  }
264
297
  return s;
265
298
  }
266
- function _e(e, t) {
299
+ function qe(e, t) {
267
300
  Array.isArray(t) ? t.forEach((r) => {
268
- q(e, r);
269
- }) : q(e, t);
301
+ U(e, r);
302
+ }) : U(e, t);
270
303
  }
271
- function Ne(e, t, r, n) {
304
+ function $e(e, t, r, o) {
272
305
  console.log(typeof t, t);
273
- const o = new p().readFeatures(t, {
306
+ const n = new I().readFeatures(t, {
274
307
  dataProjection: "EPSG:4326",
275
308
  featureProjection: "EPSG:4326"
276
309
  // 或 'EPSG:3857',看你的地图
277
- }), s = new T();
278
- s.addFeatures(o);
279
- const i = new F({
310
+ }), s = new M();
311
+ s.addFeatures(n);
312
+ const a = new E({
280
313
  source: s,
281
- style: z(e, n),
282
- zIndex: n.zIndex || 10
314
+ style: A(e, o),
315
+ zIndex: o.zIndex || 10
283
316
  });
284
- return i.set("name", e), i.set("type", "webgl"), r.addLayer(i), i;
317
+ return a.set("name", e), a.set("type", "webgl"), r.addLayer(a), a;
285
318
  }
286
- function Ze(e, t, r) {
287
- const n = new O({
319
+ function De(e, t, r) {
320
+ const o = new j({
288
321
  opacity: r.opacity || 1,
289
- source: pe(e, r),
322
+ source: je(e, r),
290
323
  zIndex: r.zIndex || 10
291
324
  });
292
- return n.set("name", e), t.addLayer(n), n;
325
+ return o.set("name", e), t.addLayer(o), o;
293
326
  }
294
- function Ce(e, t, r, n) {
327
+ function Ue(e, t, r, o) {
295
328
  if (!t || t.length === 0) return null;
296
- const o = new F({
297
- source: Te(e, t, n),
298
- style: z(e, n),
299
- zIndex: n.zIndex || 10
329
+ const n = new E({
330
+ source: ze(e, t, o),
331
+ style: A(e, o),
332
+ zIndex: o.zIndex || 10
300
333
  });
301
- return o.set("name", e), o.set("type", "webgl"), r.addLayer(o), o;
334
+ return n.set("name", e), n.set("type", "webgl"), r.addLayer(n), n;
302
335
  }
303
- function Ve(e, t, r, n) {
304
- const o = D(t), s = Fe(o, n.radius, { steps: 300, units: "meters" }), i = new p().readFeature(s, {
336
+ function We(e, t, r, o) {
337
+ const n = p(t), s = ke(n, o.radius, { steps: 300, units: "meters" }), a = new I().readFeature(s, {
305
338
  dataProjection: "EPSG:4326",
306
339
  featureProjection: "EPSG:4490"
307
- }), a = new T({ wrapX: !1 });
308
- a.addFeature(i);
309
- const c = new F({
310
- source: a,
311
- style: z(e, n),
312
- zIndex: n.zIndex ? n.zIndex : 10
340
+ }), c = new M({ wrapX: !1 });
341
+ c.addFeature(a);
342
+ const i = new E({
343
+ source: c,
344
+ style: A(e, o),
345
+ zIndex: o.zIndex ? o.zIndex : 10
313
346
  });
314
- return c.set("name", e), c.set("type", "webgl"), r.addLayer(c), c;
347
+ return i.set("name", e), i.set("type", "webgl"), r.addLayer(i), i;
315
348
  }
316
- function $e(e, t, r, n) {
317
- const o = document.createElement("div"), s = new le({
349
+ function He(e, t, r) {
350
+ const o = document.createElement("div"), n = new ye({
318
351
  element: o,
319
352
  stopEvent: !1,
320
- positioning: n.positioning || "bottom-center"
353
+ positioning: r.positioning || "bottom-center"
321
354
  });
322
- return s.set("name", e), s.set("type", "webgl"), r.addOverlay(s), { overlayer: s, content: o };
355
+ return n.set("name", e), n.set("type", "webgl"), t.addOverlay(n), { overlayer: n, content: o };
356
+ }
357
+ function Je(e, t, r) {
358
+ const o = new E({
359
+ source: new M({ wrapX: !1 }),
360
+ zIndex: r.zIndex ? r.zIndex : 10,
361
+ style: A(t, r)
362
+ });
363
+ return o.set("name", t), o.set("type", "webgl"), e.addLayer(o), o;
364
+ }
365
+ function Z(e, t) {
366
+ return e.getAllLayers().find((n) => n.get("name") === t);
323
367
  }
324
- const x = /* @__PURE__ */ new Map(), E = {}, S = {}, Ge = (e, t) => {
325
- x.has(e) && console.warn(`Map with target '${e}' already exists. Overwriting...`), x.set(e, t), E[e] && (E[e].forEach((r) => r(t)), delete E[e]), S[e] && (S[e].forEach((r) => r(t)), delete S[e]);
368
+ function Qe(e, t, r) {
369
+ const o = Z(e, t);
370
+ return o.setVisible(r), o;
371
+ }
372
+ const v = /* @__PURE__ */ new Map(), S = {}, P = {}, Xe = (e, t) => {
373
+ v.has(e) && console.warn(`Map with target '${e}' already exists. Overwriting...`), v.set(e, t), S[e] && (S[e].forEach((r) => r(t)), delete S[e]), P[e] && (P[e].forEach((r) => r(t)), delete P[e]);
326
374
  };
327
- function J(e) {
328
- const t = x.get(e);
329
- return t ? Promise.resolve(t) : (console.warn(`Map '${e}' not found. Make sure useMap() is called first.`), new Promise((r) => {
330
- S[e] = S[e] || [], S[e].push(r);
331
- }));
332
- }
333
- const Be = (e) => {
334
- x.has(e) && (x.delete(e), delete E[e]);
335
- }, Q = (e, t) => {
336
- const r = x.get(e);
375
+ function Y(e) {
376
+ const t = v.get(e);
377
+ return t ? Promise.resolve(t) : new Promise((r) => {
378
+ P[e] = P[e] || [], P[e].push(r);
379
+ });
380
+ }
381
+ const Ye = (e) => {
382
+ v.has(e) && (v.delete(e), delete S[e]);
383
+ }, K = (e, t) => {
384
+ const r = v.get(e);
337
385
  if (r) {
338
386
  t(r);
339
387
  return;
340
388
  }
341
- E[e] || (E[e] = []), E[e].push(t);
389
+ S[e] || (S[e] = []), S[e].push(t);
342
390
  };
343
- function qe(e, t = {}) {
391
+ function Ke(e, t = {}) {
344
392
  if (!e && !e.target)
345
- throw new Error("请传入地图容器");
393
+ throw new Error("is not a valid element");
346
394
  arguments.length === 1 && typeof e == "object" && (t = e, e = t.target);
347
- const n = Object.assign({
395
+ const o = Object.assign({
348
396
  zoom: 10,
349
397
  center: [104.064839, 30.548857],
350
398
  minZoom: 2,
351
399
  maxZoom: 19,
352
400
  projection: "EPSG:4326"
353
- }, t), o = new ce({
401
+ }, t), n = new ue({
354
402
  //地图容器div的ID
355
403
  target: e,
356
404
  //地图容器中加载的图层
357
405
  layers: [],
358
406
  //地图视图设置
359
- view: new ie({
360
- projection: n.projection,
407
+ view: new fe({
408
+ projection: o.projection,
361
409
  // 坐标系,有EPSG:4326和EPSG:3857
362
410
  //地图初始中心点
363
- center: n.center,
411
+ center: o.center,
364
412
  // 坐标
365
413
  //地图初始显示级别
366
- zoom: n.zoom,
367
- minZoom: n.minZoom,
368
- maxZoom: n.maxZoom
414
+ zoom: o.zoom,
415
+ minZoom: o.minZoom,
416
+ maxZoom: o.maxZoom
417
+ }),
418
+ controls: Pe({
419
+ zoom: !1,
420
+ rotate: !1,
421
+ attribution: !1
369
422
  })
370
423
  });
371
- return o.targetId = e, o;
424
+ return n.targetId = e, n;
372
425
  }
373
- function Ue(e, t, r, n) {
374
- H(e, t, r, k(A({}, n), { type: "Point" }));
426
+ function et(e, t, r, o) {
427
+ X(e, t, r, O(R({}, o), { type: "Point" }));
375
428
  }
376
- function Y(e, t, r) {
377
- return new Promise((n, o) => {
429
+ function ee(e, t, r) {
430
+ return new Promise((o, n) => {
378
431
  e.getView().animate(
379
432
  {
380
433
  center: t,
381
434
  duration: r.duration || 1e3,
382
- zoom: r.zoom || K(e),
435
+ zoom: r.zoom || re(e),
383
436
  rotation: r.rotation || 0,
384
437
  easing: r.easing
385
438
  },
386
- n
439
+ o
387
440
  );
388
441
  });
389
442
  }
390
- function X(e, t) {
391
- const r = (t.extend[0] + t.extend[2]) / 2, n = (t.extend[1] + t.extend[3]) / 2;
392
- return Y(e, [r, n], t);
443
+ function te(e, t) {
444
+ const r = (t.extend[0] + t.extend[2]) / 2, o = (t.extend[1] + t.extend[3]) / 2;
445
+ return ee(e, [r, o], t);
393
446
  }
394
- function We(e, t, r) {
395
- const n = t.getGeometry().getExtent();
396
- return X(e, k(A({}, r), { extend: n }));
447
+ function tt(e, t, r) {
448
+ const o = t.getGeometry().getExtent();
449
+ return te(e, O(R({}, r), { extend: o }));
397
450
  }
398
- function De(e) {
451
+ function rt(e) {
399
452
  return e.getView().getProjection();
400
453
  }
401
- function K(e) {
454
+ function re(e) {
402
455
  return e.getView().getZoom();
403
456
  }
404
- function He(e, t) {
457
+ function nt(e, t) {
405
458
  e.getView().setZoom(t);
406
459
  }
407
- function Je(e, t) {
460
+ function ot(e, t) {
408
461
  e.un("click", () => {
409
462
  }), e.un("pointermove", () => {
410
- }), Be(t);
463
+ }), Ye(t);
411
464
  }
412
- let P = null;
413
- function Qe(e, t = {}) {
414
- const r = new p();
415
- P = new Pe({
416
- condition: Me,
465
+ let F = null;
466
+ function st(e, t = {}) {
467
+ const r = new I();
468
+ F = new Ee({
469
+ condition: ve,
417
470
  multi: t.multi || !1,
418
- style: (a) => {
471
+ style: (c) => {
419
472
  if (typeof t.getStyle == "function") {
420
- const c = a.get("layerName");
421
- return t.getStyle(c, a);
473
+ const i = c.get("layerName");
474
+ return t.getStyle(i, c);
422
475
  } else
423
476
  return t.style;
424
477
  },
425
478
  // 高亮选中样式
426
479
  // 过滤:只允许配置中的图层被选中 (仅对 Vector 有效)
427
- layers: t.layers ? (a) => t.layers.includes(a) : void 0
428
- }), e.addInteraction(P);
429
- const n = P.getFeatures(), o = (a) => v(null, null, function* () {
430
- const c = (t.layers || e.getLayers().getArray()).filter((w) => {
480
+ layers: t.layers ? (c) => t.layers.includes(c) : void 0
481
+ }), e.addInteraction(F);
482
+ const o = F.getFeatures(), n = (c) => T(null, null, function* () {
483
+ const i = (t.layers || e.getLayers().getArray()).filter((w) => {
431
484
  const h = w.getSource();
432
- return w.getVisible() && (h instanceof j || h instanceof U);
485
+ return w.getVisible() && (h instanceof N || h instanceof W);
433
486
  });
434
- if (c.length === 0) return;
435
- const u = e.getView(), m = c.map((w) => v(null, null, function* () {
436
- const f = w.getSource().getFeatureInfoUrl(a.coordinate, u.getResolution(), u.getProjection(), {
487
+ if (i.length === 0) return;
488
+ const l = e.getView(), m = i.map((w) => T(null, null, function* () {
489
+ const f = w.getSource().getFeatureInfoUrl(c.coordinate, l.getResolution(), l.getProjection(), {
437
490
  INFO_FORMAT: "application/json",
438
491
  // 必须是 JSON 才能转 Feature
439
492
  FEATURE_COUNT: 1
@@ -444,52 +497,52 @@ function Qe(e, t = {}) {
444
497
  if (b.features && b.features.length > 0) {
445
498
  const d = r.readFeatures(b);
446
499
  return d.forEach((y) => {
447
- y.set("wms_layer_source", w), y.set("wms_event_source", a), y.set("layerName", w.get("name"));
500
+ y.set("wms_layer_source", w), y.set("wms_event_source", c), y.set("layerName", w.get("name"));
448
501
  }), d;
449
502
  }
450
- } catch (M) {
451
- console.warn(M);
503
+ } catch (L) {
504
+ console.warn(L);
452
505
  }
453
506
  return [];
454
- })), l = (yield Promise.all(m)).flat();
455
- l.length > 0 && (t.multi, n.extend(l), P.dispatchEvent({
507
+ })), u = (yield Promise.all(m)).flat();
508
+ u.length > 0 && (t.multi, o.extend(u), F.dispatchEvent({
456
509
  type: "select",
457
- selected: l,
510
+ selected: u,
458
511
  deselected: [],
459
- mapBrowserEvent: a
512
+ mapBrowserEvent: c
460
513
  }));
461
514
  });
462
- e.on("singleclick", o);
515
+ e.on("singleclick", n);
463
516
  const s = /* @__PURE__ */ new Set();
464
- P.on("select", (a) => {
465
- const c = n.getArray();
466
- if (c.length > 0) {
467
- const u = c.map((m) => ({
517
+ F.on("select", (c) => {
518
+ const i = o.getArray();
519
+ if (i.length > 0) {
520
+ const l = i.map((m) => ({
468
521
  feature: m,
469
522
  properties: m.getProperties(),
470
523
  // 如果是 WMS 注入的,我们在上面 set 过了;如果是 Vector,用 native 方法获取
471
- layer: m.get("wms_layer_source") || P.getLayer(m),
472
- event: m.get("wms_event_source") || a
524
+ layer: m.get("wms_layer_source") || F.getLayer(m),
525
+ event: m.get("wms_event_source") || c
473
526
  }));
474
- i(u);
527
+ a(l);
475
528
  } else
476
- i(null);
529
+ a(null);
477
530
  });
478
- const i = (a) => s.forEach((c) => c(a));
531
+ const a = (c) => s.forEach((i) => i(c));
479
532
  return {
480
- onSelect: (a) => (s.add(a), () => s.delete(a)),
533
+ onSelect: (c) => (s.add(c), () => s.delete(c)),
481
534
  clear: () => {
482
- s.clear(), n.clear();
535
+ s.clear(), o.clear();
483
536
  },
484
537
  destroy: () => {
485
- e.removeInteraction(P), e.un("singleclick", o), s.clear();
538
+ e.removeInteraction(F), e.un("singleclick", n), s.clear();
486
539
  }
487
540
  };
488
541
  }
489
- function Ye(e, t = {}) {
490
- var L;
491
- const r = new p(), n = (L = t.debounceTime) != null ? L : 200, o = new T(), s = new F({
492
- source: o,
542
+ function at(e, t = {}) {
543
+ var x;
544
+ const r = new I(), o = (x = t.debounceTime) != null ? x : 200, n = new M(), s = new E({
545
+ source: n,
493
546
  map: e,
494
547
  style: t.style,
495
548
  // 直接透传用户的样式配置
@@ -498,33 +551,33 @@ function Ye(e, t = {}) {
498
551
  properties: { title: "JG_HOVER_LAYER" }
499
552
  // 标记一下,防止自己拾取自己
500
553
  });
501
- let i = null, a = null;
502
- const c = /* @__PURE__ */ new Set(), u = (l, w, h) => {
503
- const f = l[0];
504
- if (i !== f)
505
- if (i = f, o.clear(), f ? (o.addFeature(f), t.cursor !== !1 && (e.getTargetElement().style.cursor = "pointer")) : t.cursor !== !1 && (e.getTargetElement().style.cursor = ""), f) {
506
- const M = {
554
+ let a = null, c = null;
555
+ const i = /* @__PURE__ */ new Set(), l = (u, w, h) => {
556
+ const f = u[0];
557
+ if (a !== f)
558
+ if (a = f, n.clear(), f ? (n.addFeature(f), t.cursor !== !1 && (e.getTargetElement().style.cursor = "pointer")) : t.cursor !== !1 && (e.getTargetElement().style.cursor = ""), f) {
559
+ const L = {
507
560
  feature: f,
508
561
  layer: w,
509
562
  properties: f.getProperties(),
510
563
  coordinate: h
511
564
  };
512
- c.forEach((b) => b([M]));
565
+ i.forEach((b) => b([L]));
513
566
  } else
514
- c.forEach((M) => M(null));
515
- }, m = (l) => {
516
- if (l.dragging) return;
517
- const w = l.pixel, h = l.coordinate;
567
+ i.forEach((L) => L(null));
568
+ }, m = (u) => {
569
+ if (u.dragging) return;
570
+ const w = u.pixel, h = u.coordinate;
518
571
  let f = !1;
519
572
  if (e.forEachFeatureAtPixel(w, (d, y) => {
520
- f || y !== s && (t.layers && !t.layers.includes(y) || (f = !0, a && clearTimeout(a), u([d], y, h)));
573
+ f || y !== s && (t.layers && !t.layers.includes(y) || (f = !0, c && clearTimeout(c), l([d], y, h)));
521
574
  }), f) return;
522
- i && (i = null, o.clear(), e.getTargetElement().style.cursor = "", c.forEach((d) => d(null))), a && clearTimeout(a);
575
+ a && (a = null, n.clear(), e.getTargetElement().style.cursor = "", i.forEach((d) => d(null))), c && clearTimeout(c);
523
576
  const b = (t.layers || e.getLayers().getArray()).filter((d) => {
524
577
  const y = d.getSource();
525
- return d.getVisible() && (y instanceof j || y instanceof U);
578
+ return d.getVisible() && (y instanceof N || y instanceof W);
526
579
  });
527
- b.length !== 0 && (a = setTimeout(() => v(null, null, function* () {
580
+ b.length !== 0 && (c = setTimeout(() => T(null, null, function* () {
528
581
  const d = e.getView();
529
582
  for (const y of b) {
530
583
  const _ = y.getSource().getFeatureInfoUrl(h, d.getResolution(), d.getProjection(), {
@@ -533,59 +586,67 @@ function Ye(e, t = {}) {
533
586
  });
534
587
  if (_)
535
588
  try {
536
- const I = yield (yield fetch(_)).json();
537
- if (I.features && I.features.length > 0) {
538
- const N = r.readFeatures(I);
539
- N.forEach((te) => te.set("wms_layer_source", y)), u(N, y, h);
589
+ const k = yield (yield fetch(_)).json();
590
+ if (k.features && k.features.length > 0) {
591
+ const C = r.readFeatures(k);
592
+ C.forEach((oe) => oe.set("wms_layer_source", y)), l(C, y, h);
540
593
  return;
541
594
  }
542
- } catch (ee) {
595
+ } catch (ne) {
543
596
  }
544
597
  }
545
- }), n));
598
+ }), o));
546
599
  };
547
600
  return e.on("pointermove", m), {
548
- onHover: (l) => (c.add(l), () => c.delete(l)),
601
+ onHover: (u) => (i.add(u), () => i.delete(u)),
549
602
  clear: () => {
550
- o.clear(), i = null;
603
+ n.clear(), a = null;
551
604
  },
552
605
  destroy: () => {
553
- e.un("pointermove", m), e.removeLayer(s), c.clear(), a && clearTimeout(a);
606
+ e.un("pointermove", m), e.removeLayer(s), i.clear(), c && clearTimeout(c);
554
607
  }
555
608
  };
556
609
  }
557
- const ft = (e, t) => {
558
- const r = qe(e, t);
559
- ze(r, t.baseLayers);
560
- const n = {
610
+ const St = (e, t) => {
611
+ const r = Ke(e, t);
612
+ Ge(r, t.baseLayers);
613
+ const o = {
561
614
  targetId: e,
562
615
  instance: r,
563
616
  // 暴露原始实例以备不时之需
564
- addMarker: (o, s, i) => Ue(r, o, s, i),
565
- createLayer: (o, s, i) => H(r, o, s, i),
566
- removeLayer: (o) => _e(r, o),
567
- useSelect: (o) => Qe(r, o),
568
- useHover: (o) => Ye(r, o),
569
- flyTo: (o, s) => Y(r, o, s),
570
- flyToByExtent: (o) => X(r, o),
571
- flyToByFeature: (o, s) => We(r, o, s),
572
- getProjection: () => De(r),
573
- getZoom: () => K(r),
574
- setZoom: (o) => He(r, o),
575
- getMapContext: (o) => J(o),
576
- onMapReady: (o, s) => Q(o, s),
577
- destroyMap: () => Je(r, e)
617
+ addMarker: (n, s, a) => et(r, n, s, a),
618
+ createLayer: (n, s, a) => X(r, n, s, a),
619
+ createBlankLayer: (n, s) => Je(r, n, s),
620
+ visibleLayer: (n, s) => Qe(r, n, s),
621
+ removeLayer: (n) => qe(r, n),
622
+ getLonLat: (n) => p(n),
623
+ getLayerByName: (n) => Z(r, n),
624
+ getSourceByName: (n) => Q(r, n),
625
+ useSelect: (n) => st(r, n),
626
+ useHover: (n) => at(r, n),
627
+ queryFeature: (n, s) => Oe(r, n, s),
628
+ lightFeature: (n, s, a, c) => J(n, s, a, c),
629
+ flashFeature: (n, s, a) => Re(n, s, a),
630
+ flyTo: (n, s) => ee(r, n, s),
631
+ flyToByExtent: (n) => te(r, n),
632
+ flyToByFeature: (n, s) => tt(r, n, s),
633
+ getProjection: () => rt(r),
634
+ getZoom: () => re(r),
635
+ setZoom: (n) => nt(r, n),
636
+ getMapContext: (n) => Y(n),
637
+ onMapReady: (n, s) => K(n, s),
638
+ destroyMap: () => ot(r, e)
578
639
  };
579
- return Ge(e, n), n;
640
+ return Xe(e, o), o;
580
641
  };
581
- function yt(e, t) {
582
- Q(e, t);
642
+ function xt(e, t) {
643
+ K(e, t);
583
644
  }
584
- function gt(e) {
585
- return J(e);
645
+ function Pt(e) {
646
+ return Y(e);
586
647
  }
587
648
  export {
588
- gt as getMapContext,
589
- yt as onMapReady,
590
- ft as useMap
649
+ Pt as getMapContext,
650
+ xt as onMapReady,
651
+ St as useMap
591
652
  };