@mint-ui/map 0.1.5-beta → 0.1.7-beta

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.
@@ -10,6 +10,7 @@ export interface MintMapProps extends MintMapEvents {
10
10
  mapId?: string;
11
11
  base?: BaseProps;
12
12
  visible?: boolean;
13
+ markerCache?: boolean;
13
14
  }
14
15
  export interface MintMapEvents {
15
16
  onBoundsChanged?: (bounds: Bounds) => void;
@@ -44,9 +44,11 @@ function MapMarkerWrapper(_a) {
44
44
  }
45
45
  }, [movingState]);
46
46
  React.useEffect(function () {
47
- setMovingState(tslib.__assign(tslib.__assign({}, movingAnimation), {
48
- marker: markerRef.current
49
- }));
47
+ if (movingAnimation) {
48
+ setMovingState(tslib.__assign(tslib.__assign({}, movingAnimation), {
49
+ marker: markerRef.current
50
+ }));
51
+ }
50
52
  }, [movingAnimation]);
51
53
  var start = MarkerMovingHook.useMarkerMoving(movingState)[0];
52
54
 
@@ -119,9 +121,11 @@ function MapMarkerWrapper(_a) {
119
121
  React.useEffect(function () {
120
122
  if (options) {
121
123
  if (markerRef.current) {
124
+ console.log('update Marker');
122
125
  controller.updateMarker(markerRef.current, options);
123
126
  offsetCalibration(controller.getMapType(), divElement, options);
124
127
  } else {
128
+ console.log('create Marker');
125
129
  markerRef.current = new MintMap.Marker(options);
126
130
  markerRef.current.element = divElement;
127
131
  controller.createMarker(markerRef.current);
@@ -1,12 +1,15 @@
1
1
  /// <reference types="navermaps" />
2
2
  import { MintMapController } from "../core/MintMapController";
3
3
  import { Bounds, Drawable, MapType, MapVendorType, Marker, MarkerOptions, MintMapProps, Polygon, PolygonOptions, Polyline, PolylineOptions, Position } from "../MintMap";
4
+ import { ObjectPool } from '@mint-ui/tools';
4
5
  export declare class NaverMintMapController extends MintMapController {
5
6
  type: MapType;
6
7
  map: naver.maps.Map | null;
7
8
  scriptUrl: string;
8
9
  scriptModules: string[];
10
+ markerPool?: ObjectPool<naver.maps.Marker>;
9
11
  constructor(props: MintMapProps);
12
+ private initMarkerPool;
10
13
  polylineEvents: string[];
11
14
  createPolyline(polyline: Polyline): void;
12
15
  updatePolyline(polyline: Polyline, options: PolylineOptions): void;
@@ -6,6 +6,7 @@ var tslib = require('tslib');
6
6
  var MintMapController = require('../core/MintMapController.js');
7
7
  var waiting = require('../core/util/waiting.js');
8
8
  var MintMap = require('../MintMap.js');
9
+ var tools = require('@mint-ui/tools');
9
10
 
10
11
  var NaverMintMapController = function (_super) {
11
12
  tslib.__extends(NaverMintMapController, _super);
@@ -26,6 +27,20 @@ var NaverMintMapController = function (_super) {
26
27
  return _this;
27
28
  }
28
29
 
30
+ NaverMintMapController.prototype.initMarkerPool = function () {
31
+ var _this = this;
32
+
33
+ if (!this.mapProps.markerCache) return;
34
+ this.markerPool = new tools.ObjectPool().setFactory(function () {
35
+ return new naver.maps.Marker({
36
+ position: new MintMap.Position(0, 0),
37
+ map: _this.map || undefined
38
+ });
39
+ }).setClear(function (item) {
40
+ item.setMap(null);
41
+ }).createPool(1000).setCheckLiveTimeInterval(1000);
42
+ };
43
+
29
44
  NaverMintMapController.prototype.createPolyline = function (polyline) {
30
45
  var _this = this;
31
46
 
@@ -163,8 +178,19 @@ var NaverMintMapController = function (_super) {
163
178
  content: marker.element,
164
179
  anchor: marker.options.anchor
165
180
  });
166
- var naverMarker_1 = new naver.maps.Marker(options);
167
- marker.native = naverMarker_1;
181
+ var naverMarker_1;
182
+
183
+ if (this.mapProps.markerCache && this.markerPool) {
184
+ naverMarker_1 = this.markerPool.getPoolItem();
185
+ naverMarker_1.setVisible(true);
186
+ options.icon && naverMarker_1.setIcon(options.icon);
187
+ marker.native = naverMarker_1;
188
+ this.updateMarker(marker, marker.options);
189
+ } else {
190
+ naverMarker_1 = new naver.maps.Marker(options);
191
+ marker.native = naverMarker_1;
192
+ }
193
+
168
194
  ((_a = marker.options) === null || _a === void 0 ? void 0 : _a.event) && marker.options.event.forEach(function (handler, key) {
169
195
  if (_this.markerEvents.includes(key)) {
170
196
  naver.maps.Event.addListener(naverMarker_1, key, handler);
@@ -178,26 +204,19 @@ var NaverMintMapController = function (_super) {
178
204
  var map = marker.native.getMap();
179
205
 
180
206
  if (map) {
181
- var newOption = {
182
- map: map,
183
- position: options.position instanceof MintMap.Position ? options.position : marker.native.getPosition(),
184
- visible: options.visible === undefined || options.visible
185
- };
207
+ if (options.position && options.position instanceof MintMap.Position) {
208
+ marker.native.setPosition(options.position);
209
+ }
186
210
 
187
- if (options.anchor) {
188
- newOption.icon = tslib.__assign(tslib.__assign({}, marker.native.getIcon()), {
189
- anchor: options.anchor
190
- });
211
+ if (options.visible !== undefined) {
212
+ marker.native.setVisible(options.visible);
191
213
  }
192
214
 
193
- marker.native.setOptions({
194
- map: map,
195
- position: options.position instanceof MintMap.Position ? options.position : marker.native.getPosition(),
196
- visible: options.visible === undefined || options.visible,
197
- icon: tslib.__assign(tslib.__assign({}, marker.native.getIcon()), {
215
+ if (options.anchor) {
216
+ marker.native.setIcon(tslib.__assign(tslib.__assign({}, marker.native.getIcon()), {
198
217
  anchor: options.anchor
199
- })
200
- });
218
+ }));
219
+ }
201
220
  }
202
221
  }
203
222
  };
@@ -241,8 +260,23 @@ var NaverMintMapController = function (_super) {
241
260
  };
242
261
 
243
262
  NaverMintMapController.prototype.clearDrawable = function (drawable) {
263
+ var _a;
264
+
244
265
  if (drawable && drawable.native && drawable.native instanceof naver.maps.OverlayView) {
245
- drawable.native.setMap(null);
266
+ if (drawable.native instanceof naver.maps.Marker) {
267
+ if (this.mapProps.markerCache && this.markerPool) {
268
+ drawable.native.setVisible(false);
269
+ this.markerEvents.map(function (eName) {
270
+ drawable.native.clearListeners(eName);
271
+ });
272
+ (_a = this.markerPool) === null || _a === void 0 ? void 0 : _a.releasePoolItem(drawable.native);
273
+ } else {
274
+ drawable.native.setMap(null);
275
+ }
276
+ } else {
277
+ drawable.native.setMap(null);
278
+ }
279
+
246
280
  return true;
247
281
  }
248
282
 
@@ -377,6 +411,7 @@ var NaverMintMapController = function (_super) {
377
411
  });
378
412
  this.map = map;
379
413
  this.mapInitialized = true;
414
+ this.initMarkerPool();
380
415
  console.log("".concat(this.type, " map script initialized"), divElement);
381
416
  resolve(map);
382
417
  return [2];
@@ -389,10 +424,13 @@ var NaverMintMapController = function (_super) {
389
424
  };
390
425
 
391
426
  NaverMintMapController.prototype.destroyMap = function () {
427
+ var _a;
428
+
392
429
  console.log("".concat(this.type, " map destroyed"));
393
430
 
394
431
  try {
395
432
  this.map && this.map.destroy();
433
+ (_a = this.markerPool) === null || _a === void 0 ? void 0 : _a.destroy();
396
434
  } catch (e) {
397
435
  console.log('naver map destroy error', e);
398
436
  }
package/dist/index.es.js CHANGED
@@ -2,6 +2,7 @@ import { __awaiter, __generator, __extends, __spreadArray, __assign, __rest } fr
2
2
  import React, { createContext, useContext, useRef, useState, useEffect } from 'react';
3
3
  import classNames from 'classnames/bind';
4
4
  import styleInject from 'style-inject';
5
+ import { ObjectPool } from '@mint-ui/tools';
5
6
  import { createPortal } from 'react-dom';
6
7
 
7
8
  var css_248z$2 = ".MintMap-module_loading-point-container__znk6l {\n display: flex;\n justify-content: center;\n align-items: center;\n width: 100%;\n height: 100%;\n}\n\n.MintMap-module_ani-blink__K89JK {\n animation: MintMap-module_blink__mqfeV infinite 0.6s;\n}\n\n@keyframes MintMap-module_blink__mqfeV {\n 0% {\n opacity: 1;\n }\n 50% {\n opacity: 0.3;\n }\n 100% {\n opacity: 1;\n }\n}\n.MintMap-module_ani-fade-in__lpHuy {\n animation: MintMap-module_fade-in__jHpv1 1s;\n}\n\n@keyframes MintMap-module_fade-in__jHpv1 {\n 0% {\n opacity: 0;\n }\n 100% {\n opacity: 1;\n }\n}\n.MintMap-module_ani-fade-out__5-esw {\n animation: MintMap-module_fade-out__CIjGe 1s;\n}\n\n@keyframes MintMap-module_fade-out__CIjGe {\n 0% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n }\n}\n.MintMap-module_ani-expansion__S2vOZ {\n animation: MintMap-module_expansion__WMo5- ease 0.6s;\n}\n\n@keyframes MintMap-module_expansion__WMo5- {\n 0% {\n width: 0%;\n }\n 100% {\n width: 100%;\n }\n}";
@@ -340,6 +341,20 @@ var NaverMintMapController = function (_super) {
340
341
  return _this;
341
342
  }
342
343
 
344
+ NaverMintMapController.prototype.initMarkerPool = function () {
345
+ var _this = this;
346
+
347
+ if (!this.mapProps.markerCache) return;
348
+ this.markerPool = new ObjectPool().setFactory(function () {
349
+ return new naver.maps.Marker({
350
+ position: new Position(0, 0),
351
+ map: _this.map || undefined
352
+ });
353
+ }).setClear(function (item) {
354
+ item.setMap(null);
355
+ }).createPool(1000).setCheckLiveTimeInterval(1000);
356
+ };
357
+
343
358
  NaverMintMapController.prototype.createPolyline = function (polyline) {
344
359
  var _this = this;
345
360
 
@@ -477,8 +492,19 @@ var NaverMintMapController = function (_super) {
477
492
  content: marker.element,
478
493
  anchor: marker.options.anchor
479
494
  });
480
- var naverMarker_1 = new naver.maps.Marker(options);
481
- marker.native = naverMarker_1;
495
+ var naverMarker_1;
496
+
497
+ if (this.mapProps.markerCache && this.markerPool) {
498
+ naverMarker_1 = this.markerPool.getPoolItem();
499
+ naverMarker_1.setVisible(true);
500
+ options.icon && naverMarker_1.setIcon(options.icon);
501
+ marker.native = naverMarker_1;
502
+ this.updateMarker(marker, marker.options);
503
+ } else {
504
+ naverMarker_1 = new naver.maps.Marker(options);
505
+ marker.native = naverMarker_1;
506
+ }
507
+
482
508
  ((_a = marker.options) === null || _a === void 0 ? void 0 : _a.event) && marker.options.event.forEach(function (handler, key) {
483
509
  if (_this.markerEvents.includes(key)) {
484
510
  naver.maps.Event.addListener(naverMarker_1, key, handler);
@@ -492,26 +518,19 @@ var NaverMintMapController = function (_super) {
492
518
  var map = marker.native.getMap();
493
519
 
494
520
  if (map) {
495
- var newOption = {
496
- map: map,
497
- position: options.position instanceof Position ? options.position : marker.native.getPosition(),
498
- visible: options.visible === undefined || options.visible
499
- };
521
+ if (options.position && options.position instanceof Position) {
522
+ marker.native.setPosition(options.position);
523
+ }
500
524
 
501
- if (options.anchor) {
502
- newOption.icon = __assign(__assign({}, marker.native.getIcon()), {
503
- anchor: options.anchor
504
- });
525
+ if (options.visible !== undefined) {
526
+ marker.native.setVisible(options.visible);
505
527
  }
506
528
 
507
- marker.native.setOptions({
508
- map: map,
509
- position: options.position instanceof Position ? options.position : marker.native.getPosition(),
510
- visible: options.visible === undefined || options.visible,
511
- icon: __assign(__assign({}, marker.native.getIcon()), {
529
+ if (options.anchor) {
530
+ marker.native.setIcon(__assign(__assign({}, marker.native.getIcon()), {
512
531
  anchor: options.anchor
513
- })
514
- });
532
+ }));
533
+ }
515
534
  }
516
535
  }
517
536
  };
@@ -555,8 +574,23 @@ var NaverMintMapController = function (_super) {
555
574
  };
556
575
 
557
576
  NaverMintMapController.prototype.clearDrawable = function (drawable) {
577
+ var _a;
578
+
558
579
  if (drawable && drawable.native && drawable.native instanceof naver.maps.OverlayView) {
559
- drawable.native.setMap(null);
580
+ if (drawable.native instanceof naver.maps.Marker) {
581
+ if (this.mapProps.markerCache && this.markerPool) {
582
+ drawable.native.setVisible(false);
583
+ this.markerEvents.map(function (eName) {
584
+ drawable.native.clearListeners(eName);
585
+ });
586
+ (_a = this.markerPool) === null || _a === void 0 ? void 0 : _a.releasePoolItem(drawable.native);
587
+ } else {
588
+ drawable.native.setMap(null);
589
+ }
590
+ } else {
591
+ drawable.native.setMap(null);
592
+ }
593
+
560
594
  return true;
561
595
  }
562
596
 
@@ -691,6 +725,7 @@ var NaverMintMapController = function (_super) {
691
725
  });
692
726
  this.map = map;
693
727
  this.mapInitialized = true;
728
+ this.initMarkerPool();
694
729
  console.log("".concat(this.type, " map script initialized"), divElement);
695
730
  resolve(map);
696
731
  return [2];
@@ -703,10 +738,13 @@ var NaverMintMapController = function (_super) {
703
738
  };
704
739
 
705
740
  NaverMintMapController.prototype.destroyMap = function () {
741
+ var _a;
742
+
706
743
  console.log("".concat(this.type, " map destroyed"));
707
744
 
708
745
  try {
709
746
  this.map && this.map.destroy();
747
+ (_a = this.markerPool) === null || _a === void 0 ? void 0 : _a.destroy();
710
748
  } catch (e) {
711
749
  console.log('naver map destroy error', e);
712
750
  }
@@ -1623,9 +1661,11 @@ function MapMarkerWrapper(_a) {
1623
1661
  }
1624
1662
  }, [movingState]);
1625
1663
  useEffect(function () {
1626
- setMovingState(__assign(__assign({}, movingAnimation), {
1627
- marker: markerRef.current
1628
- }));
1664
+ if (movingAnimation) {
1665
+ setMovingState(__assign(__assign({}, movingAnimation), {
1666
+ marker: markerRef.current
1667
+ }));
1668
+ }
1629
1669
  }, [movingAnimation]);
1630
1670
  var start = useMarkerMoving(movingState)[0];
1631
1671
 
@@ -1698,9 +1738,11 @@ function MapMarkerWrapper(_a) {
1698
1738
  useEffect(function () {
1699
1739
  if (options) {
1700
1740
  if (markerRef.current) {
1741
+ console.log('update Marker');
1701
1742
  controller.updateMarker(markerRef.current, options);
1702
1743
  offsetCalibration(controller.getMapType(), divElement, options);
1703
1744
  } else {
1745
+ console.log('create Marker');
1704
1746
  markerRef.current = new Marker(options);
1705
1747
  markerRef.current.element = divElement;
1706
1748
  controller.createMarker(markerRef.current);
package/dist/index.umd.js CHANGED
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('tslib'), require('react'), require('classnames/bind'), require('style-inject'), require('react-dom')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'tslib', 'react', 'classnames/bind', 'style-inject', 'react-dom'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@mint-ui/map"] = {}, global.tslib, global.React, global.classNames, global.styleInject, global.reactDom));
5
- })(this, (function (exports, tslib, React, classNames, styleInject, reactDom) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('tslib'), require('react'), require('classnames/bind'), require('style-inject'), require('@mint-ui/tools'), require('react-dom')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'tslib', 'react', 'classnames/bind', 'style-inject', '@mint-ui/tools', 'react-dom'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@mint-ui/map"] = {}, global.tslib, global.React, global.classNames, global.styleInject, global.tools, global.reactDom));
5
+ })(this, (function (exports, tslib, React, classNames, styleInject, tools, reactDom) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -346,6 +346,20 @@
346
346
  return _this;
347
347
  }
348
348
 
349
+ NaverMintMapController.prototype.initMarkerPool = function () {
350
+ var _this = this;
351
+
352
+ if (!this.mapProps.markerCache) return;
353
+ this.markerPool = new tools.ObjectPool().setFactory(function () {
354
+ return new naver.maps.Marker({
355
+ position: new Position(0, 0),
356
+ map: _this.map || undefined
357
+ });
358
+ }).setClear(function (item) {
359
+ item.setMap(null);
360
+ }).createPool(1000).setCheckLiveTimeInterval(1000);
361
+ };
362
+
349
363
  NaverMintMapController.prototype.createPolyline = function (polyline) {
350
364
  var _this = this;
351
365
 
@@ -483,8 +497,19 @@
483
497
  content: marker.element,
484
498
  anchor: marker.options.anchor
485
499
  });
486
- var naverMarker_1 = new naver.maps.Marker(options);
487
- marker.native = naverMarker_1;
500
+ var naverMarker_1;
501
+
502
+ if (this.mapProps.markerCache && this.markerPool) {
503
+ naverMarker_1 = this.markerPool.getPoolItem();
504
+ naverMarker_1.setVisible(true);
505
+ options.icon && naverMarker_1.setIcon(options.icon);
506
+ marker.native = naverMarker_1;
507
+ this.updateMarker(marker, marker.options);
508
+ } else {
509
+ naverMarker_1 = new naver.maps.Marker(options);
510
+ marker.native = naverMarker_1;
511
+ }
512
+
488
513
  ((_a = marker.options) === null || _a === void 0 ? void 0 : _a.event) && marker.options.event.forEach(function (handler, key) {
489
514
  if (_this.markerEvents.includes(key)) {
490
515
  naver.maps.Event.addListener(naverMarker_1, key, handler);
@@ -498,26 +523,19 @@
498
523
  var map = marker.native.getMap();
499
524
 
500
525
  if (map) {
501
- var newOption = {
502
- map: map,
503
- position: options.position instanceof Position ? options.position : marker.native.getPosition(),
504
- visible: options.visible === undefined || options.visible
505
- };
526
+ if (options.position && options.position instanceof Position) {
527
+ marker.native.setPosition(options.position);
528
+ }
506
529
 
507
- if (options.anchor) {
508
- newOption.icon = tslib.__assign(tslib.__assign({}, marker.native.getIcon()), {
509
- anchor: options.anchor
510
- });
530
+ if (options.visible !== undefined) {
531
+ marker.native.setVisible(options.visible);
511
532
  }
512
533
 
513
- marker.native.setOptions({
514
- map: map,
515
- position: options.position instanceof Position ? options.position : marker.native.getPosition(),
516
- visible: options.visible === undefined || options.visible,
517
- icon: tslib.__assign(tslib.__assign({}, marker.native.getIcon()), {
534
+ if (options.anchor) {
535
+ marker.native.setIcon(tslib.__assign(tslib.__assign({}, marker.native.getIcon()), {
518
536
  anchor: options.anchor
519
- })
520
- });
537
+ }));
538
+ }
521
539
  }
522
540
  }
523
541
  };
@@ -561,8 +579,23 @@
561
579
  };
562
580
 
563
581
  NaverMintMapController.prototype.clearDrawable = function (drawable) {
582
+ var _a;
583
+
564
584
  if (drawable && drawable.native && drawable.native instanceof naver.maps.OverlayView) {
565
- drawable.native.setMap(null);
585
+ if (drawable.native instanceof naver.maps.Marker) {
586
+ if (this.mapProps.markerCache && this.markerPool) {
587
+ drawable.native.setVisible(false);
588
+ this.markerEvents.map(function (eName) {
589
+ drawable.native.clearListeners(eName);
590
+ });
591
+ (_a = this.markerPool) === null || _a === void 0 ? void 0 : _a.releasePoolItem(drawable.native);
592
+ } else {
593
+ drawable.native.setMap(null);
594
+ }
595
+ } else {
596
+ drawable.native.setMap(null);
597
+ }
598
+
566
599
  return true;
567
600
  }
568
601
 
@@ -697,6 +730,7 @@
697
730
  });
698
731
  this.map = map;
699
732
  this.mapInitialized = true;
733
+ this.initMarkerPool();
700
734
  console.log("".concat(this.type, " map script initialized"), divElement);
701
735
  resolve(map);
702
736
  return [2];
@@ -709,10 +743,13 @@
709
743
  };
710
744
 
711
745
  NaverMintMapController.prototype.destroyMap = function () {
746
+ var _a;
747
+
712
748
  console.log("".concat(this.type, " map destroyed"));
713
749
 
714
750
  try {
715
751
  this.map && this.map.destroy();
752
+ (_a = this.markerPool) === null || _a === void 0 ? void 0 : _a.destroy();
716
753
  } catch (e) {
717
754
  console.log('naver map destroy error', e);
718
755
  }
@@ -1629,9 +1666,11 @@
1629
1666
  }
1630
1667
  }, [movingState]);
1631
1668
  React.useEffect(function () {
1632
- setMovingState(tslib.__assign(tslib.__assign({}, movingAnimation), {
1633
- marker: markerRef.current
1634
- }));
1669
+ if (movingAnimation) {
1670
+ setMovingState(tslib.__assign(tslib.__assign({}, movingAnimation), {
1671
+ marker: markerRef.current
1672
+ }));
1673
+ }
1635
1674
  }, [movingAnimation]);
1636
1675
  var start = useMarkerMoving(movingState)[0];
1637
1676
 
@@ -1704,9 +1743,11 @@
1704
1743
  React.useEffect(function () {
1705
1744
  if (options) {
1706
1745
  if (markerRef.current) {
1746
+ console.log('update Marker');
1707
1747
  controller.updateMarker(markerRef.current, options);
1708
1748
  offsetCalibration(controller.getMapType(), divElement, options);
1709
1749
  } else {
1750
+ console.log('create Marker');
1710
1751
  markerRef.current = new Marker(options);
1711
1752
  markerRef.current.element = divElement;
1712
1753
  controller.createMarker(markerRef.current);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mint-ui/map",
3
- "version": "0.1.5-beta",
3
+ "version": "0.1.7-beta",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.es.js",
6
6
  "browser": "./dist/index.umd.js",
@@ -59,6 +59,7 @@
59
59
  "dependencies": {
60
60
  "@types/google.maps": "^3.50.5",
61
61
  "@types/navermaps": "^3.6.1",
62
+ "@mint-ui/tools":"1.0.3",
62
63
  "axios": "^1.2.0",
63
64
  "classnames": "^2.3.1",
64
65
  "style-inject": "^0.3.0",