@mint-ui/map 0.5.1-beta → 0.5.3-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.
@@ -53,9 +53,15 @@ function MintMap(_a) {
53
53
  var loading = React.useMemo(function () {
54
54
  return mapLoadingComponent ? mapLoadingComponent() : React__default["default"].createElement(React__default["default"].Fragment, null);
55
55
  }, [mapLoadingComponent]);
56
+ var prevController = React.useRef();
56
57
  React.useEffect(function () {
57
58
  if (mapType && mapType.length > 0) {
58
59
  setController(undefined);
60
+
61
+ if (prevController.current) {
62
+ prevController.current.destroyMap();
63
+ }
64
+
59
65
  var newController_1 = mapType === 'naver' ? new NaverMintMapController.NaverMintMapController(tslib.__assign(tslib.__assign({
60
66
  mapType: mapType
61
67
  }, props), {
@@ -69,24 +75,11 @@ function MintMap(_a) {
69
75
  }, props), {
70
76
  base: base
71
77
  })) : null;
78
+ newController_1 && (prevController.current = newController_1);
72
79
 
73
80
  if (newController_1) {
74
81
  newController_1.loadMapApi().then(function () {
75
- setController(newController_1); // fade in 로직은 일단 스킵
76
- // if(dissolveEffectWhenLoaded && loadingRef.current){
77
- // const elemStyle = loadingRef.current.style
78
- // elemStyle.background = 'white'
79
- // elemStyle.opacity = '0'
80
- // elemStyle.animationDuration = '0.1s'
81
- // loadingRef.current.addEventListener('animationend', ()=>{
82
- // setController(newController as MintMapController)
83
- // }, {
84
- // once:true
85
- // })
86
- // loadingRef.current.classList.add(cn('ani-fade-in'))
87
- // }else{
88
- // setController(newController as MintMapController)
89
- // }
82
+ setController(newController_1);
90
83
  });
91
84
  } else {
92
85
  throw new Error("Not Supported Map type ".concat(mapType));
@@ -35,6 +35,7 @@ function MintMapCore(_a) {
35
35
  mapInitialized = _d[0],
36
36
  setMapInitialized = _d[1];
37
37
 
38
+ var currMapInitialized = React.useRef(false);
38
39
  React.useEffect(function () {
39
40
  (function () {
40
41
  return tslib.__awaiter(_this, void 0, void 0, function () {
@@ -47,16 +48,21 @@ function MintMapCore(_a) {
47
48
  , 2];
48
49
  return [4
49
50
  /*yield*/
50
- , controller.initializingMap(elementRef.current) //onload callback (setTimeout 으로 맵이 초기화 될 텀을 준다. 특히 google map..)
51
- ];
51
+ , controller.initializingMap(elementRef.current)];
52
52
 
53
53
  case 1:
54
- map_1 = _a.sent(); //onload callback (setTimeout 으로 맵이 초기화 될 텀을 준다. 특히 google map..)
54
+ map_1 = _a.sent();
55
+
56
+ if (!currMapInitialized.current) {
57
+ currMapInitialized.current = true; //onload callback (setTimeout 으로 맵이 초기화 될 텀을 준다. 특히 google map..)
58
+
59
+ setTimeout(function () {
60
+ // console.log('setMapInitialized true');
61
+ setMapInitialized(true);
62
+ onLoad && onLoad(map_1, controller);
63
+ }, 100);
64
+ }
55
65
 
56
- setTimeout(function () {
57
- setMapInitialized(true);
58
- onLoad && onLoad(map_1, controller);
59
- }, 100);
60
66
  _a.label = 2;
61
67
 
62
68
  case 2:
@@ -67,10 +73,6 @@ function MintMapCore(_a) {
67
73
  });
68
74
  });
69
75
  })();
70
-
71
- return function () {
72
- controller && controller.destroyMap();
73
- };
74
76
  }, [controller, elementRef]); //줌레벨
75
77
 
76
78
  React.useEffect(function () {
@@ -17,7 +17,17 @@ export interface MapMarkerMoving {
17
17
  export interface MapMarkerWrapperProps extends MarkerOptions {
18
18
  topOnClick?: boolean;
19
19
  topOnHover?: boolean;
20
+ /**
21
+ * 메모리 누수의 위험성이 존재하여 삭제될 예정
22
+ * animation 은 marker wrapper 의 children 레벨에서 구현하는것을 기본으로 한다.
23
+ * @deprecated
24
+ */
20
25
  startAnimationClassName?: string;
26
+ /**
27
+ * 메모리 누수의 위험성이 존재하여 삭제될 예정
28
+ * animation 은 marker wrapper 의 children 레벨에서 구현하는것을 기본으로 한다.
29
+ * @deprecated
30
+ */
21
31
  endAnimationClassName?: string;
22
32
  movingAnimation?: MapMarkerMoving;
23
33
  disablePointerEvent?: boolean;
@@ -27,9 +27,9 @@ var offsetCalibration = function (mapType, divElement, options) {
27
27
 
28
28
 
29
29
  function MapMarkerWrapper(_a) {
30
- var startAnimationClassName = _a.startAnimationClassName,
31
- endAnimationClassName = _a.endAnimationClassName,
32
- _b = _a.topOnClick,
30
+ _a.startAnimationClassName;
31
+ _a.endAnimationClassName;
32
+ var _b = _a.topOnClick,
33
33
  topOnClick = _b === void 0 ? false : _b,
34
34
  _c = _a.topOnHover,
35
35
  topOnHover = _c === void 0 ? false : _c,
@@ -43,9 +43,7 @@ function MapMarkerWrapper(_a) {
43
43
  var controller = MintMapProvider.useMintMapController(); //element
44
44
 
45
45
  var divRef = React.useRef(document.createElement('div'));
46
- var divElement = divRef.current; //element clone for animation
47
-
48
- var divCloneRef = React.useRef(); //marker
46
+ var divElement = divRef.current; //marker
49
47
 
50
48
  var markerRef = React.useRef(); //moving animation
51
49
 
@@ -120,32 +118,12 @@ function MapMarkerWrapper(_a) {
120
118
  divElement.addEventListener('click', onClickHandler);
121
119
  divElement.addEventListener('mouseover', onMouseOverHandler);
122
120
  return function () {
123
- //** kakao 는 viewport 안에 있는 마커만 렌더링하므로,
124
- //마커 해제가 되더라도 애니메이션 이벤트가 일어나지 않아서 해지된 마커가 잠시 보이는 현상이 있음
125
- //그래서 kakao 일때는 endAnimationClassName 영향을 받지 않도록 처리함
126
- if (divCloneRef.current && endAnimationClassName && controller.getMapType() !== 'kakao') {
127
- divCloneRef.current.classList.add(endAnimationClassName);
128
-
129
- var aniListener_1 = function () {
130
- //console.log('animationend!!!', divCloneRef.current);
131
- divCloneRef.current && divCloneRef.current.removeEventListener('animationend', aniListener_1);
132
-
133
- if (markerRef.current) {
134
- controller.clearDrawable(markerRef.current); // console.log('drawable cleared')
135
- }
136
-
137
- divCloneRef.current = undefined;
138
- };
121
+ divElement.removeEventListener('click', onClickHandler);
122
+ divElement.removeEventListener('mouseover', onMouseOverHandler);
139
123
 
140
- divCloneRef.current.addEventListener('animationend', aniListener_1);
141
- divElement.append(divCloneRef.current);
142
- } else {
143
- divElement.removeEventListener('click', onClickHandler);
144
- divElement.removeEventListener('mouseover', onMouseOverHandler);
145
-
146
- if (markerRef.current) {
147
- controller.clearDrawable(markerRef.current); // console.log('drawable cleared')
148
- }
124
+ if (markerRef.current) {
125
+ controller.clearDrawable(markerRef.current);
126
+ markerRef.current = undefined; // console.log('drawable cleared')
149
127
  }
150
128
  };
151
129
  }, []); //create / update object
@@ -190,31 +168,6 @@ function MapMarkerWrapper(_a) {
190
168
  setMovingState(tslib.__assign(tslib.__assign({}, movingAnimation), {
191
169
  marker: markerRef.current
192
170
  }));
193
- } //start animation
194
-
195
-
196
- if (startAnimationClassName) {
197
- divElement.style.visibility = 'hidden';
198
- setTimeout(function () {
199
- var _a, _b;
200
-
201
- divCloneRef.current = divElement.firstElementChild;
202
- divElement.style.visibility = 'visible';
203
- (_a = divElement.firstElementChild) === null || _a === void 0 ? void 0 : _a.classList.add(startAnimationClassName);
204
-
205
- var aniListener = function () {
206
- var _a, _b;
207
-
208
- (_a = divElement.firstElementChild) === null || _a === void 0 ? void 0 : _a.classList.remove(startAnimationClassName);
209
- (_b = divElement.firstElementChild) === null || _b === void 0 ? void 0 : _b.removeEventListener('animationend', aniListener);
210
- };
211
-
212
- (_b = divElement.firstElementChild) === null || _b === void 0 ? void 0 : _b.addEventListener('animationend', aniListener);
213
- });
214
- } else {
215
- setTimeout(function () {
216
- divCloneRef.current = divElement.firstElementChild;
217
- });
218
171
  }
219
172
  }
220
173
  }
@@ -31,6 +31,7 @@ function MapPolygonWrapper(_a) {
31
31
  if (polygonRef.current) {
32
32
  // console.log('polygon cleared')
33
33
  controller.clearDrawable(polygonRef.current);
34
+ polygonRef.current = undefined;
34
35
  }
35
36
  };
36
37
  }, []); //create/update object
@@ -29,7 +29,8 @@ function MapPolylineWrapper(_a) {
29
29
  React.useEffect(function () {
30
30
  return function () {
31
31
  if (polylineRef.current) {
32
- controller.clearDrawable(polylineRef.current); // console.log('polyline cleared')
32
+ controller.clearDrawable(polylineRef.current);
33
+ polylineRef.current = undefined; // console.log('polyline cleared')
33
34
  }
34
35
  };
35
36
  }, []); //create/update object
@@ -605,7 +605,6 @@ function (_super) {
605
605
  };
606
606
  callback(param);
607
607
  } else if (eventName in _this.mapUIEvent) {
608
- if (eventName.startsWith('DRAG')) console.log(eventName, e);
609
608
  var position = null;
610
609
 
611
610
  if (e) {
@@ -621,7 +620,8 @@ function (_super) {
621
620
  vendorEventName: googleEventName,
622
621
  param: {
623
622
  position: position,
624
- offset: position === null || position === void 0 ? void 0 : position.offset
623
+ offset: position === null || position === void 0 ? void 0 : position.offset,
624
+ pointerEvent: e.domEvent
625
625
  }
626
626
  };
627
627
  callback(param);
@@ -31,7 +31,9 @@ function (_super) {
31
31
  _this.dragged = false;
32
32
  _this.eventMap = new Map(); //kakao only 이벤트이름 재정의 zoom_start
33
33
 
34
- _this.mapEvent.ZOOMSTART = 'zoom_start';
34
+ _this.mapEvent.ZOOMSTART = 'zoom_start'; //contextmenu 는 지원하지 않지만 호환성을 위해 rightclick 으로 대체
35
+
36
+ _this.mapUIEvent.CONTEXTMENU = 'rightclick';
35
37
  Object.freeze(_this.mapEvent);
36
38
  Object.freeze(_this.mapUIEvent);
37
39
  return _this; // console.log(`${this.type} controller loadded`);
@@ -470,6 +472,7 @@ function (_super) {
470
472
  minZoom = 14;
471
473
  }
472
474
 
475
+ divElement.innerHTML = '';
473
476
  map = new kakao.maps.Map(divElement, options);
474
477
  map.setMaxLevel(minZoom);
475
478
  map.setMinLevel(maxZoom);
@@ -557,6 +560,7 @@ function (_super) {
557
560
  var _a;
558
561
 
559
562
  try {
563
+ this.removeAllEventListener();
560
564
  (_a = this.markerPool) === null || _a === void 0 ? void 0 : _a.destroy();
561
565
  } catch (e) {
562
566
  console.log('kakao map destroy error', e);
@@ -29,7 +29,9 @@ function (_super) {
29
29
  _this.markerEvents = ['click', 'mouseover', 'mouseout'];
30
30
  _this.dragStartPoint = [0, 0];
31
31
  _this.dragged = false;
32
- _this.eventMap = new Map();
32
+ _this.eventMap = new Map(); //contextmenu 는 지원하지 않지만 호환성을 위해 rightclick 으로 대체
33
+
34
+ _this.mapUIEvent.CONTEXTMENU = 'rightclick';
33
35
  Object.freeze(_this.mapEvent);
34
36
  Object.freeze(_this.mapUIEvent);
35
37
  return _this; // console.log(`${this.type} controller loadded`);
@@ -505,6 +507,7 @@ function (_super) {
505
507
 
506
508
  options.minZoom = minZoom;
507
509
  options.maxZoom = maxZoom;
510
+ divElement.innerHTML = '';
508
511
  map = new naver.maps.Map(divElement, options);
509
512
  this.map = map; //@ts-ignore
510
513
 
@@ -671,7 +674,8 @@ function (_super) {
671
674
  vendorEventName: naverEventName,
672
675
  param: {
673
676
  position: position,
674
- offset: position.offset
677
+ offset: position.offset,
678
+ pointerEvent: e.pointerEvent
675
679
  }
676
680
  };
677
681
  callback(param);
@@ -19,6 +19,8 @@ export declare class MapUIEvent {
19
19
  DRAG: string;
20
20
  DRAGSTART: string;
21
21
  DRAGEND: string;
22
+ RIGHTCLICK: string;
23
+ CONTEXTMENU: string;
22
24
  get(eventName: MapEventName): string | undefined;
23
25
  }
24
26
  export declare type MapEventName = keyof MapEvent | keyof MapUIEvent;
@@ -30,6 +32,7 @@ export declare type MapEventParam = {
30
32
  export declare type MapUIEventParam = {
31
33
  offset: Offset;
32
34
  position: Position;
35
+ pointerEvent?: PointerEvent;
33
36
  };
34
37
  export declare type EventParamType = MapEventParam & MapUIEventParam;
35
38
  export interface EventParam<T> {
@@ -40,6 +40,8 @@ function () {
40
40
  this.DRAG = 'drag';
41
41
  this.DRAGSTART = 'dragstart';
42
42
  this.DRAGEND = 'dragend';
43
+ this.RIGHTCLICK = 'rightclick';
44
+ this.CONTEXTMENU = 'contextmenu';
43
45
  }
44
46
 
45
47
  MapUIEvent.prototype.get = function (eventName) {
package/dist/index.es.js CHANGED
@@ -626,6 +626,7 @@ function MintMapCore(_a) {
626
626
  mapInitialized = _d[0],
627
627
  setMapInitialized = _d[1];
628
628
 
629
+ var currMapInitialized = useRef(false);
629
630
  useEffect(function () {
630
631
  (function () {
631
632
  return __awaiter(_this, void 0, void 0, function () {
@@ -638,16 +639,21 @@ function MintMapCore(_a) {
638
639
  , 2];
639
640
  return [4
640
641
  /*yield*/
641
- , controller.initializingMap(elementRef.current) //onload callback (setTimeout 으로 맵이 초기화 될 텀을 준다. 특히 google map..)
642
- ];
642
+ , controller.initializingMap(elementRef.current)];
643
643
 
644
644
  case 1:
645
- map_1 = _a.sent(); //onload callback (setTimeout 으로 맵이 초기화 될 텀을 준다. 특히 google map..)
645
+ map_1 = _a.sent();
646
+
647
+ if (!currMapInitialized.current) {
648
+ currMapInitialized.current = true; //onload callback (setTimeout 으로 맵이 초기화 될 텀을 준다. 특히 google map..)
649
+
650
+ setTimeout(function () {
651
+ // console.log('setMapInitialized true');
652
+ setMapInitialized(true);
653
+ onLoad && onLoad(map_1, controller);
654
+ }, 100);
655
+ }
646
656
 
647
- setTimeout(function () {
648
- setMapInitialized(true);
649
- onLoad && onLoad(map_1, controller);
650
- }, 100);
651
657
  _a.label = 2;
652
658
 
653
659
  case 2:
@@ -658,10 +664,6 @@ function MintMapCore(_a) {
658
664
  });
659
665
  });
660
666
  })();
661
-
662
- return function () {
663
- controller && controller.destroyMap();
664
- };
665
667
  }, [controller, elementRef]); //줌레벨
666
668
 
667
669
  useEffect(function () {
@@ -1121,6 +1123,8 @@ function () {
1121
1123
  this.DRAG = 'drag';
1122
1124
  this.DRAGSTART = 'dragstart';
1123
1125
  this.DRAGEND = 'dragend';
1126
+ this.RIGHTCLICK = 'rightclick';
1127
+ this.CONTEXTMENU = 'contextmenu';
1124
1128
  }
1125
1129
 
1126
1130
  MapUIEvent.prototype.get = function (eventName) {
@@ -1154,7 +1158,9 @@ function (_super) {
1154
1158
  _this.markerEvents = ['click', 'mouseover', 'mouseout'];
1155
1159
  _this.dragStartPoint = [0, 0];
1156
1160
  _this.dragged = false;
1157
- _this.eventMap = new Map();
1161
+ _this.eventMap = new Map(); //contextmenu 는 지원하지 않지만 호환성을 위해 rightclick 으로 대체
1162
+
1163
+ _this.mapUIEvent.CONTEXTMENU = 'rightclick';
1158
1164
  Object.freeze(_this.mapEvent);
1159
1165
  Object.freeze(_this.mapUIEvent);
1160
1166
  return _this; // console.log(`${this.type} controller loadded`);
@@ -1630,6 +1636,7 @@ function (_super) {
1630
1636
 
1631
1637
  options.minZoom = minZoom;
1632
1638
  options.maxZoom = maxZoom;
1639
+ divElement.innerHTML = '';
1633
1640
  map = new naver.maps.Map(divElement, options);
1634
1641
  this.map = map; //@ts-ignore
1635
1642
 
@@ -1796,7 +1803,8 @@ function (_super) {
1796
1803
  vendorEventName: naverEventName,
1797
1804
  param: {
1798
1805
  position: position,
1799
- offset: position.offset
1806
+ offset: position.offset,
1807
+ pointerEvent: e.pointerEvent
1800
1808
  }
1801
1809
  };
1802
1810
  callback(param);
@@ -2446,7 +2454,6 @@ function (_super) {
2446
2454
  };
2447
2455
  callback(param);
2448
2456
  } else if (eventName in _this.mapUIEvent) {
2449
- if (eventName.startsWith('DRAG')) console.log(eventName, e);
2450
2457
  var position = null;
2451
2458
 
2452
2459
  if (e) {
@@ -2462,7 +2469,8 @@ function (_super) {
2462
2469
  vendorEventName: googleEventName,
2463
2470
  param: {
2464
2471
  position: position,
2465
- offset: position === null || position === void 0 ? void 0 : position.offset
2472
+ offset: position === null || position === void 0 ? void 0 : position.offset,
2473
+ pointerEvent: e.domEvent
2466
2474
  }
2467
2475
  };
2468
2476
  callback(param);
@@ -2541,7 +2549,9 @@ function (_super) {
2541
2549
  _this.dragged = false;
2542
2550
  _this.eventMap = new Map(); //kakao only 이벤트이름 재정의 zoom_start
2543
2551
 
2544
- _this.mapEvent.ZOOMSTART = 'zoom_start';
2552
+ _this.mapEvent.ZOOMSTART = 'zoom_start'; //contextmenu 는 지원하지 않지만 호환성을 위해 rightclick 으로 대체
2553
+
2554
+ _this.mapUIEvent.CONTEXTMENU = 'rightclick';
2545
2555
  Object.freeze(_this.mapEvent);
2546
2556
  Object.freeze(_this.mapUIEvent);
2547
2557
  return _this; // console.log(`${this.type} controller loadded`);
@@ -2980,6 +2990,7 @@ function (_super) {
2980
2990
  minZoom = 14;
2981
2991
  }
2982
2992
 
2993
+ divElement.innerHTML = '';
2983
2994
  map = new kakao.maps.Map(divElement, options);
2984
2995
  map.setMaxLevel(minZoom);
2985
2996
  map.setMinLevel(maxZoom);
@@ -3067,6 +3078,7 @@ function (_super) {
3067
3078
  var _a;
3068
3079
 
3069
3080
  try {
3081
+ this.removeAllEventListener();
3070
3082
  (_a = this.markerPool) === null || _a === void 0 ? void 0 : _a.destroy();
3071
3083
  } catch (e) {
3072
3084
  console.log('kakao map destroy error', e);
@@ -3264,9 +3276,15 @@ function MintMap(_a) {
3264
3276
  var loading = useMemo(function () {
3265
3277
  return mapLoadingComponent ? mapLoadingComponent() : React.createElement(React.Fragment, null);
3266
3278
  }, [mapLoadingComponent]);
3279
+ var prevController = useRef();
3267
3280
  useEffect(function () {
3268
3281
  if (mapType && mapType.length > 0) {
3269
3282
  setController(undefined);
3283
+
3284
+ if (prevController.current) {
3285
+ prevController.current.destroyMap();
3286
+ }
3287
+
3270
3288
  var newController_1 = mapType === 'naver' ? new NaverMintMapController(__assign(__assign({
3271
3289
  mapType: mapType
3272
3290
  }, props), {
@@ -3280,24 +3298,11 @@ function MintMap(_a) {
3280
3298
  }, props), {
3281
3299
  base: base
3282
3300
  })) : null;
3301
+ newController_1 && (prevController.current = newController_1);
3283
3302
 
3284
3303
  if (newController_1) {
3285
3304
  newController_1.loadMapApi().then(function () {
3286
- setController(newController_1); // fade in 로직은 일단 스킵
3287
- // if(dissolveEffectWhenLoaded && loadingRef.current){
3288
- // const elemStyle = loadingRef.current.style
3289
- // elemStyle.background = 'white'
3290
- // elemStyle.opacity = '0'
3291
- // elemStyle.animationDuration = '0.1s'
3292
- // loadingRef.current.addEventListener('animationend', ()=>{
3293
- // setController(newController as MintMapController)
3294
- // }, {
3295
- // once:true
3296
- // })
3297
- // loadingRef.current.classList.add(cn('ani-fade-in'))
3298
- // }else{
3299
- // setController(newController as MintMapController)
3300
- // }
3305
+ setController(newController_1);
3301
3306
  });
3302
3307
  } else {
3303
3308
  throw new Error("Not Supported Map type ".concat(mapType));
@@ -3899,9 +3904,9 @@ var offsetCalibration = function (mapType, divElement, options) {
3899
3904
 
3900
3905
 
3901
3906
  function MapMarkerWrapper(_a) {
3902
- var startAnimationClassName = _a.startAnimationClassName,
3903
- endAnimationClassName = _a.endAnimationClassName,
3904
- _b = _a.topOnClick,
3907
+ _a.startAnimationClassName;
3908
+ _a.endAnimationClassName;
3909
+ var _b = _a.topOnClick,
3905
3910
  topOnClick = _b === void 0 ? false : _b,
3906
3911
  _c = _a.topOnHover,
3907
3912
  topOnHover = _c === void 0 ? false : _c,
@@ -3915,9 +3920,7 @@ function MapMarkerWrapper(_a) {
3915
3920
  var controller = useMintMapController(); //element
3916
3921
 
3917
3922
  var divRef = useRef(document.createElement('div'));
3918
- var divElement = divRef.current; //element clone for animation
3919
-
3920
- var divCloneRef = useRef(); //marker
3923
+ var divElement = divRef.current; //marker
3921
3924
 
3922
3925
  var markerRef = useRef(); //moving animation
3923
3926
 
@@ -3992,32 +3995,12 @@ function MapMarkerWrapper(_a) {
3992
3995
  divElement.addEventListener('click', onClickHandler);
3993
3996
  divElement.addEventListener('mouseover', onMouseOverHandler);
3994
3997
  return function () {
3995
- //** kakao 는 viewport 안에 있는 마커만 렌더링하므로,
3996
- //마커 해제가 되더라도 애니메이션 이벤트가 일어나지 않아서 해지된 마커가 잠시 보이는 현상이 있음
3997
- //그래서 kakao 일때는 endAnimationClassName 영향을 받지 않도록 처리함
3998
- if (divCloneRef.current && endAnimationClassName && controller.getMapType() !== 'kakao') {
3999
- divCloneRef.current.classList.add(endAnimationClassName);
4000
-
4001
- var aniListener_1 = function () {
4002
- //console.log('animationend!!!', divCloneRef.current);
4003
- divCloneRef.current && divCloneRef.current.removeEventListener('animationend', aniListener_1);
4004
-
4005
- if (markerRef.current) {
4006
- controller.clearDrawable(markerRef.current); // console.log('drawable cleared')
4007
- }
3998
+ divElement.removeEventListener('click', onClickHandler);
3999
+ divElement.removeEventListener('mouseover', onMouseOverHandler);
4008
4000
 
4009
- divCloneRef.current = undefined;
4010
- };
4011
-
4012
- divCloneRef.current.addEventListener('animationend', aniListener_1);
4013
- divElement.append(divCloneRef.current);
4014
- } else {
4015
- divElement.removeEventListener('click', onClickHandler);
4016
- divElement.removeEventListener('mouseover', onMouseOverHandler);
4017
-
4018
- if (markerRef.current) {
4019
- controller.clearDrawable(markerRef.current); // console.log('drawable cleared')
4020
- }
4001
+ if (markerRef.current) {
4002
+ controller.clearDrawable(markerRef.current);
4003
+ markerRef.current = undefined; // console.log('drawable cleared')
4021
4004
  }
4022
4005
  };
4023
4006
  }, []); //create / update object
@@ -4062,31 +4045,6 @@ function MapMarkerWrapper(_a) {
4062
4045
  setMovingState(__assign(__assign({}, movingAnimation), {
4063
4046
  marker: markerRef.current
4064
4047
  }));
4065
- } //start animation
4066
-
4067
-
4068
- if (startAnimationClassName) {
4069
- divElement.style.visibility = 'hidden';
4070
- setTimeout(function () {
4071
- var _a, _b;
4072
-
4073
- divCloneRef.current = divElement.firstElementChild;
4074
- divElement.style.visibility = 'visible';
4075
- (_a = divElement.firstElementChild) === null || _a === void 0 ? void 0 : _a.classList.add(startAnimationClassName);
4076
-
4077
- var aniListener = function () {
4078
- var _a, _b;
4079
-
4080
- (_a = divElement.firstElementChild) === null || _a === void 0 ? void 0 : _a.classList.remove(startAnimationClassName);
4081
- (_b = divElement.firstElementChild) === null || _b === void 0 ? void 0 : _b.removeEventListener('animationend', aniListener);
4082
- };
4083
-
4084
- (_b = divElement.firstElementChild) === null || _b === void 0 ? void 0 : _b.addEventListener('animationend', aniListener);
4085
- });
4086
- } else {
4087
- setTimeout(function () {
4088
- divCloneRef.current = divElement.firstElementChild;
4089
- });
4090
4048
  }
4091
4049
  }
4092
4050
  }
@@ -4534,6 +4492,7 @@ function MapPolygonWrapper(_a) {
4534
4492
  if (polygonRef.current) {
4535
4493
  // console.log('polygon cleared')
4536
4494
  controller.clearDrawable(polygonRef.current);
4495
+ polygonRef.current = undefined;
4537
4496
  }
4538
4497
  };
4539
4498
  }, []); //create/update object
@@ -5054,7 +5013,8 @@ function MapPolylineWrapper(_a) {
5054
5013
  useEffect(function () {
5055
5014
  return function () {
5056
5015
  if (polylineRef.current) {
5057
- controller.clearDrawable(polylineRef.current); // console.log('polyline cleared')
5016
+ controller.clearDrawable(polylineRef.current);
5017
+ polylineRef.current = undefined; // console.log('polyline cleared')
5058
5018
  }
5059
5019
  };
5060
5020
  }, []); //create/update object
package/dist/index.umd.js CHANGED
@@ -630,6 +630,7 @@
630
630
  mapInitialized = _d[0],
631
631
  setMapInitialized = _d[1];
632
632
 
633
+ var currMapInitialized = React.useRef(false);
633
634
  React.useEffect(function () {
634
635
  (function () {
635
636
  return tslib.__awaiter(_this, void 0, void 0, function () {
@@ -642,16 +643,21 @@
642
643
  , 2];
643
644
  return [4
644
645
  /*yield*/
645
- , controller.initializingMap(elementRef.current) //onload callback (setTimeout 으로 맵이 초기화 될 텀을 준다. 특히 google map..)
646
- ];
646
+ , controller.initializingMap(elementRef.current)];
647
647
 
648
648
  case 1:
649
- map_1 = _a.sent(); //onload callback (setTimeout 으로 맵이 초기화 될 텀을 준다. 특히 google map..)
649
+ map_1 = _a.sent();
650
+
651
+ if (!currMapInitialized.current) {
652
+ currMapInitialized.current = true; //onload callback (setTimeout 으로 맵이 초기화 될 텀을 준다. 특히 google map..)
653
+
654
+ setTimeout(function () {
655
+ // console.log('setMapInitialized true');
656
+ setMapInitialized(true);
657
+ onLoad && onLoad(map_1, controller);
658
+ }, 100);
659
+ }
650
660
 
651
- setTimeout(function () {
652
- setMapInitialized(true);
653
- onLoad && onLoad(map_1, controller);
654
- }, 100);
655
661
  _a.label = 2;
656
662
 
657
663
  case 2:
@@ -662,10 +668,6 @@
662
668
  });
663
669
  });
664
670
  })();
665
-
666
- return function () {
667
- controller && controller.destroyMap();
668
- };
669
671
  }, [controller, elementRef]); //줌레벨
670
672
 
671
673
  React.useEffect(function () {
@@ -1125,6 +1127,8 @@
1125
1127
  this.DRAG = 'drag';
1126
1128
  this.DRAGSTART = 'dragstart';
1127
1129
  this.DRAGEND = 'dragend';
1130
+ this.RIGHTCLICK = 'rightclick';
1131
+ this.CONTEXTMENU = 'contextmenu';
1128
1132
  }
1129
1133
 
1130
1134
  MapUIEvent.prototype.get = function (eventName) {
@@ -1158,7 +1162,9 @@
1158
1162
  _this.markerEvents = ['click', 'mouseover', 'mouseout'];
1159
1163
  _this.dragStartPoint = [0, 0];
1160
1164
  _this.dragged = false;
1161
- _this.eventMap = new Map();
1165
+ _this.eventMap = new Map(); //contextmenu 는 지원하지 않지만 호환성을 위해 rightclick 으로 대체
1166
+
1167
+ _this.mapUIEvent.CONTEXTMENU = 'rightclick';
1162
1168
  Object.freeze(_this.mapEvent);
1163
1169
  Object.freeze(_this.mapUIEvent);
1164
1170
  return _this; // console.log(`${this.type} controller loadded`);
@@ -1634,6 +1640,7 @@
1634
1640
 
1635
1641
  options.minZoom = minZoom;
1636
1642
  options.maxZoom = maxZoom;
1643
+ divElement.innerHTML = '';
1637
1644
  map = new naver.maps.Map(divElement, options);
1638
1645
  this.map = map; //@ts-ignore
1639
1646
 
@@ -1800,7 +1807,8 @@
1800
1807
  vendorEventName: naverEventName,
1801
1808
  param: {
1802
1809
  position: position,
1803
- offset: position.offset
1810
+ offset: position.offset,
1811
+ pointerEvent: e.pointerEvent
1804
1812
  }
1805
1813
  };
1806
1814
  callback(param);
@@ -2450,7 +2458,6 @@
2450
2458
  };
2451
2459
  callback(param);
2452
2460
  } else if (eventName in _this.mapUIEvent) {
2453
- if (eventName.startsWith('DRAG')) console.log(eventName, e);
2454
2461
  var position = null;
2455
2462
 
2456
2463
  if (e) {
@@ -2466,7 +2473,8 @@
2466
2473
  vendorEventName: googleEventName,
2467
2474
  param: {
2468
2475
  position: position,
2469
- offset: position === null || position === void 0 ? void 0 : position.offset
2476
+ offset: position === null || position === void 0 ? void 0 : position.offset,
2477
+ pointerEvent: e.domEvent
2470
2478
  }
2471
2479
  };
2472
2480
  callback(param);
@@ -2545,7 +2553,9 @@
2545
2553
  _this.dragged = false;
2546
2554
  _this.eventMap = new Map(); //kakao only 이벤트이름 재정의 zoom_start
2547
2555
 
2548
- _this.mapEvent.ZOOMSTART = 'zoom_start';
2556
+ _this.mapEvent.ZOOMSTART = 'zoom_start'; //contextmenu 는 지원하지 않지만 호환성을 위해 rightclick 으로 대체
2557
+
2558
+ _this.mapUIEvent.CONTEXTMENU = 'rightclick';
2549
2559
  Object.freeze(_this.mapEvent);
2550
2560
  Object.freeze(_this.mapUIEvent);
2551
2561
  return _this; // console.log(`${this.type} controller loadded`);
@@ -2984,6 +2994,7 @@
2984
2994
  minZoom = 14;
2985
2995
  }
2986
2996
 
2997
+ divElement.innerHTML = '';
2987
2998
  map = new kakao.maps.Map(divElement, options);
2988
2999
  map.setMaxLevel(minZoom);
2989
3000
  map.setMinLevel(maxZoom);
@@ -3071,6 +3082,7 @@
3071
3082
  var _a;
3072
3083
 
3073
3084
  try {
3085
+ this.removeAllEventListener();
3074
3086
  (_a = this.markerPool) === null || _a === void 0 ? void 0 : _a.destroy();
3075
3087
  } catch (e) {
3076
3088
  console.log('kakao map destroy error', e);
@@ -3268,9 +3280,15 @@
3268
3280
  var loading = React.useMemo(function () {
3269
3281
  return mapLoadingComponent ? mapLoadingComponent() : React__default["default"].createElement(React__default["default"].Fragment, null);
3270
3282
  }, [mapLoadingComponent]);
3283
+ var prevController = React.useRef();
3271
3284
  React.useEffect(function () {
3272
3285
  if (mapType && mapType.length > 0) {
3273
3286
  setController(undefined);
3287
+
3288
+ if (prevController.current) {
3289
+ prevController.current.destroyMap();
3290
+ }
3291
+
3274
3292
  var newController_1 = mapType === 'naver' ? new NaverMintMapController(tslib.__assign(tslib.__assign({
3275
3293
  mapType: mapType
3276
3294
  }, props), {
@@ -3284,24 +3302,11 @@
3284
3302
  }, props), {
3285
3303
  base: base
3286
3304
  })) : null;
3305
+ newController_1 && (prevController.current = newController_1);
3287
3306
 
3288
3307
  if (newController_1) {
3289
3308
  newController_1.loadMapApi().then(function () {
3290
- setController(newController_1); // fade in 로직은 일단 스킵
3291
- // if(dissolveEffectWhenLoaded && loadingRef.current){
3292
- // const elemStyle = loadingRef.current.style
3293
- // elemStyle.background = 'white'
3294
- // elemStyle.opacity = '0'
3295
- // elemStyle.animationDuration = '0.1s'
3296
- // loadingRef.current.addEventListener('animationend', ()=>{
3297
- // setController(newController as MintMapController)
3298
- // }, {
3299
- // once:true
3300
- // })
3301
- // loadingRef.current.classList.add(cn('ani-fade-in'))
3302
- // }else{
3303
- // setController(newController as MintMapController)
3304
- // }
3309
+ setController(newController_1);
3305
3310
  });
3306
3311
  } else {
3307
3312
  throw new Error("Not Supported Map type ".concat(mapType));
@@ -3903,9 +3908,9 @@
3903
3908
 
3904
3909
 
3905
3910
  function MapMarkerWrapper(_a) {
3906
- var startAnimationClassName = _a.startAnimationClassName,
3907
- endAnimationClassName = _a.endAnimationClassName,
3908
- _b = _a.topOnClick,
3911
+ _a.startAnimationClassName;
3912
+ _a.endAnimationClassName;
3913
+ var _b = _a.topOnClick,
3909
3914
  topOnClick = _b === void 0 ? false : _b,
3910
3915
  _c = _a.topOnHover,
3911
3916
  topOnHover = _c === void 0 ? false : _c,
@@ -3919,9 +3924,7 @@
3919
3924
  var controller = useMintMapController(); //element
3920
3925
 
3921
3926
  var divRef = React.useRef(document.createElement('div'));
3922
- var divElement = divRef.current; //element clone for animation
3923
-
3924
- var divCloneRef = React.useRef(); //marker
3927
+ var divElement = divRef.current; //marker
3925
3928
 
3926
3929
  var markerRef = React.useRef(); //moving animation
3927
3930
 
@@ -3996,32 +3999,12 @@
3996
3999
  divElement.addEventListener('click', onClickHandler);
3997
4000
  divElement.addEventListener('mouseover', onMouseOverHandler);
3998
4001
  return function () {
3999
- //** kakao 는 viewport 안에 있는 마커만 렌더링하므로,
4000
- //마커 해제가 되더라도 애니메이션 이벤트가 일어나지 않아서 해지된 마커가 잠시 보이는 현상이 있음
4001
- //그래서 kakao 일때는 endAnimationClassName 영향을 받지 않도록 처리함
4002
- if (divCloneRef.current && endAnimationClassName && controller.getMapType() !== 'kakao') {
4003
- divCloneRef.current.classList.add(endAnimationClassName);
4004
-
4005
- var aniListener_1 = function () {
4006
- //console.log('animationend!!!', divCloneRef.current);
4007
- divCloneRef.current && divCloneRef.current.removeEventListener('animationend', aniListener_1);
4008
-
4009
- if (markerRef.current) {
4010
- controller.clearDrawable(markerRef.current); // console.log('drawable cleared')
4011
- }
4002
+ divElement.removeEventListener('click', onClickHandler);
4003
+ divElement.removeEventListener('mouseover', onMouseOverHandler);
4012
4004
 
4013
- divCloneRef.current = undefined;
4014
- };
4015
-
4016
- divCloneRef.current.addEventListener('animationend', aniListener_1);
4017
- divElement.append(divCloneRef.current);
4018
- } else {
4019
- divElement.removeEventListener('click', onClickHandler);
4020
- divElement.removeEventListener('mouseover', onMouseOverHandler);
4021
-
4022
- if (markerRef.current) {
4023
- controller.clearDrawable(markerRef.current); // console.log('drawable cleared')
4024
- }
4005
+ if (markerRef.current) {
4006
+ controller.clearDrawable(markerRef.current);
4007
+ markerRef.current = undefined; // console.log('drawable cleared')
4025
4008
  }
4026
4009
  };
4027
4010
  }, []); //create / update object
@@ -4066,31 +4049,6 @@
4066
4049
  setMovingState(tslib.__assign(tslib.__assign({}, movingAnimation), {
4067
4050
  marker: markerRef.current
4068
4051
  }));
4069
- } //start animation
4070
-
4071
-
4072
- if (startAnimationClassName) {
4073
- divElement.style.visibility = 'hidden';
4074
- setTimeout(function () {
4075
- var _a, _b;
4076
-
4077
- divCloneRef.current = divElement.firstElementChild;
4078
- divElement.style.visibility = 'visible';
4079
- (_a = divElement.firstElementChild) === null || _a === void 0 ? void 0 : _a.classList.add(startAnimationClassName);
4080
-
4081
- var aniListener = function () {
4082
- var _a, _b;
4083
-
4084
- (_a = divElement.firstElementChild) === null || _a === void 0 ? void 0 : _a.classList.remove(startAnimationClassName);
4085
- (_b = divElement.firstElementChild) === null || _b === void 0 ? void 0 : _b.removeEventListener('animationend', aniListener);
4086
- };
4087
-
4088
- (_b = divElement.firstElementChild) === null || _b === void 0 ? void 0 : _b.addEventListener('animationend', aniListener);
4089
- });
4090
- } else {
4091
- setTimeout(function () {
4092
- divCloneRef.current = divElement.firstElementChild;
4093
- });
4094
4052
  }
4095
4053
  }
4096
4054
  }
@@ -4538,6 +4496,7 @@
4538
4496
  if (polygonRef.current) {
4539
4497
  // console.log('polygon cleared')
4540
4498
  controller.clearDrawable(polygonRef.current);
4499
+ polygonRef.current = undefined;
4541
4500
  }
4542
4501
  };
4543
4502
  }, []); //create/update object
@@ -5058,7 +5017,8 @@
5058
5017
  React.useEffect(function () {
5059
5018
  return function () {
5060
5019
  if (polylineRef.current) {
5061
- controller.clearDrawable(polylineRef.current); // console.log('polyline cleared')
5020
+ controller.clearDrawable(polylineRef.current);
5021
+ polylineRef.current = undefined; // console.log('polyline cleared')
5062
5022
  }
5063
5023
  };
5064
5024
  }, []); //create/update object
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mint-ui/map",
3
- "version": "0.5.1-beta",
3
+ "version": "0.5.3-beta",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.es.js",
6
6
  "browser": "./dist/index.umd.js",