jgis 1.0.2 → 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
@@ -27,17 +27,18 @@ var T = (e, t, r) => new Promise((o, n) => {
27
27
  c((r = r.apply(e, t)).next());
28
28
  });
29
29
  import { Map as ue, View as fe } from "ol";
30
- import { Tile as N, Vector as E } from "ol/layer";
31
- import { Vector as v, TileWMS as j, XYZ as G, ImageWMS as W } from "ol/source";
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
32
  import { GeoJSON as I } from "ol/format";
33
33
  import ye from "ol/Overlay";
34
34
  import { Geometry as ge, Polygon as me, MultiPolygon as de, MultiLineString as we, LineString as he, Point as be } from "ol/geom";
35
35
  import Le from "ol/Feature";
36
36
  import "ol/extent";
37
37
  import { Style as Fe, Circle as Se, Fill as xe } 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 = {
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),
@@ -72,7 +73,7 @@ function q(e, t, r = {}) {
72
73
  coordinates: e
73
74
  }, t, r);
74
75
  }
75
- function ve(e, t, r = {}) {
76
+ function Te(e, t, r = {}) {
76
77
  for (const n of e) {
77
78
  if (n.length < 4)
78
79
  throw new Error(
@@ -89,8 +90,8 @@ function ve(e, t, r = {}) {
89
90
  coordinates: e
90
91
  }, t, r);
91
92
  }
92
- function Te(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;
@@ -104,7 +105,7 @@ function z(e) {
104
105
  function D(e) {
105
106
  return !isNaN(e) && e !== null && !Array.isArray(e);
106
107
  }
107
- function Ie(e) {
108
+ function pe(e) {
108
109
  if (!e)
109
110
  throw new Error("coord is required");
110
111
  if (!Array.isArray(e)) {
@@ -117,8 +118,8 @@ function Ie(e) {
117
118
  return [...e];
118
119
  throw new Error("coord must be GeoJSON Point or an Array of numbers");
119
120
  }
120
- function pe(e, t, r, o = {}) {
121
- const n = Ie(e), s = z(n[0]), a = z(n[1]), c = z(r), i = Te(t, o.units), l = Math.asin(
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(
122
123
  Math.sin(a) * Math.cos(i) + Math.cos(a) * Math.sin(i) * Math.cos(c)
123
124
  ), m = s + Math.atan2(
124
125
  Math.sin(c) * Math.sin(i) * Math.cos(a),
@@ -126,16 +127,16 @@ function pe(e, t, r, o = {}) {
126
127
  ), x = $(m), u = $(l);
127
128
  return n[2] !== void 0 ? q([x, u, n[2]], o.properties) : q([x, u], o.properties);
128
129
  }
129
- function Ae(e, t, r = {}) {
130
+ function ke(e, t, r = {}) {
130
131
  const o = r.steps || 64, n = r.properties ? r.properties : !Array.isArray(e) && e.type === "Feature" && e.properties ? e.properties : {}, s = [];
131
132
  for (let a = 0; a < o; a++)
132
133
  s.push(
133
- pe(e, t, a * -360 / o, r).geometry.coordinates
134
+ Ae(e, t, a * -360 / o, r).geometry.coordinates
134
135
  );
135
- return s.push(s[0]), ve([s], n);
136
+ return s.push(s[0]), Te([s], n);
136
137
  }
137
- function p(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
141
  function U(e, t) {
141
142
  e.getLayers().getArray().forEach((o) => {
@@ -146,7 +147,7 @@ function J(e, t, r, o = !1) {
146
147
  const n = o ? r.style || r.getStyle(e, t) : void 0, s = o ? 999 : -1;
147
148
  n && typeof n.setZIndex == "function" && n.setZIndex(s), t.setStyle(n);
148
149
  }
149
- function ke(e, t, r) {
150
+ function Re(e, t, r) {
150
151
  if (!t) return;
151
152
  const o = r.time || 300;
152
153
  let n = Date.now(), s = !1, a = 0;
@@ -160,7 +161,7 @@ function ke(e, t, r) {
160
161
  t.running = !1, cancelAnimationFrame(a), t.setStyle(void 0);
161
162
  };
162
163
  }
163
- function Re(e, t, r) {
164
+ function Oe(e, t, r) {
164
165
  var a, c;
165
166
  if (!r) return;
166
167
  let o = p(r);
@@ -170,7 +171,7 @@ function Re(e, t, r) {
170
171
  return l && l instanceof ge && typeof l.intersectsCoordinate == "function" ? l.intersectsCoordinate(o) : !1;
171
172
  }) : void 0;
172
173
  }
173
- function Oe(e, t, r) {
174
+ function ze(e, t, r) {
174
175
  const o = [];
175
176
  let n;
176
177
  const s = r.type || "Point";
@@ -180,16 +181,16 @@ function Oe(e, t, r) {
180
181
  n = Ne(c);
181
182
  break;
182
183
  case "LineString":
183
- n = je(c);
184
+ n = Ze(c);
184
185
  break;
185
186
  case "MultiLineString":
186
- n = Ze(c);
187
+ n = _e(c);
187
188
  break;
188
189
  case "MultiPolygon":
189
- n = _e(c);
190
+ n = Ce(c);
190
191
  break;
191
192
  case "Polygon":
192
- n = Ce(c);
193
+ n = Be(c);
193
194
  break;
194
195
  }
195
196
  if (!n) return;
@@ -199,11 +200,11 @@ function Oe(e, t, r) {
199
200
  });
200
201
  i.set("layerName", e), o.push(i);
201
202
  });
202
- const a = new v();
203
+ const a = new M();
203
204
  return o.length > 0 && a.addFeatures(o), a;
204
205
  }
205
- function ze(e, t) {
206
- 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({
207
208
  url: t.url,
208
209
  params: {
209
210
  LAYERS: t.layers,
@@ -222,23 +223,23 @@ function Ne(e) {
222
223
  if (t)
223
224
  return new be(t);
224
225
  }
225
- function je(e) {
226
+ function Ze(e) {
226
227
  return new he(e.coordinates);
227
228
  }
228
- function Ze(e) {
229
+ function _e(e) {
229
230
  return new we(e.coordinates);
230
231
  }
231
- function _e(e) {
232
+ function Ce(e) {
232
233
  return new de(e.coordinates);
233
234
  }
234
- function Ce(e) {
235
+ function Be(e) {
235
236
  return new me(e.coordinates);
236
237
  }
237
238
  function A(e, t) {
238
239
  let r = null;
239
- return t.style ? r = t.style : t.getStyle ? r = (o, n) => t.getStyle(e, o, n) : r = Be(), r;
240
+ return t.style ? r = t.style : t.getStyle ? r = (o, n) => t.getStyle(e, o, n) : r = Ve(), r;
240
241
  }
241
- function Be() {
242
+ function Ve() {
242
243
  return (t, r) => new Fe({
243
244
  image: new Se({
244
245
  radius: 5,
@@ -246,8 +247,8 @@ function Be() {
246
247
  })
247
248
  });
248
249
  }
249
- function Ve(e, t = {}) {
250
- const r = t.token || "dadcbbdb5206b626a29ca739686b3087", o = t.baseType || "img", n = t.noteType || "cia", s = new N({
250
+ function Ge(e, t = {}) {
251
+ const r = t.token || "dadcbbdb5206b626a29ca739686b3087", o = t.baseType || "img", n = t.noteType || "cia", s = new j({
251
252
  className: "tdt-base-layer",
252
253
  source: new G({
253
254
  url: `http://t0.tianditu.com/DataServer?T=${o}_w&x={x}&y={y}&l={z}&tk=${r}`,
@@ -257,7 +258,7 @@ function Ve(e, t = {}) {
257
258
  zIndex: t.zIndex || 1
258
259
  });
259
260
  s.set("name", "tdt-base-layer");
260
- const a = new N({
261
+ const a = new j({
261
262
  className: "tdt-base-layer",
262
263
  source: new G({
263
264
  url: `http://t0.tianditu.com/DataServer?T=${n}_w&x={x}&y={y}&l={z}&tk=${r}`,
@@ -274,39 +275,39 @@ function X(e, t, r, o) {
274
275
  let s;
275
276
  switch (n) {
276
277
  case "GeoJSON":
277
- s = qe(t, r, e, o);
278
+ s = $e(t, r, e, o);
278
279
  break;
279
280
  case "Wms":
280
- s = $e(t, e, o);
281
+ s = De(t, e, o);
281
282
  break;
282
283
  case "Point":
283
284
  case "LineString":
284
285
  case "MultiLineString":
285
286
  case "Polygon":
286
287
  case "MultiPolygon":
287
- s = De(t, r, e, o);
288
+ s = Ue(t, r, e, o);
288
289
  break;
289
290
  case "Circle":
290
- s = Ue(t, r, e, o);
291
+ s = We(t, r, e, o);
291
292
  break;
292
293
  case "Overlay":
293
- s = We(t, e, o);
294
+ s = He(t, e, o);
294
295
  break;
295
296
  }
296
297
  return s;
297
298
  }
298
- function Ge(e, t) {
299
+ function qe(e, t) {
299
300
  Array.isArray(t) ? t.forEach((r) => {
300
301
  U(e, r);
301
302
  }) : U(e, t);
302
303
  }
303
- function qe(e, t, r, o) {
304
+ function $e(e, t, r, o) {
304
305
  console.log(typeof t, t);
305
306
  const n = new I().readFeatures(t, {
306
307
  dataProjection: "EPSG:4326",
307
308
  featureProjection: "EPSG:4326"
308
309
  // 或 'EPSG:3857',看你的地图
309
- }), s = new v();
310
+ }), s = new M();
310
311
  s.addFeatures(n);
311
312
  const a = new E({
312
313
  source: s,
@@ -315,28 +316,28 @@ function qe(e, t, r, o) {
315
316
  });
316
317
  return a.set("name", e), a.set("type", "webgl"), r.addLayer(a), a;
317
318
  }
318
- function $e(e, t, r) {
319
- const o = new N({
319
+ function De(e, t, r) {
320
+ const o = new j({
320
321
  opacity: r.opacity || 1,
321
- source: ze(e, r),
322
+ source: je(e, r),
322
323
  zIndex: r.zIndex || 10
323
324
  });
324
325
  return o.set("name", e), t.addLayer(o), o;
325
326
  }
326
- function De(e, t, r, o) {
327
+ function Ue(e, t, r, o) {
327
328
  if (!t || t.length === 0) return null;
328
329
  const n = new E({
329
- source: Oe(e, t, o),
330
+ source: ze(e, t, o),
330
331
  style: A(e, o),
331
332
  zIndex: o.zIndex || 10
332
333
  });
333
334
  return n.set("name", e), n.set("type", "webgl"), r.addLayer(n), n;
334
335
  }
335
- function Ue(e, t, r, o) {
336
- const n = p(t), s = Ae(n, o.radius, { steps: 300, units: "meters" }), a = new I().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, {
337
338
  dataProjection: "EPSG:4326",
338
339
  featureProjection: "EPSG:4490"
339
- }), c = new v({ wrapX: !1 });
340
+ }), c = new M({ wrapX: !1 });
340
341
  c.addFeature(a);
341
342
  const i = new E({
342
343
  source: c,
@@ -345,7 +346,7 @@ function Ue(e, t, r, o) {
345
346
  });
346
347
  return i.set("name", e), i.set("type", "webgl"), r.addLayer(i), i;
347
348
  }
348
- function We(e, t, r) {
349
+ function He(e, t, r) {
349
350
  const o = document.createElement("div"), n = new ye({
350
351
  element: o,
351
352
  stopEvent: !1,
@@ -353,9 +354,9 @@ function We(e, t, r) {
353
354
  });
354
355
  return n.set("name", e), n.set("type", "webgl"), t.addOverlay(n), { overlayer: n, content: o };
355
356
  }
356
- function He(e, t, r) {
357
+ function Je(e, t, r) {
357
358
  const o = new E({
358
- source: new v({ wrapX: !1 }),
359
+ source: new M({ wrapX: !1 }),
359
360
  zIndex: r.zIndex ? r.zIndex : 10,
360
361
  style: A(t, r)
361
362
  });
@@ -364,32 +365,32 @@ function He(e, t, r) {
364
365
  function Z(e, t) {
365
366
  return e.getAllLayers().find((n) => n.get("name") === t);
366
367
  }
367
- function Je(e, t, r) {
368
+ function Qe(e, t, r) {
368
369
  const o = Z(e, t);
369
370
  return o.setVisible(r), o;
370
371
  }
371
- const P = /* @__PURE__ */ new Map(), S = {}, M = {}, Qe = (e, t) => {
372
- P.has(e) && console.warn(`Map with target '${e}' already exists. Overwriting...`), P.set(e, t), S[e] && (S[e].forEach((r) => r(t)), delete S[e]), M[e] && (M[e].forEach((r) => r(t)), delete M[e]);
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]);
373
374
  };
374
375
  function Y(e) {
375
- const t = P.get(e);
376
- return t ? Promise.resolve(t) : (console.warn(`Map '${e}' not found. Make sure useMap() is called first.`), new Promise((r) => {
377
- M[e] = M[e] || [], M[e].push(r);
378
- }));
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
+ });
379
380
  }
380
- const Xe = (e) => {
381
- P.has(e) && (P.delete(e), delete S[e]);
381
+ const Ye = (e) => {
382
+ v.has(e) && (v.delete(e), delete S[e]);
382
383
  }, K = (e, t) => {
383
- const r = P.get(e);
384
+ const r = v.get(e);
384
385
  if (r) {
385
386
  t(r);
386
387
  return;
387
388
  }
388
389
  S[e] || (S[e] = []), S[e].push(t);
389
390
  };
390
- function Ye(e, t = {}) {
391
+ function Ke(e, t = {}) {
391
392
  if (!e && !e.target)
392
- throw new Error("请传入地图容器");
393
+ throw new Error("is not a valid element");
393
394
  arguments.length === 1 && typeof e == "object" && (t = e, e = t.target);
394
395
  const o = Object.assign({
395
396
  zoom: 10,
@@ -413,11 +414,16 @@ function Ye(e, t = {}) {
413
414
  zoom: o.zoom,
414
415
  minZoom: o.minZoom,
415
416
  maxZoom: o.maxZoom
417
+ }),
418
+ controls: Pe({
419
+ zoom: !1,
420
+ rotate: !1,
421
+ attribution: !1
416
422
  })
417
423
  });
418
424
  return n.targetId = e, n;
419
425
  }
420
- function Ke(e, t, r, o) {
426
+ function et(e, t, r, o) {
421
427
  X(e, t, r, O(R({}, o), { type: "Point" }));
422
428
  }
423
429
  function ee(e, t, r) {
@@ -438,29 +444,29 @@ function te(e, t) {
438
444
  const r = (t.extend[0] + t.extend[2]) / 2, o = (t.extend[1] + t.extend[3]) / 2;
439
445
  return ee(e, [r, o], t);
440
446
  }
441
- function et(e, t, r) {
447
+ function tt(e, t, r) {
442
448
  const o = t.getGeometry().getExtent();
443
449
  return te(e, O(R({}, r), { extend: o }));
444
450
  }
445
- function tt(e) {
451
+ function rt(e) {
446
452
  return e.getView().getProjection();
447
453
  }
448
454
  function re(e) {
449
455
  return e.getView().getZoom();
450
456
  }
451
- function rt(e, t) {
457
+ function nt(e, t) {
452
458
  e.getView().setZoom(t);
453
459
  }
454
- function nt(e, t) {
460
+ function ot(e, t) {
455
461
  e.un("click", () => {
456
462
  }), e.un("pointermove", () => {
457
- }), Xe(t);
463
+ }), Ye(t);
458
464
  }
459
465
  let F = null;
460
- function ot(e, t = {}) {
466
+ function st(e, t = {}) {
461
467
  const r = new I();
462
- F = new Pe({
463
- condition: Me,
468
+ F = new Ee({
469
+ condition: ve,
464
470
  multi: t.multi || !1,
465
471
  style: (c) => {
466
472
  if (typeof t.getStyle == "function") {
@@ -476,7 +482,7 @@ function ot(e, t = {}) {
476
482
  const o = F.getFeatures(), n = (c) => T(null, null, function* () {
477
483
  const i = (t.layers || e.getLayers().getArray()).filter((w) => {
478
484
  const h = w.getSource();
479
- return w.getVisible() && (h instanceof j || h instanceof W);
485
+ return w.getVisible() && (h instanceof N || h instanceof W);
480
486
  });
481
487
  if (i.length === 0) return;
482
488
  const l = e.getView(), m = i.map((w) => T(null, null, function* () {
@@ -533,9 +539,9 @@ function ot(e, t = {}) {
533
539
  }
534
540
  };
535
541
  }
536
- function st(e, t = {}) {
542
+ function at(e, t = {}) {
537
543
  var x;
538
- const r = new I(), o = (x = t.debounceTime) != null ? x : 200, n = new v(), s = new E({
544
+ const r = new I(), o = (x = t.debounceTime) != null ? x : 200, n = new M(), s = new E({
539
545
  source: n,
540
546
  map: e,
541
547
  style: t.style,
@@ -569,7 +575,7 @@ function st(e, t = {}) {
569
575
  a && (a = null, n.clear(), e.getTargetElement().style.cursor = "", i.forEach((d) => d(null))), c && clearTimeout(c);
570
576
  const b = (t.layers || e.getLayers().getArray()).filter((d) => {
571
577
  const y = d.getSource();
572
- return d.getVisible() && (y instanceof j || y instanceof W);
578
+ return d.getVisible() && (y instanceof N || y instanceof W);
573
579
  });
574
580
  b.length !== 0 && (c = setTimeout(() => T(null, null, function* () {
575
581
  const d = e.getView();
@@ -601,46 +607,46 @@ function st(e, t = {}) {
601
607
  }
602
608
  };
603
609
  }
604
- const Lt = (e, t) => {
605
- const r = Ye(e, t);
606
- Ve(r, t.baseLayers);
610
+ const St = (e, t) => {
611
+ const r = Ke(e, t);
612
+ Ge(r, t.baseLayers);
607
613
  const o = {
608
614
  targetId: e,
609
615
  instance: r,
610
616
  // 暴露原始实例以备不时之需
611
- addMarker: (n, s, a) => Ke(r, n, s, a),
617
+ addMarker: (n, s, a) => et(r, n, s, a),
612
618
  createLayer: (n, s, a) => X(r, n, s, a),
613
- createBlankLayer: (n, s) => He(r, n, s),
614
- visibleLayer: (n, s) => Je(r, n, s),
615
- removeLayer: (n) => Ge(r, n),
619
+ createBlankLayer: (n, s) => Je(r, n, s),
620
+ visibleLayer: (n, s) => Qe(r, n, s),
621
+ removeLayer: (n) => qe(r, n),
616
622
  getLonLat: (n) => p(n),
617
623
  getLayerByName: (n) => Z(r, n),
618
624
  getSourceByName: (n) => Q(r, n),
619
- useSelect: (n) => ot(r, n),
620
- useHover: (n) => st(r, n),
621
- queryFeature: (n, s) => Re(r, n, s),
625
+ useSelect: (n) => st(r, n),
626
+ useHover: (n) => at(r, n),
627
+ queryFeature: (n, s) => Oe(r, n, s),
622
628
  lightFeature: (n, s, a, c) => J(n, s, a, c),
623
- flashFeature: (n, s, a) => ke(n, s, a),
629
+ flashFeature: (n, s, a) => Re(n, s, a),
624
630
  flyTo: (n, s) => ee(r, n, s),
625
631
  flyToByExtent: (n) => te(r, n),
626
- flyToByFeature: (n, s) => et(r, n, s),
627
- getProjection: () => tt(r),
632
+ flyToByFeature: (n, s) => tt(r, n, s),
633
+ getProjection: () => rt(r),
628
634
  getZoom: () => re(r),
629
- setZoom: (n) => rt(r, n),
635
+ setZoom: (n) => nt(r, n),
630
636
  getMapContext: (n) => Y(n),
631
637
  onMapReady: (n, s) => K(n, s),
632
- destroyMap: () => nt(r, e)
638
+ destroyMap: () => ot(r, e)
633
639
  };
634
- return Qe(e, o), o;
640
+ return Xe(e, o), o;
635
641
  };
636
- function Ft(e, t) {
642
+ function xt(e, t) {
637
643
  K(e, t);
638
644
  }
639
- function St(e) {
645
+ function Pt(e) {
640
646
  return Y(e);
641
647
  }
642
648
  export {
643
- St as getMapContext,
644
- Ft as onMapReady,
645
- Lt as useMap
649
+ Pt as getMapContext,
650
+ xt as onMapReady,
651
+ St as useMap
646
652
  };
@@ -4,6 +4,7 @@ import { Layer } from 'ol/layer';
4
4
  import { FeatureLike } from 'ol/Feature';
5
5
  import { HoverOptions, SelectOptions, UseHoverResult, UseSelectResult } from './interaction';
6
6
  import { Source } from 'ol/source';
7
+ import { Projection } from 'ol/proj';
7
8
  export interface BaseLayerOptions {
8
9
  token?: string;
9
10
  maxZoom?: number;
@@ -77,13 +78,13 @@ export interface MapContext {
77
78
  queryFeature: (layerName: string, properties: any) => FeatureLike;
78
79
  useSelect: (options: SelectOptions) => UseSelectResult;
79
80
  useHover: (options: HoverOptions) => UseHoverResult;
80
- flyTo: (coordinate: [number, number], options: flyOptions) => void;
81
- flyToByExtent: (options: flyOptions) => void;
82
- flyToByFeature: (feature: Feature, options: flyOptions) => void;
83
- getProjection: () => void;
81
+ flyTo: (coordinate: [number, number], options: flyOptions) => Promise<boolean>;
82
+ flyToByExtent: (options: flyOptions) => Promise<boolean>;
83
+ flyToByFeature: (feature: Feature, options: flyOptions) => Promise<boolean>;
84
+ getProjection: () => Projection;
84
85
  getZoom: () => number;
85
86
  setZoom: (zoom: number) => void;
86
87
  getMapContext: (id: string) => Promise<MapContext>;
87
- onMapReady: (id: string, callback: () => void) => void;
88
- destroyMap: (id: string) => void;
88
+ onMapReady: (id: string, callback: (ctx: MapContext) => void) => void;
89
+ destroyMap: (map: MapInstance, id: string) => void;
89
90
  }
@@ -19,7 +19,10 @@ type dataType = {
19
19
  * @param data 数据
20
20
  * @returns [经度, 纬度]
21
21
  */
22
- export declare function getLonLat(data: dataType): [number, number];
22
+ export declare function getLonLat(data: dataType, options?: {
23
+ lonLabel: string;
24
+ latLabel: string;
25
+ }): [number, number];
23
26
  /**
24
27
  * 根据图层名称删除图层
25
28
  * @param map 地图实例
package/dist/3d/core.d.ts CHANGED
@@ -1,19 +1,50 @@
1
+ import { Coordinates, flyOptions } from './types';
1
2
  import * as Cesium from 'cesium';
2
3
  /**
3
4
  * 创建Viewer
4
5
  *
5
- * @param {String} [divStr] Cesium.viewer对应的DOM元素名:<div id="cesiumContainer"></div>
6
+ * @param {String} [el] Cesium.viewer对应的DOM元素名:<div id="cesiumContainer"></div>
6
7
  * @param {String} [terrainUrl] 地形链接
7
8
  */
8
- export declare function CreateViewer(el: HTMLElement, terrainUrl?: string): Cesium.Viewer;
9
- /**
10
- * 初始化地图
11
- * @param {Cesium.Viewer} viewer
12
- */
13
- export declare function createBaseLayer(viewer: Cesium.Viewer, options: any): void;
9
+ export declare function createViewer(el: string, options?: any): Cesium.Viewer;
14
10
  /**
15
11
  * 添加标记
16
12
  * @param {Cesium.Viewer} viewer
13
+ * @param {stringr} layerName
14
+ * @param points 数据
17
15
  * @returns {void}
18
16
  */
19
- export declare function addMarker(viewer: Cesium.Viewer, points: any[], markerOptions: any): void;
17
+ export declare function addMarker(viewer: Cesium.Viewer, layerName: string, points: any[], options: any): void;
18
+ /**
19
+ * 定位
20
+ * @param map 地图实例
21
+ * @param coordinate [经度, 纬度]
22
+ * @param options {flyOptions} 配置项
23
+ */
24
+ export declare function flyTo(viewer: Cesium.Viewer, coordinate: Coordinates, options?: flyOptions): Promise<boolean>;
25
+ /**
26
+ * 飞行到初始位置
27
+ * @param viewer 视图对象
28
+ * @param duration 飞行时间
29
+ */
30
+ export declare function flyHome(viewer: Cesium.Viewer, duration?: number): void;
31
+ /**
32
+ * 飞行到包围球
33
+ * @param viewer 视图对象
34
+ * @param boundingSphere
35
+ * @param options 配置项
36
+ */
37
+ export declare function flyToBoundingSphere(viewer: Cesium.Viewer, boundingSphere: Cesium.BoundingSphere, options: flyOptions): Promise<boolean>;
38
+ /**
39
+ * 设置视角
40
+ * @param viewer 视图对象
41
+ * @param coordinate [经度, 纬度, 高度]
42
+ * @param options 配置项
43
+ */
44
+ export declare function setView(viewer: Cesium.Viewer, coordinate: Coordinates, options: flyOptions): void;
45
+ /**
46
+ * 销毁地图
47
+ * @param viewer 视图对象
48
+ * @param id 地图id
49
+ */
50
+ export declare function destroyMap(viewer: Cesium.Viewer, id: string): void;
@@ -1,4 +1,20 @@
1
- export declare function useMap(el: HTMLElement, options: any): {
2
- instance: import('cesium').Viewer;
3
- addMarker: (points: any[], markerOptions: any) => void;
4
- };
1
+ import { MapContext } from './types';
2
+ /**
3
+ * 创建地图
4
+ * @param el 绑定地图元素Id
5
+ * @param options 配置项
6
+ * @returns 地图方法和地图实例
7
+ */
8
+ export declare function useMap(el: string, options: any): MapContext;
9
+ /**
10
+ * 保证能获取到方法
11
+ * @param id
12
+ * @param callback
13
+ */
14
+ export declare function onMapReady(id: string, callback: (ctx: MapContext) => void): void;
15
+ /**
16
+ * 获取地图返回的上下文
17
+ * @param id
18
+ * @returns Promise<MapContext>
19
+ */
20
+ export declare function getMapContext(id: string): Promise<MapContext>;
package/dist/3d/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var d=(r,t,e)=>new Promise((a,l)=>{var c=n=>{try{s(e.next(n))}catch(o){l(o)}},m=n=>{try{s(e.throw(n))}catch(o){l(o)}},s=n=>n.done?a(n.value):Promise.resolve(n.value).then(c,m);s((e=e.apply(r,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("cesium");function f(r){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const e in r)if(e!=="default"){const a=Object.getOwnPropertyDescriptor(r,e);Object.defineProperty(t,e,a.get?a:{enumerable:!0,get:()=>r[e]})}}return t.default=r,Object.freeze(t)}const i=f(g);function y(r,t){const e={img_w:!0,ibo_w:!0,cia_w:!0,token:"dadcbbdb5206b626a29ca739686b3087"},{img_w:a,ibo_w:l,cia_w:c,token:m}=Object.assign(e,t),s="https://t{s}.tianditu.gov.cn/",n=["0","1","2","3","4","5","6","7"];if(a){const o=new i.UrlTemplateImageryProvider({url:s+"DataServer?T=img_w&x={x}&y={y}&l={z}&tk="+m,subdomains:n,tilingScheme:new i.WebMercatorTilingScheme,maximumLevel:18});let u=r.imageryLayers.addImageryProvider(o);u.gamma=1}else{const o=new i.UrlTemplateImageryProvider({url:"https://tile-{s}.openstreetmap.fr/hot/{z}/{x}/{y}.png",subdomains:["a","b","c","d"],tilingScheme:new i.WebMercatorTilingScheme,maximumLevel:18});r.imageryLayers.addImageryProvider(o)}if(l){const o=new i.UrlTemplateImageryProvider({url:s+"DataServer?T=ibo_w&x={x}&y={y}&l={z}&tk="+m,subdomains:n,tilingScheme:new i.WebMercatorTilingScheme,maximumLevel:10});r.imageryLayers.addImageryProvider(o)}if(c){const o=new i.UrlTemplateImageryProvider({url:s+"DataServer?T=cia_w&x={x}&y={y}&l={z}&tk="+m,subdomains:n,tilingScheme:new i.WebMercatorTilingScheme,maximumLevel:18});r.imageryLayers.addImageryProvider(o)}}function b(r,t){let e;i.defined(t)&&(e=d(null,null,function*(){return yield i.CesiumTerrainProvider.fromUrl(t,{requestVertexNormals:!0,requestWaterMask:!0})})),i.defined(e)||(e=new i.EllipsoidTerrainProvider);const a=new i.Viewer(r,{requestRenderMode:!0,maximumRenderTimeChange:1/0,selectionIndicator:!1,animation:!1,timeline:!1,geocoder:!1,homeButton:!1,baseLayerPicker:!1,imageryProvider:new i.GridImageryProvider,sceneModePicker:!1,navigationHelpButton:!1,infoBox:!1,fullscreenButton:!1,shouldAnimate:!0,terrainProvider:e,contextOptions:{webgl:{preserveDrawingBuffer:!0}}});return a._cesiumWidget._creditContainer.style.display="none",a}function v(r,t){y(r,t)}function p(r,t,e){console.log("添加标记",r,t,e)}function w(r,t){const e=b(r);return v(e,t),{instance:e,addMarker:(a,l)=>p(e,a,l)}}exports.useMap=w;
1
+ "use strict";var M=Object.defineProperty,C=Object.defineProperties;var I=Object.getOwnPropertyDescriptors;var p=Object.getOwnPropertySymbols;var x=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable;var h=(t,r,e)=>r in t?M(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,u=(t,r)=>{for(var e in r||(r={}))x.call(r,e)&&h(t,e,r[e]);if(p)for(var e of p(r))O.call(r,e)&&h(t,e,r[e]);return t},f=(t,r)=>C(t,I(r));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("cesium"),b=require("../index.js");function k(t){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const e in t)if(e!=="default"){const a=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(r,e,a.get?a:{enumerable:!0,get:()=>t[e]})}}return r.default=t,Object.freeze(r)}const o=k(L);function _(t,r){const e={baseType:"img",noteType:"cia",token:"dadcbbdb5206b626a29ca739686b3087"},{baseType:a,noteType:n,token:i}=Object.assign(e,r),c="https://t{s}.tianditu.gov.cn",s=["0","1","2","3","4","5","6","7"],l=new o.UrlTemplateImageryProvider({url:`${c}/DataServer?T=${a}_w&x={x}&y={y}&l={z}&tk=${i}`,subdomains:s,tilingScheme:new o.WebMercatorTilingScheme});let d=t.imageryLayers.addImageryProvider(l);d.gamma=1;const T=new o.UrlTemplateImageryProvider({url:`${c}/DataServer?T=ibo_w&x={x}&y={y}&l={z}&tk=${i}`,subdomains:s,tilingScheme:new o.WebMercatorTilingScheme});t.imageryLayers.addImageryProvider(T);const v=new o.UrlTemplateImageryProvider({url:`${c}/DataServer?T=${n}_w&x={x}&y={y}&l={z}&tk=${i}`,subdomains:s,tilingScheme:new o.WebMercatorTilingScheme});t.imageryLayers.addImageryProvider(v)}function D(t,r){_(t,r)}function P(t,r,e,a){(!a||!a.type)&&(a=Object.assign({},e,a));const n=a.type||"Point";let i;switch(n){case"Point":i=B(t,r,e,a);break;case"LineString":i=R(t,r,e,a);break}return i}function B(t,r,e,a){const n=t.scene.primitives.add(new o.BillboardCollection);return n._layerName=r,e.forEach((i,c)=>{const s={scale:1,verticalOrigin:o.VerticalOrigin.BOTTOM,show:!0,disableDepthTestDistance:Number.POSITIVE_INFINITY,scaleByDistance:new o.NearFarScalar(1,1,1e5,.2)},l={position:o.Cartesian3.fromDegrees(...b.getLonLat(i),1),image:a.style||a.getStyle(i),id:i.id||`point_${c}`},d=n.add(u(u(u({},s),a),l));d._originStyle=f(u(u(u({},s),a),l),{color:o.Color.WHITE}),d.properties=i}),t.scene.requestRender(),n}function R(t,r,e,a){if(e.length<2)return;const n=E(e,a),i=new o.GroundPolylinePrimitive({geometryInstances:n,appearance:new o.PolylineColorAppearance({translucent:!0}),interleave:!0,allowPicking:!0,asynchronous:!1});i._layerName=r,t.scene.groundPrimitives.add(i)}function E(t,r){const e=[],a=t.map(c=>o.Cartesian3.fromDegrees(...b.getLonLat(c),0)),n=new o.GroundPolylineGeometry({positions:a,width:r.width||4,granularity:r.granularity||2e3}),i=new o.GeometryInstance({id:"pipeLine",geometry:n,attributes:{color:o.ColorGeometryInstanceAttribute.fromColor(o.Color.fromCssColorString(r.color))}});return e.push(i),e}function N(t,r){const e=t.scene.primitives,a=e.length;for(let n=0;n<a;n++){const i=e.get(n);if(i._layerName===r)return i}return null}const y=new Map,m={},g={},j=(t,r)=>{y.has(t)&&console.warn(`Map with target '${t}' already exists. Overwriting...`),y.set(t,r),m[t]&&(m[t].forEach(e=>e(r)),delete m[t]),g[t]&&(g[t].forEach(e=>e(r)),delete g[t])};function w(t){const r=y.get(t);return r?Promise.resolve(r):new Promise(e=>{g[t]=g[t]||[],g[t].push(e)})}const $=t=>{y.has(t)&&(y.delete(t),delete m[t])},S=(t,r)=>{const e=y.get(t);if(e){r(e);return}m[t]||(m[t]=[]),m[t].push(r)};function H(t,r={}){const e=new o.Viewer(t,{requestRenderMode:!0,maximumRenderTimeChange:1/0,selectionIndicator:!1,animation:!1,timeline:!1,geocoder:!1,homeButton:!1,baseLayerPicker:!1,sceneModePicker:!1,navigationHelpButton:!1,infoBox:!1,fullscreenButton:!1,shouldAnimate:!0,contextOptions:{webgl:{preserveDrawingBuffer:!0}}});let a;return o.defined(r.terrainUrl)?o.CesiumTerrainProvider.fromUrl(r.terrainUrl,{requestVertexNormals:!0,requestWaterMask:!0}).then(n=>{a=n,e.terrainProvider=a}):a=new o.EllipsoidTerrainProvider,e.terrainProvider=a,e._cesiumWidget._creditContainer.style.display="none",e.scene.globe.baseColor=new o.Color(0,0,0,0),e.scene.screenSpaceCameraController.minimumZoomDistance=r.minZoom||1,e.scene.screenSpaceCameraController.maximumZoomDistance=r.maxZoom||1e7,e.resolutionScale=window.devicePixelRatio>2?2:window.devicePixelRatio,e}function q(t,r,e,a){P(t,r,e,f(u({},a),{type:"Point"}))}function V(t,r,e){return new Promise((a,n)=>{t.camera.flyTo({destination:o.Cartesian3.fromDegrees(...r),duration:e.duration||1.2,orientation:{heading:e.heading||0,pitch:e.pitch||-Math.PI/2,roll:e.roll||0},easingFunction:e.easing||o.EasingFunction.LINEAR_NONE,maximumHeight:e.maxHeight||1e6,complete:()=>{a(!0)},cancel:()=>{a(!1)}})})}function G(t,r=1){return t.camera.flyHome(r)}function U(t,r,e){return new Promise((a,n)=>{t.camera.flyToBoundingSphere(r,{duration:e.duration||1e3,offset:new o.HeadingPitchRange(e.heading||0,e.pitch||-Math.PI/4,e.roll||0),easingFunction:e.easing,maximumHeight:e.maxHeight||1e6,complete:()=>{a(!0)},cancel:()=>{a(!1)}})})}function F(t,r,e){t.camera.setView({destination:o.Cartesian3.fromDegrees(...r),orientation:{heading:e.heading||0,pitch:e.pitch||-Math.PI/2,roll:e.roll||0}})}function W(t,r){t.destroy(),$(r)}function A(t,r){const e=new Set,a=new o.ScreenSpaceEventHandler(t.scene.canvas);let n=null;a.setInputAction(c=>{const s=t.scene.pick(c.position);if(n&&(Object.assign(n,n._originStyle),n=null,t.scene.requestRender()),o.defined(s)&&s.primitive instanceof o.Billboard){const l=s.primitive,d={billboard:l,properties:l.properties,event:c,pick:s};n=l,i(d),Object.assign(l,r.style||r.getStyle(l)),t.scene.requestRender()}},o.ScreenSpaceEventType.LEFT_CLICK);const i=c=>e.forEach(s=>s(c));return{onSelect:c=>(e.add(c),()=>e.delete(c)),clear(){e.clear()},destroy(){e.clear()}}}function z(t,r){const e=H(t,r);D(e,r);const a={targetId:t,instance:e,addMarker:(n,i,c)=>q(e,n,i,c),createLayer:(n,i,c)=>P(e,n,i,c),getLayerByName:n=>N(e,n),useSelect:n=>A(e,n),flyTo:(n,i)=>V(e,n,i),flyHome:n=>G(e,n),flyToBoundingSphere:(n,i)=>U(e,n,i),setView:(n,i)=>F(e,n,i),getMapContext:n=>w(n),onMapReady:(n,i)=>S(n,i),destroyMap:n=>W(e,n)};return j(t,a),a}function Z(t,r){S(t,r)}function K(t){return w(t)}exports.getMapContext=K;exports.onMapReady=Z;exports.useMap=z;