@vue-start/map 0.0.6 → 0.0.8

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/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # 0.0.7
2
+
3
+ - perf: useMapApi 返回插件对象 targetRef;
4
+
5
+ ```ts
6
+ const { targetRef } = useMapApi("", {});
7
+ ```
package/dist/index.d.ts CHANGED
@@ -566,6 +566,7 @@ interface IUseMapApiResult {
566
566
  data: UnwrapNestedRefs<any>;
567
567
  requesting: Ref<UnwrapRef<boolean>>;
568
568
  request: (opts?: Record<string, any>, params?: any[]) => void;
569
+ targetRef: ShallowRef<any>;
569
570
  }
570
571
  /**
571
572
  * api组成说明 `AMap.${PluginName}_MethodName`
package/dist/index.es.js CHANGED
@@ -1,16 +1,16 @@
1
- import { defineComponent as v, shallowRef as X, ref as g, createVNode as A, provide as Y, inject as Z, toRef as C, Teleport as $, mergeProps as ee } from "vue";
2
- import ae from "@amap/amap-jsapi-loader";
3
- import { useEffect as i, useWatch as R, createExposeObj as te, useState as re } from "@vue-start/hooks";
4
- import { forEach as B, size as x, upperFirst as ne, isFunction as h, isNumber as J, debounce as z, isArray as _, map as oe, omit as V, isBoolean as ce, split as se, get as ue } from "lodash";
5
- const q = (e, a) => {
6
- i(() => (B(a, (r) => {
7
- e.on(r.type, r.handler, void 0, r.once);
1
+ import { defineComponent as v, shallowRef as x, ref as T, createVNode as A, provide as Z, inject as ee, toRef as C, Teleport as J, mergeProps as ae } from "vue";
2
+ import te from "@amap/amap-jsapi-loader";
3
+ import { useEffect as i, useWatch as R, createExposeObj as re, useState as ne } from "@vue-start/hooks";
4
+ import { forEach as B, size as V, isFunction as h, upperFirst as oe, isNumber as z, debounce as q, isArray as _, map as ce, omit as K, isBoolean as se, split as ue, get as ie } from "lodash";
5
+ const Q = (e, a) => {
6
+ i(() => (B(a, (n) => {
7
+ e.on(n.type, n.handler, void 0, n.once);
8
8
  }), () => {
9
- B(a, (r) => {
10
- e.off(r.type, r.handler);
9
+ B(a, (n) => {
10
+ e.off(n.type, n.handler);
11
11
  });
12
12
  }), []);
13
- }, K = Symbol("amap-key"), j = (e) => Y(K, e), m = () => Z(K), ie = () => ({
13
+ }, U = Symbol("amap-key"), j = (e) => Z(U, e), m = () => ee(U), le = () => ({
14
14
  securityJsCode: {
15
15
  type: String
16
16
  },
@@ -23,7 +23,7 @@ const q = (e, a) => {
23
23
  events: {
24
24
  type: Array
25
25
  }
26
- }), le = (e) => {
26
+ }), pe = (e) => {
27
27
  var a;
28
28
  if (!!e) {
29
29
  if (!window._AMapSecurityConfig || !((a = window._AMapSecurityConfig) != null && a.securityJsCode)) {
@@ -36,7 +36,7 @@ const q = (e, a) => {
36
36
  securityJsCode: e
37
37
  }, console.warn("\u5F53\u524Dwindow\u5BF9\u8C61\u5DF2\u7ECF\u6CE8\u5165\u8FC7securityJsCode\u503C\uFF0C\u53EF\u80FD\u9020\u6210\u95EE\u9898"));
38
38
  }
39
- }, pe = v({
39
+ }, de = v({
40
40
  props: {
41
41
  events: {
42
42
  type: Array
@@ -46,22 +46,22 @@ const q = (e, a) => {
46
46
  const {
47
47
  mapRef: a
48
48
  } = m();
49
- return q(a.value, e.events), () => null;
49
+ return Q(a.value, e.events), () => null;
50
50
  }
51
- }), Le = v({
51
+ }), be = v({
52
52
  props: {
53
- ...ie()
53
+ ...le()
54
54
  },
55
55
  setup: (e, {
56
56
  slots: a,
57
- expose: r
57
+ expose: n
58
58
  }) => {
59
- le(e.securityJsCode);
60
- const n = X(), t = g();
61
- return r({
62
- mapRef: n,
59
+ pe(e.securityJsCode);
60
+ const r = x(), t = T();
61
+ return n({
62
+ mapRef: r,
63
63
  domRef: t
64
- }), i(() => (ae.load({
64
+ }), i(() => (te.load({
65
65
  version: "2.0",
66
66
  ...e.loadOpts
67
67
  }).then((o) => {
@@ -69,50 +69,50 @@ const q = (e, a) => {
69
69
  ...e.opts
70
70
  });
71
71
  u.on("complete", () => {
72
- n.value = u;
72
+ r.value = u;
73
73
  });
74
74
  }).catch((o) => {
75
75
  console.error("\u52A0\u8F7D\u5730\u56FE\u9519\u8BEF"), console.error(o);
76
76
  }), () => {
77
- n.value && n.value.destroy();
77
+ r.value && r.value.destroy();
78
78
  }), []), j({
79
- mapRef: n
79
+ mapRef: r
80
80
  }), () => {
81
81
  var o;
82
82
  return A("div", {
83
83
  ref: t
84
- }, [n.value && A(pe, {
84
+ }, [r.value && A(de, {
85
85
  events: e.events
86
- }, null), n.value && ((o = a.default) == null ? void 0 : o.call(a))]);
86
+ }, null), r.value && ((o = a.default) == null ? void 0 : o.call(a))]);
87
87
  };
88
88
  }
89
- }), Q = (e, a) => {
90
- const { mapRef: r } = m();
89
+ }), X = (e, a) => {
90
+ const { mapRef: n } = m();
91
91
  i(() => {
92
- if (!r.value) {
92
+ if (!n.value) {
93
93
  console.warn("\u8BF7\u5728Map\u7EC4\u4EF6\u5185\u4F7F\u7528 useMapPlugin");
94
94
  return;
95
95
  }
96
- if (!e || x(e) <= 0) {
96
+ if (!e || V(e) <= 0) {
97
97
  a();
98
98
  return;
99
99
  }
100
100
  window.AMap.plugin(e, a);
101
101
  }, []);
102
- }, de = v({
102
+ }, Me = v({
103
103
  props: {
104
104
  plugins: Array
105
105
  },
106
106
  setup: (e, { slots: a }) => {
107
- const r = g(!1);
108
- return Q(e.plugins, () => {
109
- r.value = !0;
107
+ const n = T(!1);
108
+ return X(e.plugins, () => {
109
+ n.value = !0;
110
110
  }), () => {
111
- var n;
112
- return r.value ? (n = a.default) == null ? void 0 : n.call(a) : null;
111
+ var r;
112
+ return n.value ? (r = a.default) == null ? void 0 : r.call(a) : null;
113
113
  };
114
114
  }
115
- }), S = {
115
+ }), g = {
116
116
  ElasticMarker: "AMap.ElasticMarker",
117
117
  ControlBar: "AMap.ControlBar",
118
118
  ToolBar: "AMap.ToolBar",
@@ -154,19 +154,19 @@ const q = (e, a) => {
154
154
  i(() => (a.value.add(e), () => {
155
155
  try {
156
156
  a.value.remove(e);
157
- } catch (r) {
158
- console.error(r);
157
+ } catch (n) {
158
+ console.error(n);
159
159
  }
160
160
  }), []);
161
- }, U = (e) => {
161
+ }, Y = (e) => {
162
162
  const {
163
163
  mapRef: a
164
164
  } = m();
165
165
  i(() => (e.setMap(a.value), () => {
166
166
  try {
167
167
  e.setMap(null);
168
- } catch (r) {
169
- console.error(r);
168
+ } catch (n) {
169
+ console.error(n);
170
170
  }
171
171
  }), []);
172
172
  }, F = (e) => {
@@ -176,32 +176,40 @@ const q = (e, a) => {
176
176
  i(() => (a.value.addControl(e), () => {
177
177
  try {
178
178
  a.value.removeControl(e);
179
- } catch (r) {
180
- console.error(r);
179
+ } catch (n) {
180
+ console.error(n);
181
181
  }
182
182
  }), []);
183
183
  }, P = (e, a) => {
184
- const r = () => {
184
+ const n = () => {
185
185
  e && h(e.show) && e.show();
186
- }, n = () => {
186
+ }, r = () => {
187
187
  e && h(e.hide) && e.hide();
188
188
  };
189
189
  i(() => {
190
- a.value || n();
190
+ a.value || r();
191
191
  }, []), R(() => {
192
- a.value ? r() : n();
192
+ a.value ? n() : r();
193
193
  }, a);
194
- }, k = (e, a) => {
195
- i(() => {
196
- B(a.value, (r, n) => {
197
- const t = "set" + ne(n);
198
- e[t] && h(e[t]) && e[t](r);
194
+ }, E = (e, a) => {
195
+ const n = (r, t) => {
196
+ const o = "set" + oe(r);
197
+ if (e[o] && h(e[o]))
198
+ e[o](t);
199
+ else {
200
+ const u = "set" + r;
201
+ e[u] && h(e[u]) && e[u](t);
202
+ }
203
+ };
204
+ i((r, t) => {
205
+ B(a.value, (o, u) => {
206
+ (t == null ? void 0 : t[u]) !== o && n(u, o);
199
207
  });
200
208
  }, a);
201
209
  }, c = (e, {
202
210
  useMapConnect: a,
203
- createFeatureObj: r,
204
- needDom: n
211
+ createFeatureObj: n,
212
+ needDom: r
205
213
  }) => v({
206
214
  props: {
207
215
  opts: {
@@ -222,18 +230,18 @@ const q = (e, a) => {
222
230
  slots: o,
223
231
  expose: u
224
232
  }) => {
225
- const s = r ? r(t.opts) : new window.AMap[e](t.opts);
233
+ const s = n ? n(t.opts) : new window.AMap[e](t.opts);
226
234
  a(s);
227
235
  const p = C(t, "show");
228
236
  P(s, p);
229
237
  const d = C(t, "opts$");
230
- k(s, d), q(s, t.events), u({
238
+ E(s, d), Q(s, t.events), u({
231
239
  getFeature: () => s
232
240
  });
233
- const M = g();
241
+ const M = T();
234
242
  return i(() => {
235
243
  M.value && h(s.setContent) && s.setContent(M.value);
236
- }, M), () => n && o.default ? A($, {
244
+ }, M), () => r && o.default ? A(J, {
237
245
  to: "body"
238
246
  }, {
239
247
  default: () => [A("div", {
@@ -241,24 +249,24 @@ const q = (e, a) => {
241
249
  }, [o.default()])]
242
250
  }) : null;
243
251
  }
244
- }), L = (e, a) => v({
252
+ }), S = (e, a) => v({
245
253
  props: {
246
254
  ...a.props
247
255
  },
248
- setup: (r, {
249
- slots: n,
256
+ setup: (n, {
257
+ slots: r,
250
258
  expose: t
251
259
  }) => {
252
- const o = g();
253
- return t(te(o, ["getFeature"])), () => A(de, {
260
+ const o = T();
261
+ return t(re(o, ["getFeature"])), () => A(Me, {
254
262
  plugins: e
255
263
  }, {
256
- default: () => [A(a, ee({
264
+ default: () => [A(a, ae({
257
265
  ref: o
258
- }, r), n)]
266
+ }, n), r)]
259
267
  });
260
268
  }
261
- }), Me = () => {
269
+ }), ye = () => {
262
270
  const { mapRef: e, overlayGroup: a } = m();
263
271
  return { addToMap: (t) => {
264
272
  if (a) {
@@ -278,11 +286,11 @@ const q = (e, a) => {
278
286
  }
279
287
  } };
280
288
  }, w = (e) => {
281
- const { addToMap: a, removeFromMap: r } = Me();
289
+ const { addToMap: a, removeFromMap: n } = ye();
282
290
  i(() => (a(e), () => {
283
- r(e);
291
+ n(e);
284
292
  }), []);
285
- }, be = v({
293
+ }, Re = v({
286
294
  props: {
287
295
  bind: { type: Boolean, default: !1 },
288
296
  bindTime: { type: Number, default: void 0 },
@@ -290,14 +298,14 @@ const q = (e, a) => {
290
298
  show: { type: Boolean, default: !0 },
291
299
  events: { type: Array }
292
300
  },
293
- setup: (e, { slots: a, expose: r }) => {
294
- const { mapRef: n } = m(), t = new window.AMap.OverlayGroup();
301
+ setup: (e, { slots: a, expose: n }) => {
302
+ const { mapRef: r } = m(), t = new window.AMap.OverlayGroup();
295
303
  let o = !1;
296
304
  const u = () => {
297
- o || (n.value.add(t), o = !0);
305
+ o || (r.value.add(t), o = !0);
298
306
  }, s = () => {
299
307
  try {
300
- n.value.remove(t);
308
+ r.value.remove(t);
301
309
  } catch (l) {
302
310
  console.error(l);
303
311
  }
@@ -306,7 +314,7 @@ const q = (e, a) => {
306
314
  i(() => () => {
307
315
  s();
308
316
  }, []), i(() => {
309
- if (!J(e.bindTime))
317
+ if (!z(e.bindTime))
310
318
  return;
311
319
  const l = setTimeout(() => {
312
320
  u();
@@ -315,7 +323,7 @@ const q = (e, a) => {
315
323
  l && clearTimeout(l);
316
324
  };
317
325
  }, []);
318
- const d = z(() => {
326
+ const d = q(() => {
319
327
  u();
320
328
  }, 300);
321
329
  R(
@@ -326,13 +334,13 @@ const q = (e, a) => {
326
334
  );
327
335
  const M = C(e, "show");
328
336
  P(t, M);
329
- const T = C(e, "opts$");
330
- return k(t, T), r({ getFeature: p, addToMap: u, removeFormMap: s }), j({ mapRef: n, overlayGroup: t }), () => {
337
+ const L = C(e, "opts$");
338
+ return E(t, L), n({ getFeature: p, addToMap: u, removeFormMap: s }), j({ mapRef: r, overlayGroup: t }), () => {
331
339
  var l;
332
340
  return (l = a.default) == null ? void 0 : l.call(a);
333
341
  };
334
342
  }
335
- }), Re = v({
343
+ }), Fe = v({
336
344
  props: {
337
345
  opts: {
338
346
  type: Object
@@ -347,33 +355,33 @@ const q = (e, a) => {
347
355
  },
348
356
  setup: (e, {
349
357
  slots: a,
350
- emit: r
358
+ emit: n
351
359
  }) => {
352
360
  const {
353
- mapRef: n
361
+ mapRef: r
354
362
  } = m(), t = new window.AMap.InfoWindow({
355
363
  closeWhenClickMap: !0,
356
364
  isCustom: !!a.default,
357
365
  ...e.opts
358
366
  }), o = C(e, "opts$");
359
- k(t, o);
367
+ E(t, o);
360
368
  const u = () => {
361
- r("close");
369
+ n("close");
362
370
  };
363
371
  i(() => (t.on("close", u), () => {
364
372
  t.off("close", u), t.close();
365
373
  }), []), i(() => {
366
374
  var d, M;
367
375
  const p = ((d = e.opts$) == null ? void 0 : d.position) || ((M = e.opts) == null ? void 0 : M.position);
368
- !p || t.open(n.value, p, e.height);
376
+ !p || t.open(r.value, p, e.height);
369
377
  }, () => {
370
378
  var p;
371
379
  return (p = e.opts$) == null ? void 0 : p.position;
372
380
  });
373
- const s = g();
381
+ const s = T();
374
382
  return i(() => {
375
383
  s.value && h(t.setContent) && t.setContent(s.value);
376
- }, s), () => a.default ? A($, {
384
+ }, s), () => a.default ? A(J, {
377
385
  to: "body"
378
386
  }, {
379
387
  default: () => [A("div", {
@@ -381,7 +389,7 @@ const q = (e, a) => {
381
389
  }, [a.default()])]
382
390
  }) : null;
383
391
  }
384
- }), Fe = c("CircleMarker", { useMapConnect: G }), Oe = c("Text", { useMapConnect: G }), Be = c("ElasticMarker", { useMapConnect: G }), _e = c("Marker", { useMapConnect: w, needDom: !0 }), Pe = c("Polygon", { useMapConnect: w }), ke = c("Polyline", { useMapConnect: w }), Ee = c("Circle", { useMapConnect: w }), De = c("Rectangle", { useMapConnect: w }), je = c("Ellipse", { useMapConnect: w }), Ge = c("BezierCurve", { useMapConnect: w }), ye = c("ToolBar", { useMapConnect: F }), Ie = L([S.ToolBar], ye), fe = c("Scale", { useMapConnect: F }), Ne = L([S.Scale], fe), me = c("HawkEye", { useMapConnect: F }), He = L([S.HawkEye], me), ve = c("MapType", { useMapConnect: F }), We = L([S.MapType], ve), Ae = c("ControlBar", { useMapConnect: F }), $e = L([S.ControlBar], Ae), Ce = () => {
392
+ }), Oe = c("CircleMarker", { useMapConnect: G }), Be = c("Text", { useMapConnect: G }), _e = c("ElasticMarker", { useMapConnect: G }), Pe = c("Marker", { useMapConnect: w, needDom: !0 }), Ee = c("Polygon", { useMapConnect: w }), ke = c("Polyline", { useMapConnect: w }), De = c("Circle", { useMapConnect: w }), je = c("Rectangle", { useMapConnect: w }), Ge = c("Ellipse", { useMapConnect: w }), Ie = c("BezierCurve", { useMapConnect: w }), fe = c("ToolBar", { useMapConnect: F }), He = S([g.ToolBar], fe), me = c("Scale", { useMapConnect: F }), Ne = S([g.Scale], me), ve = c("HawkEye", { useMapConnect: F }), We = S([g.HawkEye], ve), Ae = c("MapType", { useMapConnect: F }), $e = S([g.MapType], Ae), Ce = c("ControlBar", { useMapConnect: F }), xe = S([g.ControlBar], Ce), he = () => {
385
393
  const { mapRef: e, layerGroup: a } = m();
386
394
  return { addToMap: (t) => {
387
395
  if (a) {
@@ -400,12 +408,12 @@ const q = (e, a) => {
400
408
  console.error(o);
401
409
  }
402
410
  } };
403
- }, y = (e) => {
404
- const { addToMap: a, removeFromMap: r } = Ce();
411
+ }, f = (e) => {
412
+ const { addToMap: a, removeFromMap: n } = he();
405
413
  i(() => (a(e), () => {
406
- r(e);
414
+ n(e);
407
415
  }), []);
408
- }, xe = v({
416
+ }, Je = v({
409
417
  props: {
410
418
  bind: { type: Boolean, default: !1 },
411
419
  bindTime: { type: Number, default: void 0 },
@@ -413,11 +421,11 @@ const q = (e, a) => {
413
421
  show: { type: Boolean, default: !0 },
414
422
  events: { type: Array }
415
423
  },
416
- setup: (e, { slots: a, expose: r }) => {
417
- const { mapRef: n } = m(), t = new window.AMap.LayerGroup();
424
+ setup: (e, { slots: a, expose: n }) => {
425
+ const { mapRef: r } = m(), t = new window.AMap.LayerGroup();
418
426
  let o = !1;
419
427
  const u = () => {
420
- o || (t.setMap(n.value), o = !0);
428
+ o || (t.setMap(r.value), o = !0);
421
429
  }, s = () => {
422
430
  try {
423
431
  t.setMap(null);
@@ -429,7 +437,7 @@ const q = (e, a) => {
429
437
  i(() => () => {
430
438
  s();
431
439
  }, []), i(() => {
432
- if (!J(e.bindTime))
440
+ if (!z(e.bindTime))
433
441
  return;
434
442
  const l = setTimeout(() => {
435
443
  u();
@@ -438,7 +446,7 @@ const q = (e, a) => {
438
446
  l && clearTimeout(l);
439
447
  };
440
448
  }, []);
441
- const d = z(() => {
449
+ const d = q(() => {
442
450
  u();
443
451
  }, 300);
444
452
  R(
@@ -449,13 +457,13 @@ const q = (e, a) => {
449
457
  );
450
458
  const M = C(e, "show");
451
459
  P(t, M);
452
- const T = C(e, "opts$");
453
- return k(t, T), r({ getFeature: p, addToMap: u, removeFormMap: s }), j({ mapRef: n, layerGroup: t }), () => {
460
+ const L = C(e, "opts$");
461
+ return E(t, L), n({ getFeature: p, addToMap: u, removeFormMap: s }), j({ mapRef: r, layerGroup: t }), () => {
454
462
  var l;
455
463
  return (l = a.default) == null ? void 0 : l.call(a);
456
464
  };
457
465
  }
458
- }), Je = v({
466
+ }), Ve = v({
459
467
  props: {
460
468
  opts: { type: Object },
461
469
  itemOpts: { type: Object },
@@ -464,7 +472,7 @@ const q = (e, a) => {
464
472
  events: { type: Array }
465
473
  },
466
474
  setup: (e, { expose: a }) => {
467
- const { mapRef: r } = m(), n = new window.AMap.LabelsLayer(e.opts), t = () => oe(e.data, (s) => {
475
+ const { mapRef: n } = m(), r = new window.AMap.LabelsLayer(e.opts), t = () => ce(e.data, (s) => {
468
476
  const p = new window.AMap.LabelMarker({
469
477
  ...e.itemOpts,
470
478
  ...s
@@ -473,12 +481,12 @@ const q = (e, a) => {
473
481
  p.on(d.type, d.handler, void 0, d.once);
474
482
  }), p;
475
483
  }), o = () => {
476
- n.clear();
484
+ r.clear();
477
485
  const s = t();
478
- n.add(s);
486
+ r.add(s);
479
487
  };
480
- i(() => (x(e.data) > 0 && o(), r.value.add(n), () => {
481
- n.clear(), r.value.remove(n);
488
+ i(() => (V(e.data) > 0 && o(), n.value.add(r), () => {
489
+ r.clear(), n.value.remove(r);
482
490
  }), []), R(
483
491
  () => {
484
492
  o();
@@ -486,65 +494,66 @@ const q = (e, a) => {
486
494
  () => e.data
487
495
  );
488
496
  const u = C(e, "show");
489
- return P(n, u), a({ getFeature: () => n }), () => null;
497
+ return P(r, u), a({ getFeature: () => r }), () => null;
490
498
  }
491
- }), ze = c("TileLayer", { useMapConnect: y }), Ve = c("TileLayer.Satellite", {
492
- useMapConnect: y,
499
+ }), ze = c("TileLayer", { useMapConnect: f }), qe = c("TileLayer.Satellite", {
500
+ useMapConnect: f,
493
501
  createFeatureObj: (e) => new window.AMap.TileLayer.Satellite(e)
494
- }), qe = c("TileLayer.RoadNet", {
495
- useMapConnect: y,
502
+ }), Ke = c("TileLayer.RoadNet", {
503
+ useMapConnect: f,
496
504
  createFeatureObj: (e) => new window.AMap.TileLayer.RoadNet(e)
497
- }), Ke = c("TileLayer.Traffic", {
498
- useMapConnect: y,
505
+ }), Qe = c("TileLayer.Traffic", {
506
+ useMapConnect: f,
499
507
  createFeatureObj: (e) => new window.AMap.TileLayer.Traffic(e)
500
- }), Qe = c("Buildings", { useMapConnect: y }), Ue = c("MassMarks", {
501
- useMapConnect: U,
502
- createFeatureObj: (e) => new window.AMap.MassMarks((e == null ? void 0 : e.data) || [], V(e, "data"))
503
- }), Xe = c("TileLayer.Flexible", {
504
- useMapConnect: y,
508
+ }), Ue = c("Buildings", { useMapConnect: f }), Xe = c("MassMarks", {
509
+ useMapConnect: Y,
510
+ createFeatureObj: (e) => new window.AMap.MassMarks((e == null ? void 0 : e.data) || [], K(e, "data"))
511
+ }), Ye = c("TileLayer.Flexible", {
512
+ useMapConnect: f,
505
513
  createFeatureObj: (e) => new window.AMap.TileLayer.Flexible(e)
506
- }), Ye = c("ImageLayer", { useMapConnect: y }), Ze = c("VideoLayer", { useMapConnect: y }), ea = c("CanvasLayer", { useMapConnect: y }), aa = c("CustomLayer", {
507
- useMapConnect: y,
508
- createFeatureObj: (e) => new window.AMap.CustomLayer(e == null ? void 0 : e.canvas, V(e, "canvas"))
509
- }), ta = c("DistrictLayer.World", {
510
- useMapConnect: y,
514
+ }), Ze = c("ImageLayer", { useMapConnect: f }), ea = c("VideoLayer", { useMapConnect: f }), aa = c("CanvasLayer", { useMapConnect: f }), ta = c("CustomLayer", {
515
+ useMapConnect: f,
516
+ createFeatureObj: (e) => new window.AMap.CustomLayer(e == null ? void 0 : e.canvas, K(e, "canvas"))
517
+ }), ra = c("DistrictLayer.World", {
518
+ useMapConnect: f,
511
519
  createFeatureObj: (e) => new window.AMap.DistrictLayer.World(e)
512
- }), ra = c("DistrictLayer.Country", {
513
- useMapConnect: y,
520
+ }), na = c("DistrictLayer.Country", {
521
+ useMapConnect: f,
514
522
  createFeatureObj: (e) => new window.AMap.DistrictLayer.Country(e)
515
- }), na = c("DistrictLayer.Province", {
516
- useMapConnect: y,
523
+ }), oa = c("DistrictLayer.Province", {
524
+ useMapConnect: f,
517
525
  createFeatureObj: (e) => new window.AMap.DistrictLayer.Province(e)
518
- }), he = c("HeatMap", {
519
- useMapConnect: U,
526
+ }), we = c("HeatMap", {
527
+ useMapConnect: Y,
520
528
  createFeatureObj: (e) => new window.AMap.HeatMap(null, e)
521
- }), oa = L([S.HeatMap], he), ca = (e, a) => {
522
- let r = !1, n = null;
523
- const [t, o] = re(), u = g(ce(a.initEmit) ? a.initEmit : !1), s = se(e, "_"), p = s[0], d = s[1], M = () => {
524
- const f = ue(window, p);
525
- return f ? new f({ ...a.opts, ...n == null ? void 0 : n.opts }) : null;
526
- }, T = (f) => f || (h(a.params) ? a.params() : a.params || []), l = () => {
527
- if (!n)
529
+ }), ca = S([g.HeatMap], we), sa = (e, a) => {
530
+ let n = !1, r = null;
531
+ const t = x(), [o, u] = ne(), s = T(se(a.initEmit) ? a.initEmit : !1), p = ue(e, "_"), d = p[0], M = p[1], L = () => {
532
+ const y = ie(window, d);
533
+ return y ? new y({ ...a.opts, ...r == null ? void 0 : r.opts }) : null;
534
+ }, l = (y) => y || (h(a.params) ? a.params() : a.params || []), I = () => {
535
+ if (!r)
528
536
  return;
529
- const f = M();
530
- if (!f || !h(f[d]))
537
+ const y = L();
538
+ if (t.value = y, !y || !h(y[M]))
531
539
  return;
532
- const D = T(n.params);
533
- u.value = !0, f[d](...D, (O, b) => {
534
- var I, N, H, W;
535
- o(b), (I = a.onComplete) == null || I.call(a, O, b), O === "complete" ? (N = a.onSuccess) == null || N.call(a, b) : O === "error" ? (H = a.onFail) == null || H.call(a, b) : O === "no_data" && ((W = a.onNoData) == null || W.call(a, b)), n = null, u.value = !1;
536
- });
540
+ const D = l(r.params);
541
+ return s.value = !0, y[M](...D, (O, b) => {
542
+ var H, N, W, $;
543
+ u(b), (H = a.onComplete) == null || H.call(a, O, b), O === "complete" ? (N = a.onSuccess) == null || N.call(a, b) : O === "error" ? (W = a.onFail) == null || W.call(a, b) : O === "no_data" && (($ = a.onNoData) == null || $.call(a, b)), r = null, s.value = !1;
544
+ }), y;
537
545
  };
538
- Q([p], () => {
539
- r = !0, l();
546
+ X([d], () => {
547
+ n = !0, I();
540
548
  });
541
- const E = (f, D) => {
542
- n = { opts: f || a.opts, params: T(D) }, r && l();
549
+ const k = (y, D) => {
550
+ if (r = { opts: y || a.opts, params: l(D) }, !!n)
551
+ return I();
543
552
  };
544
553
  return i(() => {
545
- a.initEmit && E();
546
- }, []), R(() => E(), a.deps || []), { data: t, request: E, requesting: u };
547
- }, sa = {
554
+ a.initEmit && k();
555
+ }, []), R(() => k(), a.deps || []), { data: o, request: k, requesting: s, targetRef: t };
556
+ }, ua = {
548
557
  Geocoder_getLocation: "AMap.Geocoder_getLocation",
549
558
  Geocoder_getAddress: "AMap.Geocoder_getAddress",
550
559
  Autocomplete_search: "AMap.Autocomplete_search",
@@ -559,57 +568,57 @@ const q = (e, a) => {
559
568
  StationSearch_searchById: "AMap.StationSearch_searchById"
560
569
  };
561
570
  export {
562
- sa as ApiNames,
563
- Ge as BezierCurve,
564
- Qe as Buildings,
565
- ea as CanvasLayer,
566
- Ee as Circle,
567
- Fe as CircleMarker,
568
- $e as ControlBar,
569
- aa as CustomLayer,
570
- ra as DistrictLayerCountry,
571
- na as DistrictLayerProvince,
572
- ta as DistrictLayerWorld,
573
- Be as ElasticMarker,
574
- je as Ellipse,
575
- He as HawkEye,
576
- oa as HeatMap,
577
- Ye as ImageLayer,
578
- Re as InfoWindow,
579
- Je as LabelsLayer,
580
- xe as LayerGroup,
581
- Le as Map,
582
- pe as MapEvents,
583
- de as MapPlugin,
584
- S as MapPluginType,
585
- We as MapType,
586
- _e as Marker,
587
- Ue as MassMarks,
588
- be as OverlayGroup,
589
- Pe as Polygon,
571
+ ua as ApiNames,
572
+ Ie as BezierCurve,
573
+ Ue as Buildings,
574
+ aa as CanvasLayer,
575
+ De as Circle,
576
+ Oe as CircleMarker,
577
+ xe as ControlBar,
578
+ ta as CustomLayer,
579
+ na as DistrictLayerCountry,
580
+ oa as DistrictLayerProvince,
581
+ ra as DistrictLayerWorld,
582
+ _e as ElasticMarker,
583
+ Ge as Ellipse,
584
+ We as HawkEye,
585
+ ca as HeatMap,
586
+ Ze as ImageLayer,
587
+ Fe as InfoWindow,
588
+ Ve as LabelsLayer,
589
+ Je as LayerGroup,
590
+ be as Map,
591
+ de as MapEvents,
592
+ Me as MapPlugin,
593
+ g as MapPluginType,
594
+ $e as MapType,
595
+ Pe as Marker,
596
+ Xe as MassMarks,
597
+ Re as OverlayGroup,
598
+ Ee as Polygon,
590
599
  ke as Polyline,
591
- De as Rectangle,
600
+ je as Rectangle,
592
601
  Ne as Scale,
593
- Oe as Text,
602
+ Be as Text,
594
603
  ze as TileLayer,
595
- Xe as TileLayerFlexible,
596
- qe as TileLayerRoadNet,
597
- Ve as TileLayerSatellite,
598
- Ke as TileLayerTraffic,
599
- Ie as ToolBar,
600
- Ze as VideoLayer,
604
+ Ye as TileLayerFlexible,
605
+ Ke as TileLayerRoadNet,
606
+ qe as TileLayerSatellite,
607
+ Qe as TileLayerTraffic,
608
+ He as ToolBar,
609
+ ea as VideoLayer,
601
610
  c as createFeature,
602
- L as createPluginFeature,
611
+ S as createPluginFeature,
603
612
  j as provideMap,
604
- q as useEvents,
605
- k as useFeatureOptMethods,
613
+ Q as useEvents,
614
+ E as useFeatureOptMethods,
606
615
  m as useMap,
607
- ca as useMapApi,
616
+ sa as useMapApi,
608
617
  G as useMapConnect,
609
- U as useMapConnect2,
618
+ Y as useMapConnect2,
610
619
  F as useMapControlConnect,
611
- y as useMapLayerConnect,
620
+ f as useMapLayerConnect,
612
621
  w as useMapOverlayConnect,
613
- Q as useMapPlugin,
622
+ X as useMapPlugin,
614
623
  P as useShowConnect
615
624
  };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const o=require("vue"),V=require("@amap/amap-jsapi-loader"),i=require("@vue-start/hooks"),u=require("lodash"),$=e=>e&&typeof e=="object"&&"default"in e?e:{default:e},x=$(V),k=(e,a)=>{i.useEffect(()=>(u.forEach(a,r=>{e.on(r.type,r.handler,void 0,r.once)}),()=>{u.forEach(a,r=>{e.off(r.type,r.handler)})}),[])},W=Symbol("amap-key"),R=e=>o.provide(W,e),m=()=>o.inject(W),J=()=>({securityJsCode:{type:String},loadOpts:{type:Object},opts:{type:Object},events:{type:Array}}),q=e=>{var a;if(!!e){if(!window._AMapSecurityConfig||!((a=window._AMapSecurityConfig)!=null&&a.securityJsCode)){window._AMapSecurityConfig={securityJsCode:e};return}window._AMapSecurityConfig.securityJsCode!==e&&(window._AMapSecurityConfig={securityJsCode:e},console.warn("\u5F53\u524Dwindow\u5BF9\u8C61\u5DF2\u7ECF\u6CE8\u5165\u8FC7securityJsCode\u503C\uFF0C\u53EF\u80FD\u9020\u6210\u95EE\u9898"))}},I=o.defineComponent({props:{events:{type:Array}},setup:e=>{const{mapRef:a}=m();return k(a.value,e.events),()=>null}}),z=o.defineComponent({props:{...J()},setup:(e,{slots:a,expose:r})=>{q(e.securityJsCode);const n=o.shallowRef(),t=o.ref();return r({mapRef:n,domRef:t}),i.useEffect(()=>(x.default.load({version:"2.0",...e.loadOpts}).then(c=>{const p=new c.Map(t.value,{...e.opts});p.on("complete",()=>{n.value=p})}).catch(c=>{console.error("\u52A0\u8F7D\u5730\u56FE\u9519\u8BEF"),console.error(c)}),()=>{n.value&&n.value.destroy()}),[]),R({mapRef:n}),()=>{var c;return o.createVNode("div",{ref:t},[n.value&&o.createVNode(I,{events:e.events},null),n.value&&((c=a.default)==null?void 0:c.call(a))])}}}),B=(e,a)=>{const{mapRef:r}=m();i.useEffect(()=>{if(!r.value){console.warn("\u8BF7\u5728Map\u7EC4\u4EF6\u5185\u4F7F\u7528 useMapPlugin");return}if(!e||u.size(e)<=0){a();return}window.AMap.plugin(e,a)},[])},H=o.defineComponent({props:{plugins:Array},setup:(e,{slots:a})=>{const r=o.ref(!1);return B(e.plugins,()=>{r.value=!0}),()=>{var n;return r.value?(n=a.default)==null?void 0:n.call(a):null}}}),A={ElasticMarker:"AMap.ElasticMarker",ControlBar:"AMap.ControlBar",ToolBar:"AMap.ToolBar",Scale:"AMap.Scale",HawkEye:"AMap.HawkEye",MapType:"AMap.MapType",AdvancedInfoWindow:"AMap.AdvancedInfoWindow",DragRoute:"AMap.DragRoute",IndoorMap:"AMap.IndoorMap",MouseTool:"AMap.MouseTool",CircleEditor:"AMap.CircleEditor",PolygonEditor:"AMap.PolygonEditor",PolylineEditor:"AMap.PolylineEditor",MarkerCluster:"AMap.MarkerCluster",RangingTool:"AMap.RangingTool",Geolocation:"AMap.Geolocation",Geocoder:"AMap.Geocoder",AutoComplete:"AMap.AutoComplete",PlaceSearch:"AMap.PlaceSearch",LineSearch:"AMap.LineSearch",DistrictSearch:"AMap.DistrictSearch",StationSearch:"AMap.StationSearch",CitySearch:"AMap.CitySearch",CloudDataSearch:"AMap.CloudDataSearch",RoadInfoSearch:"AMap.RoadInfoSearch",Driving:"AMap.Driving",TruckDriving:"AMap.TruckDriving",Transfer:"AMap.Transfer",Walking:"AMap.Walking",Riding:"AMap.Riding",ArrivalRange:"AMap.ArrivalRange",GraspRoad:"AMap.GraspRoad",HeatMap:"AMap.HeatMap",Weather:"AMap.Weather"},F=e=>{const{mapRef:a}=m();i.useEffect(()=>(a.value.add(e),()=>{try{a.value.remove(e)}catch(r){console.error(r)}}),[])},_=e=>{const{mapRef:a}=m();i.useEffect(()=>(e.setMap(a.value),()=>{try{e.setMap(null)}catch(r){console.error(r)}}),[])},g=e=>{const{mapRef:a}=m();i.useEffect(()=>(a.value.addControl(e),()=>{try{a.value.removeControl(e)}catch(r){console.error(r)}}),[])},S=(e,a)=>{const r=()=>{e&&u.isFunction(e.show)&&e.show()},n=()=>{e&&u.isFunction(e.hide)&&e.hide()};i.useEffect(()=>{a.value||n()},[]),i.useWatch(()=>{a.value?r():n()},a)},E=(e,a)=>{i.useEffect(()=>{u.forEach(a.value,(r,n)=>{const t="set"+u.upperFirst(n);e[t]&&u.isFunction(e[t])&&e[t](r)})},a)},s=(e,{useMapConnect:a,createFeatureObj:r,needDom:n})=>o.defineComponent({props:{opts:{type:Object},opts$:{type:Object},show:{type:Boolean,default:!0},events:{type:Array}},setup:(t,{slots:c,expose:p})=>{const l=r?r(t.opts):new window.AMap[e](t.opts);a(l);const M=o.toRef(t,"show");S(l,M);const f=o.toRef(t,"opts$");E(l,f),k(l,t.events),p({getFeature:()=>l});const C=o.ref();return i.useEffect(()=>{C.value&&u.isFunction(l.setContent)&&l.setContent(C.value)},C),()=>n&&c.default?o.createVNode(o.Teleport,{to:"body"},{default:()=>[o.createVNode("div",{ref:C},[c.default()])]}):null}}),w=(e,a)=>o.defineComponent({props:{...a.props},setup:(r,{slots:n,expose:t})=>{const c=o.ref();return t(i.createExposeObj(c,["getFeature"])),()=>o.createVNode(H,{plugins:e},{default:()=>[o.createVNode(a,o.mergeProps({ref:c},r),n)]})}}),K=()=>{const{mapRef:e,overlayGroup:a}=m();return{addToMap:t=>{if(a){u.isArray(t)?a.addOverlays(t):a.addOverlay(t);return}e.value.add(t)},removeFromMap:t=>{if(a){u.isArray(t)?a.removeOverlays(t):a.removeOverlay(t);return}try{e.value.remove(t)}catch(c){console.error(c)}}}},h=e=>{const{addToMap:a,removeFromMap:r}=K();i.useEffect(()=>(a(e),()=>{r(e)}),[])},Q=o.defineComponent({props:{bind:{type:Boolean,default:!1},bindTime:{type:Number,default:void 0},opts$:{type:Object},show:{type:Boolean,default:!0},events:{type:Array}},setup:(e,{slots:a,expose:r})=>{const{mapRef:n}=m(),t=new window.AMap.OverlayGroup;let c=!1;const p=()=>{c||(n.value.add(t),c=!0)},l=()=>{try{n.value.remove(t)}catch(d){console.error(d)}c=!1},M=()=>t;i.useEffect(()=>()=>{l()},[]),i.useEffect(()=>{if(!u.isNumber(e.bindTime))return;const d=setTimeout(()=>{p()},e.bindTime);return()=>{d&&clearTimeout(d)}},[]);const f=u.debounce(()=>{p()},300);i.useWatch(()=>{e.bind&&f()},()=>e.bind);const C=o.toRef(e,"show");S(t,C);const T=o.toRef(e,"opts$");return E(t,T),r({getFeature:M,addToMap:p,removeFormMap:l}),R({mapRef:n,overlayGroup:t}),()=>{var d;return(d=a.default)==null?void 0:d.call(a)}}}),U=o.defineComponent({props:{opts:{type:Object},opts$:{type:Object},height:{type:Number,default:void 0}},setup:(e,{slots:a,emit:r})=>{const{mapRef:n}=m(),t=new window.AMap.InfoWindow({closeWhenClickMap:!0,isCustom:!!a.default,...e.opts}),c=o.toRef(e,"opts$");E(t,c);const p=()=>{r("close")};i.useEffect(()=>(t.on("close",p),()=>{t.off("close",p),t.close()}),[]),i.useEffect(()=>{var f,C;const M=((f=e.opts$)==null?void 0:f.position)||((C=e.opts)==null?void 0:C.position);!M||t.open(n.value,M,e.height)},()=>{var M;return(M=e.opts$)==null?void 0:M.position});const l=o.ref();return i.useEffect(()=>{l.value&&u.isFunction(t.setContent)&&t.setContent(l.value)},l),()=>a.default?o.createVNode(o.Teleport,{to:"body"},{default:()=>[o.createVNode("div",{ref:l},[a.default()])]}):null}}),X=s("CircleMarker",{useMapConnect:F}),Y=s("Text",{useMapConnect:F}),Z=s("ElasticMarker",{useMapConnect:F}),ee=s("Marker",{useMapConnect:h,needDom:!0}),ae=s("Polygon",{useMapConnect:h}),te=s("Polyline",{useMapConnect:h}),re=s("Circle",{useMapConnect:h}),ne=s("Rectangle",{useMapConnect:h}),oe=s("Ellipse",{useMapConnect:h}),ce=s("BezierCurve",{useMapConnect:h}),se=s("ToolBar",{useMapConnect:g}),ue=w([A.ToolBar],se),ie=s("Scale",{useMapConnect:g}),le=w([A.Scale],ie),pe=s("HawkEye",{useMapConnect:g}),de=w([A.HawkEye],pe),Me=s("MapType",{useMapConnect:g}),fe=w([A.MapType],Me),ye=s("ControlBar",{useMapConnect:g}),Ce=w([A.ControlBar],ye),me=()=>{const{mapRef:e,layerGroup:a}=m();return{addToMap:t=>{if(a){u.isArray(t)?a.addLayers(t):a.addLayer(t);return}e.value.add(t)},removeFromMap:t=>{if(a){u.isArray(t)?a.removeLayers(t):a.removeLayer(t);return}try{e.value.remove(t)}catch(c){console.error(c)}}}},y=e=>{const{addToMap:a,removeFromMap:r}=me();i.useEffect(()=>(a(e),()=>{r(e)}),[])},ve=o.defineComponent({props:{bind:{type:Boolean,default:!1},bindTime:{type:Number,default:void 0},opts$:{type:Object},show:{type:Boolean,default:!0},events:{type:Array}},setup:(e,{slots:a,expose:r})=>{const{mapRef:n}=m(),t=new window.AMap.LayerGroup;let c=!1;const p=()=>{c||(t.setMap(n.value),c=!0)},l=()=>{try{t.setMap(null)}catch(d){console.error(d)}c=!1},M=()=>t;i.useEffect(()=>()=>{l()},[]),i.useEffect(()=>{if(!u.isNumber(e.bindTime))return;const d=setTimeout(()=>{p()},e.bindTime);return()=>{d&&clearTimeout(d)}},[]);const f=u.debounce(()=>{p()},300);i.useWatch(()=>{e.bind&&f()},()=>e.bind);const C=o.toRef(e,"show");S(t,C);const T=o.toRef(e,"opts$");return E(t,T),r({getFeature:M,addToMap:p,removeFormMap:l}),R({mapRef:n,layerGroup:t}),()=>{var d;return(d=a.default)==null?void 0:d.call(a)}}}),he=o.defineComponent({props:{opts:{type:Object},itemOpts:{type:Object},data:{type:Array},show:{type:Boolean,default:!0},events:{type:Array}},setup:(e,{expose:a})=>{const{mapRef:r}=m(),n=new window.AMap.LabelsLayer(e.opts),t=()=>u.map(e.data,l=>{const M=new window.AMap.LabelMarker({...e.itemOpts,...l});return e.events&&u.forEach(e.events,f=>{M.on(f.type,f.handler,void 0,f.once)}),M}),c=()=>{n.clear();const l=t();n.add(l)};i.useEffect(()=>(u.size(e.data)>0&&c(),r.value.add(n),()=>{n.clear(),r.value.remove(n)}),[]),i.useWatch(()=>{c()},()=>e.data);const p=o.toRef(e,"show");return S(n,p),a({getFeature:()=>n}),()=>null}}),Ae=s("TileLayer",{useMapConnect:y}),we=s("TileLayer.Satellite",{useMapConnect:y,createFeatureObj:e=>new window.AMap.TileLayer.Satellite(e)}),Te=s("TileLayer.RoadNet",{useMapConnect:y,createFeatureObj:e=>new window.AMap.TileLayer.RoadNet(e)}),ge=s("TileLayer.Traffic",{useMapConnect:y,createFeatureObj:e=>new window.AMap.TileLayer.Traffic(e)}),Le=s("Buildings",{useMapConnect:y}),Se=s("MassMarks",{useMapConnect:_,createFeatureObj:e=>new window.AMap.MassMarks((e==null?void 0:e.data)||[],u.omit(e,"data"))}),Ee=s("TileLayer.Flexible",{useMapConnect:y,createFeatureObj:e=>new window.AMap.TileLayer.Flexible(e)}),be=s("ImageLayer",{useMapConnect:y}),Re=s("VideoLayer",{useMapConnect:y}),Fe=s("CanvasLayer",{useMapConnect:y}),Oe=s("CustomLayer",{useMapConnect:y,createFeatureObj:e=>new window.AMap.CustomLayer(e==null?void 0:e.canvas,u.omit(e,"canvas"))}),Pe=s("DistrictLayer.World",{useMapConnect:y,createFeatureObj:e=>new window.AMap.DistrictLayer.World(e)}),ke=s("DistrictLayer.Country",{useMapConnect:y,createFeatureObj:e=>new window.AMap.DistrictLayer.Country(e)}),Be=s("DistrictLayer.Province",{useMapConnect:y,createFeatureObj:e=>new window.AMap.DistrictLayer.Province(e)}),_e=s("HeatMap",{useMapConnect:_,createFeatureObj:e=>new window.AMap.HeatMap(null,e)}),De=w([A.HeatMap],_e),Ne=(e,a)=>{let r=!1,n=null;const[t,c]=i.useState(),p=o.ref(u.isBoolean(a.initEmit)?a.initEmit:!1),l=u.split(e,"_"),M=l[0],f=l[1],C=()=>{const v=u.get(window,M);return v?new v({...a.opts,...n==null?void 0:n.opts}):null},T=v=>v||(u.isFunction(a.params)?a.params():a.params||[]),d=()=>{if(!n)return;const v=C();if(!v||!u.isFunction(v[f]))return;const P=T(n.params);p.value=!0,v[f](...P,(b,L)=>{var D,N,j,G;c(L),(D=a.onComplete)==null||D.call(a,b,L),b==="complete"?(N=a.onSuccess)==null||N.call(a,L):b==="error"?(j=a.onFail)==null||j.call(a,L):b==="no_data"&&((G=a.onNoData)==null||G.call(a,L)),n=null,p.value=!1})};B([M],()=>{r=!0,d()});const O=(v,P)=>{n={opts:v||a.opts,params:T(P)},r&&d()};return i.useEffect(()=>{a.initEmit&&O()},[]),i.useWatch(()=>O(),a.deps||[]),{data:t,request:O,requesting:p}},je={Geocoder_getLocation:"AMap.Geocoder_getLocation",Geocoder_getAddress:"AMap.Geocoder_getAddress",Autocomplete_search:"AMap.Autocomplete_search",PlaceSearch_search:"AMap.PlaceSearch_search",PlaceSearch_searchNearBy:"AMap.PlaceSearch_searchNearBy",PlaceSearch_searchInBounds:"AMap.PlaceSearch_searchInBounds",PlaceSearch_getDetails:"AMap.PlaceSearch_getDetails",DistrictSearch_search:"AMap.DistrictSearch_search",LineSearch_search:"AMap.LineSearch_search",LineSearch_searchById:"AMap.LineSearch_searchById",StationSearch_search:"AMap.StationSearch_search",StationSearch_searchById:"AMap.StationSearch_searchById"};exports.ApiNames=je;exports.BezierCurve=ce;exports.Buildings=Le;exports.CanvasLayer=Fe;exports.Circle=re;exports.CircleMarker=X;exports.ControlBar=Ce;exports.CustomLayer=Oe;exports.DistrictLayerCountry=ke;exports.DistrictLayerProvince=Be;exports.DistrictLayerWorld=Pe;exports.ElasticMarker=Z;exports.Ellipse=oe;exports.HawkEye=de;exports.HeatMap=De;exports.ImageLayer=be;exports.InfoWindow=U;exports.LabelsLayer=he;exports.LayerGroup=ve;exports.Map=z;exports.MapEvents=I;exports.MapPlugin=H;exports.MapPluginType=A;exports.MapType=fe;exports.Marker=ee;exports.MassMarks=Se;exports.OverlayGroup=Q;exports.Polygon=ae;exports.Polyline=te;exports.Rectangle=ne;exports.Scale=le;exports.Text=Y;exports.TileLayer=Ae;exports.TileLayerFlexible=Ee;exports.TileLayerRoadNet=Te;exports.TileLayerSatellite=we;exports.TileLayerTraffic=ge;exports.ToolBar=ue;exports.VideoLayer=Re;exports.createFeature=s;exports.createPluginFeature=w;exports.provideMap=R;exports.useEvents=k;exports.useFeatureOptMethods=E;exports.useMap=m;exports.useMapApi=Ne;exports.useMapConnect=F;exports.useMapConnect2=_;exports.useMapControlConnect=g;exports.useMapLayerConnect=y;exports.useMapOverlayConnect=h;exports.useMapPlugin=B;exports.useShowConnect=S;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const c=require("vue"),x=require("@amap/amap-jsapi-loader"),l=require("@vue-start/hooks"),u=require("lodash"),$=e=>e&&typeof e=="object"&&"default"in e?e:{default:e},J=$(x),_=(e,a)=>{l.useEffect(()=>(u.forEach(a,n=>{e.on(n.type,n.handler,void 0,n.once)}),()=>{u.forEach(a,n=>{e.off(n.type,n.handler)})}),[])},I=Symbol("amap-key"),R=e=>c.provide(I,e),h=()=>c.inject(I),q=()=>({securityJsCode:{type:String},loadOpts:{type:Object},opts:{type:Object},events:{type:Array}}),z=e=>{var a;if(!!e){if(!window._AMapSecurityConfig||!((a=window._AMapSecurityConfig)!=null&&a.securityJsCode)){window._AMapSecurityConfig={securityJsCode:e};return}window._AMapSecurityConfig.securityJsCode!==e&&(window._AMapSecurityConfig={securityJsCode:e},console.warn("\u5F53\u524Dwindow\u5BF9\u8C61\u5DF2\u7ECF\u6CE8\u5165\u8FC7securityJsCode\u503C\uFF0C\u53EF\u80FD\u9020\u6210\u95EE\u9898"))}},H=c.defineComponent({props:{events:{type:Array}},setup:e=>{const{mapRef:a}=h();return _(a.value,e.events),()=>null}}),K=c.defineComponent({props:{...q()},setup:(e,{slots:a,expose:n})=>{z(e.securityJsCode);const r=c.shallowRef(),t=c.ref();return n({mapRef:r,domRef:t}),l.useEffect(()=>(J.default.load({version:"2.0",...e.loadOpts}).then(o=>{const p=new o.Map(t.value,{...e.opts});p.on("complete",()=>{r.value=p})}).catch(o=>{console.error("\u52A0\u8F7D\u5730\u56FE\u9519\u8BEF"),console.error(o)}),()=>{r.value&&r.value.destroy()}),[]),R({mapRef:r}),()=>{var o;return c.createVNode("div",{ref:t},[r.value&&c.createVNode(H,{events:e.events},null),r.value&&((o=a.default)==null?void 0:o.call(a))])}}}),B=(e,a)=>{const{mapRef:n}=h();l.useEffect(()=>{if(!n.value){console.warn("\u8BF7\u5728Map\u7EC4\u4EF6\u5185\u4F7F\u7528 useMapPlugin");return}if(!e||u.size(e)<=0){a();return}window.AMap.plugin(e,a)},[])},V=c.defineComponent({props:{plugins:Array},setup:(e,{slots:a})=>{const n=c.ref(!1);return B(e.plugins,()=>{n.value=!0}),()=>{var r;return n.value?(r=a.default)==null?void 0:r.call(a):null}}}),A={ElasticMarker:"AMap.ElasticMarker",ControlBar:"AMap.ControlBar",ToolBar:"AMap.ToolBar",Scale:"AMap.Scale",HawkEye:"AMap.HawkEye",MapType:"AMap.MapType",AdvancedInfoWindow:"AMap.AdvancedInfoWindow",DragRoute:"AMap.DragRoute",IndoorMap:"AMap.IndoorMap",MouseTool:"AMap.MouseTool",CircleEditor:"AMap.CircleEditor",PolygonEditor:"AMap.PolygonEditor",PolylineEditor:"AMap.PolylineEditor",MarkerCluster:"AMap.MarkerCluster",RangingTool:"AMap.RangingTool",Geolocation:"AMap.Geolocation",Geocoder:"AMap.Geocoder",AutoComplete:"AMap.AutoComplete",PlaceSearch:"AMap.PlaceSearch",LineSearch:"AMap.LineSearch",DistrictSearch:"AMap.DistrictSearch",StationSearch:"AMap.StationSearch",CitySearch:"AMap.CitySearch",CloudDataSearch:"AMap.CloudDataSearch",RoadInfoSearch:"AMap.RoadInfoSearch",Driving:"AMap.Driving",TruckDriving:"AMap.TruckDriving",Transfer:"AMap.Transfer",Walking:"AMap.Walking",Riding:"AMap.Riding",ArrivalRange:"AMap.ArrivalRange",GraspRoad:"AMap.GraspRoad",HeatMap:"AMap.HeatMap",Weather:"AMap.Weather"},F=e=>{const{mapRef:a}=h();l.useEffect(()=>(a.value.add(e),()=>{try{a.value.remove(e)}catch(n){console.error(n)}}),[])},k=e=>{const{mapRef:a}=h();l.useEffect(()=>(e.setMap(a.value),()=>{try{e.setMap(null)}catch(n){console.error(n)}}),[])},T=e=>{const{mapRef:a}=h();l.useEffect(()=>(a.value.addControl(e),()=>{try{a.value.removeControl(e)}catch(n){console.error(n)}}),[])},S=(e,a)=>{const n=()=>{e&&u.isFunction(e.show)&&e.show()},r=()=>{e&&u.isFunction(e.hide)&&e.hide()};l.useEffect(()=>{a.value||r()},[]),l.useWatch(()=>{a.value?n():r()},a)},E=(e,a)=>{const n=(r,t)=>{const o="set"+u.upperFirst(r);if(e[o]&&u.isFunction(e[o]))e[o](t);else{const p="set"+r;e[p]&&u.isFunction(e[p])&&e[p](t)}};l.useEffect((r,t)=>{u.forEach(a.value,(o,p)=>{(t==null?void 0:t[p])!==o&&n(p,o)})},a)},s=(e,{useMapConnect:a,createFeatureObj:n,needDom:r})=>c.defineComponent({props:{opts:{type:Object},opts$:{type:Object},show:{type:Boolean,default:!0},events:{type:Array}},setup:(t,{slots:o,expose:p})=>{const i=n?n(t.opts):new window.AMap[e](t.opts);a(i);const M=c.toRef(t,"show");S(i,M);const f=c.toRef(t,"opts$");E(i,f),_(i,t.events),p({getFeature:()=>i});const y=c.ref();return l.useEffect(()=>{y.value&&u.isFunction(i.setContent)&&i.setContent(y.value)},y),()=>r&&o.default?c.createVNode(c.Teleport,{to:"body"},{default:()=>[c.createVNode("div",{ref:y},[o.default()])]}):null}}),w=(e,a)=>c.defineComponent({props:{...a.props},setup:(n,{slots:r,expose:t})=>{const o=c.ref();return t(l.createExposeObj(o,["getFeature"])),()=>c.createVNode(V,{plugins:e},{default:()=>[c.createVNode(a,c.mergeProps({ref:o},n),r)]})}}),Q=()=>{const{mapRef:e,overlayGroup:a}=h();return{addToMap:t=>{if(a){u.isArray(t)?a.addOverlays(t):a.addOverlay(t);return}e.value.add(t)},removeFromMap:t=>{if(a){u.isArray(t)?a.removeOverlays(t):a.removeOverlay(t);return}try{e.value.remove(t)}catch(o){console.error(o)}}}},v=e=>{const{addToMap:a,removeFromMap:n}=Q();l.useEffect(()=>(a(e),()=>{n(e)}),[])},U=c.defineComponent({props:{bind:{type:Boolean,default:!1},bindTime:{type:Number,default:void 0},opts$:{type:Object},show:{type:Boolean,default:!0},events:{type:Array}},setup:(e,{slots:a,expose:n})=>{const{mapRef:r}=h(),t=new window.AMap.OverlayGroup;let o=!1;const p=()=>{o||(r.value.add(t),o=!0)},i=()=>{try{r.value.remove(t)}catch(d){console.error(d)}o=!1},M=()=>t;l.useEffect(()=>()=>{i()},[]),l.useEffect(()=>{if(!u.isNumber(e.bindTime))return;const d=setTimeout(()=>{p()},e.bindTime);return()=>{d&&clearTimeout(d)}},[]);const f=u.debounce(()=>{p()},300);l.useWatch(()=>{e.bind&&f()},()=>e.bind);const y=c.toRef(e,"show");S(t,y);const g=c.toRef(e,"opts$");return E(t,g),n({getFeature:M,addToMap:p,removeFormMap:i}),R({mapRef:r,overlayGroup:t}),()=>{var d;return(d=a.default)==null?void 0:d.call(a)}}}),X=c.defineComponent({props:{opts:{type:Object},opts$:{type:Object},height:{type:Number,default:void 0}},setup:(e,{slots:a,emit:n})=>{const{mapRef:r}=h(),t=new window.AMap.InfoWindow({closeWhenClickMap:!0,isCustom:!!a.default,...e.opts}),o=c.toRef(e,"opts$");E(t,o);const p=()=>{n("close")};l.useEffect(()=>(t.on("close",p),()=>{t.off("close",p),t.close()}),[]),l.useEffect(()=>{var f,y;const M=((f=e.opts$)==null?void 0:f.position)||((y=e.opts)==null?void 0:y.position);!M||t.open(r.value,M,e.height)},()=>{var M;return(M=e.opts$)==null?void 0:M.position});const i=c.ref();return l.useEffect(()=>{i.value&&u.isFunction(t.setContent)&&t.setContent(i.value)},i),()=>a.default?c.createVNode(c.Teleport,{to:"body"},{default:()=>[c.createVNode("div",{ref:i},[a.default()])]}):null}}),Y=s("CircleMarker",{useMapConnect:F}),Z=s("Text",{useMapConnect:F}),ee=s("ElasticMarker",{useMapConnect:F}),ae=s("Marker",{useMapConnect:v,needDom:!0}),te=s("Polygon",{useMapConnect:v}),re=s("Polyline",{useMapConnect:v}),ne=s("Circle",{useMapConnect:v}),oe=s("Rectangle",{useMapConnect:v}),ce=s("Ellipse",{useMapConnect:v}),se=s("BezierCurve",{useMapConnect:v}),ue=s("ToolBar",{useMapConnect:T}),ie=w([A.ToolBar],ue),le=s("Scale",{useMapConnect:T}),pe=w([A.Scale],le),de=s("HawkEye",{useMapConnect:T}),Me=w([A.HawkEye],de),fe=s("MapType",{useMapConnect:T}),ye=w([A.MapType],fe),Ce=s("ControlBar",{useMapConnect:T}),me=w([A.ControlBar],Ce),he=()=>{const{mapRef:e,layerGroup:a}=h();return{addToMap:t=>{if(a){u.isArray(t)?a.addLayers(t):a.addLayer(t);return}e.value.add(t)},removeFromMap:t=>{if(a){u.isArray(t)?a.removeLayers(t):a.removeLayer(t);return}try{e.value.remove(t)}catch(o){console.error(o)}}}},C=e=>{const{addToMap:a,removeFromMap:n}=he();l.useEffect(()=>(a(e),()=>{n(e)}),[])},ve=c.defineComponent({props:{bind:{type:Boolean,default:!1},bindTime:{type:Number,default:void 0},opts$:{type:Object},show:{type:Boolean,default:!0},events:{type:Array}},setup:(e,{slots:a,expose:n})=>{const{mapRef:r}=h(),t=new window.AMap.LayerGroup;let o=!1;const p=()=>{o||(t.setMap(r.value),o=!0)},i=()=>{try{t.setMap(null)}catch(d){console.error(d)}o=!1},M=()=>t;l.useEffect(()=>()=>{i()},[]),l.useEffect(()=>{if(!u.isNumber(e.bindTime))return;const d=setTimeout(()=>{p()},e.bindTime);return()=>{d&&clearTimeout(d)}},[]);const f=u.debounce(()=>{p()},300);l.useWatch(()=>{e.bind&&f()},()=>e.bind);const y=c.toRef(e,"show");S(t,y);const g=c.toRef(e,"opts$");return E(t,g),n({getFeature:M,addToMap:p,removeFormMap:i}),R({mapRef:r,layerGroup:t}),()=>{var d;return(d=a.default)==null?void 0:d.call(a)}}}),Ae=c.defineComponent({props:{opts:{type:Object},itemOpts:{type:Object},data:{type:Array},show:{type:Boolean,default:!0},events:{type:Array}},setup:(e,{expose:a})=>{const{mapRef:n}=h(),r=new window.AMap.LabelsLayer(e.opts),t=()=>u.map(e.data,i=>{const M=new window.AMap.LabelMarker({...e.itemOpts,...i});return e.events&&u.forEach(e.events,f=>{M.on(f.type,f.handler,void 0,f.once)}),M}),o=()=>{r.clear();const i=t();r.add(i)};l.useEffect(()=>(u.size(e.data)>0&&o(),n.value.add(r),()=>{r.clear(),n.value.remove(r)}),[]),l.useWatch(()=>{o()},()=>e.data);const p=c.toRef(e,"show");return S(r,p),a({getFeature:()=>r}),()=>null}}),we=s("TileLayer",{useMapConnect:C}),Te=s("TileLayer.Satellite",{useMapConnect:C,createFeatureObj:e=>new window.AMap.TileLayer.Satellite(e)}),ge=s("TileLayer.RoadNet",{useMapConnect:C,createFeatureObj:e=>new window.AMap.TileLayer.RoadNet(e)}),Le=s("TileLayer.Traffic",{useMapConnect:C,createFeatureObj:e=>new window.AMap.TileLayer.Traffic(e)}),Se=s("Buildings",{useMapConnect:C}),Ee=s("MassMarks",{useMapConnect:k,createFeatureObj:e=>new window.AMap.MassMarks((e==null?void 0:e.data)||[],u.omit(e,"data"))}),be=s("TileLayer.Flexible",{useMapConnect:C,createFeatureObj:e=>new window.AMap.TileLayer.Flexible(e)}),Re=s("ImageLayer",{useMapConnect:C}),Fe=s("VideoLayer",{useMapConnect:C}),Oe=s("CanvasLayer",{useMapConnect:C}),Pe=s("CustomLayer",{useMapConnect:C,createFeatureObj:e=>new window.AMap.CustomLayer(e==null?void 0:e.canvas,u.omit(e,"canvas"))}),_e=s("DistrictLayer.World",{useMapConnect:C,createFeatureObj:e=>new window.AMap.DistrictLayer.World(e)}),Be=s("DistrictLayer.Country",{useMapConnect:C,createFeatureObj:e=>new window.AMap.DistrictLayer.Country(e)}),ke=s("DistrictLayer.Province",{useMapConnect:C,createFeatureObj:e=>new window.AMap.DistrictLayer.Province(e)}),De=s("HeatMap",{useMapConnect:k,createFeatureObj:e=>new window.AMap.HeatMap(null,e)}),je=w([A.HeatMap],De),Ne=(e,a)=>{let n=!1,r=null;const t=c.shallowRef(),[o,p]=l.useState(),i=c.ref(u.isBoolean(a.initEmit)?a.initEmit:!1),M=u.split(e,"_"),f=M[0],y=M[1],g=()=>{const m=u.get(window,f);return m?new m({...a.opts,...r==null?void 0:r.opts}):null},d=m=>m||(u.isFunction(a.params)?a.params():a.params||[]),D=()=>{if(!r)return;const m=g();if(t.value=m,!m||!u.isFunction(m[y]))return;const P=d(r.params);return i.value=!0,m[y](...P,(b,L)=>{var j,N,G,W;p(L),(j=a.onComplete)==null||j.call(a,b,L),b==="complete"?(N=a.onSuccess)==null||N.call(a,L):b==="error"?(G=a.onFail)==null||G.call(a,L):b==="no_data"&&((W=a.onNoData)==null||W.call(a,L)),r=null,i.value=!1}),m};B([f],()=>{n=!0,D()});const O=(m,P)=>{if(r={opts:m||a.opts,params:d(P)},!!n)return D()};return l.useEffect(()=>{a.initEmit&&O()},[]),l.useWatch(()=>O(),a.deps||[]),{data:o,request:O,requesting:i,targetRef:t}},Ge={Geocoder_getLocation:"AMap.Geocoder_getLocation",Geocoder_getAddress:"AMap.Geocoder_getAddress",Autocomplete_search:"AMap.Autocomplete_search",PlaceSearch_search:"AMap.PlaceSearch_search",PlaceSearch_searchNearBy:"AMap.PlaceSearch_searchNearBy",PlaceSearch_searchInBounds:"AMap.PlaceSearch_searchInBounds",PlaceSearch_getDetails:"AMap.PlaceSearch_getDetails",DistrictSearch_search:"AMap.DistrictSearch_search",LineSearch_search:"AMap.LineSearch_search",LineSearch_searchById:"AMap.LineSearch_searchById",StationSearch_search:"AMap.StationSearch_search",StationSearch_searchById:"AMap.StationSearch_searchById"};exports.ApiNames=Ge;exports.BezierCurve=se;exports.Buildings=Se;exports.CanvasLayer=Oe;exports.Circle=ne;exports.CircleMarker=Y;exports.ControlBar=me;exports.CustomLayer=Pe;exports.DistrictLayerCountry=Be;exports.DistrictLayerProvince=ke;exports.DistrictLayerWorld=_e;exports.ElasticMarker=ee;exports.Ellipse=ce;exports.HawkEye=Me;exports.HeatMap=je;exports.ImageLayer=Re;exports.InfoWindow=X;exports.LabelsLayer=Ae;exports.LayerGroup=ve;exports.Map=K;exports.MapEvents=H;exports.MapPlugin=V;exports.MapPluginType=A;exports.MapType=ye;exports.Marker=ae;exports.MassMarks=Ee;exports.OverlayGroup=U;exports.Polygon=te;exports.Polyline=re;exports.Rectangle=oe;exports.Scale=pe;exports.Text=Z;exports.TileLayer=we;exports.TileLayerFlexible=be;exports.TileLayerRoadNet=ge;exports.TileLayerSatellite=Te;exports.TileLayerTraffic=Le;exports.ToolBar=ie;exports.VideoLayer=Fe;exports.createFeature=s;exports.createPluginFeature=w;exports.provideMap=R;exports.useEvents=_;exports.useFeatureOptMethods=E;exports.useMap=h;exports.useMapApi=Ne;exports.useMapConnect=F;exports.useMapConnect2=k;exports.useMapControlConnect=T;exports.useMapLayerConnect=C;exports.useMapOverlayConnect=v;exports.useMapPlugin=B;exports.useShowConnect=S;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue-start/map",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "amap wrapper",
5
5
  "keywords": [
6
6
  "amap"
@@ -30,5 +30,5 @@
30
30
  "dependencies": {
31
31
  "@amap/amap-jsapi-loader": "^1.0.1"
32
32
  },
33
- "gitHead": "da60ad3ea417c123ef11c3d385d447f0451a70c0"
33
+ "gitHead": "dd1b977211bd0db823224570b4a48892aab7c9c1"
34
34
  }