@mint-ui/map 0.2.0-beta → 0.3.0-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.
@@ -12,12 +12,14 @@ export interface MintMapProps extends MintMapEvents {
12
12
  visible?: boolean;
13
13
  markerCache?: boolean;
14
14
  markerCachePoolSize?: number;
15
+ boundsChangeThrottlingTime?: number;
15
16
  }
16
17
  export interface MintMapEvents {
17
18
  onBoundsChanged?: (bounds: Bounds) => void;
18
19
  onZoomChanged?: (level: number) => void;
19
20
  onLoad?: (map: MapVendorType, controller: MintMapController) => void;
20
21
  onClick?: (positon: Position) => void;
22
+ onMouseMove?: (positon: Position) => void;
21
23
  }
22
24
  export declare class Position {
23
25
  lat: number;
@@ -36,6 +38,7 @@ export declare class Bounds {
36
38
  private covertNWSEtoNESW;
37
39
  private covertNESWtoNWSE;
38
40
  getCenter(): Position;
41
+ includesPosition(pos: Position): boolean;
39
42
  getIncludedPositions(positions: Position[]): Position[];
40
43
  includes(positions: Position | Position[]): boolean;
41
44
  includesOnlyOnePoint(positions: Position[]): boolean;
@@ -65,7 +65,11 @@ var Bounds = function () {
65
65
  };
66
66
 
67
67
  Bounds.prototype.getCenter = function () {
68
- return new Position(this.nw.lat + (this.se.lat - this.nw.lat) / 2, this.nw.lng + (this.se.lng - this.nw.lng) / 2);
68
+ return new Position(this.se.lat + (this.nw.lat - this.se.lat) / 2, this.nw.lng + (this.se.lng - this.nw.lng) / 2);
69
+ };
70
+
71
+ Bounds.prototype.includesPosition = function (pos) {
72
+ return this.nw.lng < pos.lng && this.se.lng > pos.lng && this.se.lat < pos.lat && this.nw.lat > pos.lat;
69
73
  };
70
74
 
71
75
  Bounds.prototype.getIncludedPositions = function (positions) {
@@ -74,7 +78,7 @@ var Bounds = function () {
74
78
  for (var _i = 0, positions_1 = positions; _i < positions_1.length; _i++) {
75
79
  var pos = positions_1[_i];
76
80
 
77
- if (!(this.nw.lat > pos.lat || this.se.lat < pos.lat || this.nw.lng > pos.lng || this.se.lng < pos.lng)) {
81
+ if (this.includesPosition(pos)) {
78
82
  result.push(pos);
79
83
  }
80
84
  }
@@ -88,7 +92,7 @@ var Bounds = function () {
88
92
  for (var _i = 0, positions_2 = positions; _i < positions_2.length; _i++) {
89
93
  var pos = positions_2[_i];
90
94
 
91
- if (this.nw.lat > pos.lat || this.se.lat < pos.lat || this.nw.lng > pos.lng || this.se.lng < pos.lng) {
95
+ if (!this.includesPosition(pos)) {
92
96
  return false;
93
97
  }
94
98
  }
@@ -100,7 +104,7 @@ var Bounds = function () {
100
104
  for (var _i = 0, positions_3 = positions; _i < positions_3.length; _i++) {
101
105
  var pos = positions_3[_i];
102
106
 
103
- if (!(this.nw.lat > pos.lat || this.se.lat < pos.lat || this.nw.lng > pos.lng || this.se.lng < pos.lng)) {
107
+ if (this.includesPosition(pos)) {
104
108
  return true;
105
109
  }
106
110
  }
@@ -30,4 +30,6 @@ export declare abstract class MintMapController {
30
30
  buildUrl(baseUrl: string, param: {
31
31
  [key: string]: string | string[];
32
32
  }): string;
33
+ private processedTime;
34
+ checkBoundsChangeThrottleTime(): boolean;
33
35
  }
@@ -8,6 +8,7 @@ var MintMapController = function () {
8
8
  function MintMapController(props) {
9
9
  this.mapApiLoaded = false;
10
10
  this.mapInitialized = false;
11
+ this.processedTime = 0;
11
12
  this.mapProps = props;
12
13
  }
13
14
 
@@ -52,6 +53,18 @@ var MintMapController = function () {
52
53
  return "".concat(baseUrl, "?").concat(params);
53
54
  };
54
55
 
56
+ MintMapController.prototype.checkBoundsChangeThrottleTime = function () {
57
+ if (!this.mapProps.boundsChangeThrottlingTime) return true;
58
+ var time = new Date().getTime();
59
+
60
+ if (this.processedTime > 0 && time - this.processedTime < this.mapProps.boundsChangeThrottlingTime) {
61
+ return false;
62
+ } else {
63
+ this.processedTime = time;
64
+ return true;
65
+ }
66
+ };
67
+
55
68
  return MintMapController;
56
69
  }();
57
70
 
@@ -0,0 +1,18 @@
1
+ import { Bounds, Position } from "../../MintMap";
2
+ export interface ClusterInfo {
3
+ bounds: Bounds;
4
+ checked: boolean;
5
+ center: boolean;
6
+ centerPosition: Position;
7
+ incList: any;
8
+ itemList: Position[];
9
+ size: number;
10
+ }
11
+ export interface ClusterStatus {
12
+ total: number;
13
+ average: number;
14
+ min: number;
15
+ max: number;
16
+ }
17
+ export declare type ClusterSizeCalculator = (info: ClusterInfo, status: ClusterStatus) => number;
18
+ export declare const getClusterInfo: (basePixelSize: number, mapBounds: Bounds, mapWidth: number, mapHeight: number, itemList: Position[], sizeFunction?: ClusterSizeCalculator) => (ClusterInfo[] | Bounds[])[];
@@ -19,7 +19,7 @@ function MapPolygonWrapper(_a) {
19
19
  React.useEffect(function () {
20
20
  return function () {
21
21
  if (polygonRef.current) {
22
- console.log('polygon cleared', controller.clearDrawable(polygonRef.current));
22
+ controller.clearDrawable(polygonRef.current);
23
23
  }
24
24
  };
25
25
  }, []);
@@ -19,7 +19,7 @@ function MapPolylineWrapper(_a) {
19
19
  React.useEffect(function () {
20
20
  return function () {
21
21
  if (polylineRef.current) {
22
- console.log('polyline cleared', controller.clearDrawable(polylineRef.current));
22
+ controller.clearDrawable(polylineRef.current);
23
23
  }
24
24
  };
25
25
  }, []);
@@ -23,7 +23,13 @@ var GoogleMintMapController = function (_super) {
23
23
  _this.dragged = false;
24
24
 
25
25
  _this.destroyMap = function () {
26
- console.log("".concat(_this.type, " map destroy feature is not supported"));
26
+ try {
27
+ _this.map && google.maps.event.clearInstanceListeners(_this.map);
28
+ } catch (e) {
29
+ console.log('google map destroy error', e);
30
+ }
31
+
32
+ console.log("".concat(_this.type, " map destroyed"));
27
33
  };
28
34
 
29
35
  console.log("".concat(_this.type, " controller loadded"));
@@ -111,7 +117,8 @@ var GoogleMintMapController = function (_super) {
111
117
  var outLine = position.map(function (elem) {
112
118
  return Array.isArray(elem) ? new MintMap.Position(elem[1], elem[0]) : elem;
113
119
  });
114
- var paths = innerPositions ? tslib.__spreadArray([outLine], innerPositions, true) : [outLine];
120
+ var paths = [outLine];
121
+ innerPositions && paths.push.apply(paths, innerPositions);
115
122
  var pol_2 = new google.maps.Polygon({
116
123
  map: this.map,
117
124
  paths: paths,
@@ -136,6 +143,16 @@ var GoogleMintMapController = function (_super) {
136
143
  GoogleMintMapController.prototype.updatePolygon = function (polygon, options) {
137
144
  if (polygon && polygon.native && polygon.native instanceof google.maps.Polygon) {
138
145
  var polygonOption = this.getValidOptions(options);
146
+
147
+ if (this.map && Array.isArray(options.position)) {
148
+ var outLine = options.position.map(function (elem) {
149
+ return Array.isArray(elem) ? new MintMap.Position(elem[1], elem[0]) : elem;
150
+ });
151
+ var paths = [outLine];
152
+ options.innerPositions && paths.push.apply(paths, options.innerPositions);
153
+ polygonOption.paths = paths;
154
+ }
155
+
139
156
  polygon.native.setOptions(polygonOption);
140
157
  }
141
158
  };
@@ -367,18 +384,28 @@ var GoogleMintMapController = function (_super) {
367
384
  minZoom: (_c = this.mapProps.base) === null || _c === void 0 ? void 0 : _c.minZoomLevel,
368
385
  zoom: (_d = this.mapProps.base) === null || _d === void 0 ? void 0 : _d.zoomLevel,
369
386
  disableDefaultUI: true,
370
- gestureHandling: 'greedy'
387
+ gestureHandling: 'greedy',
388
+ clickableIcons: false
371
389
  });
372
390
  map.addListener('idle', function () {
373
- _this.mapProps.onBoundsChanged && _this.mapProps.onBoundsChanged(_this.getCurrBounds());
391
+ _this.checkBoundsChangeThrottleTime() && _this.mapProps.onBoundsChanged && _this.mapProps.onBoundsChanged(_this.getCurrBounds());
374
392
  });
375
393
  map.addListener('zoom_changed', function () {
376
394
  _this.map && _this.mapProps.onZoomChanged && _this.mapProps.onZoomChanged(_this.map.getZoom());
377
395
  });
378
396
  map.addListener('click', function (e) {
397
+ if (!_this.mapProps.onClick) return;
398
+ var pos = new MintMap.Position(e.latLng.lat(), e.latLng.lng());
399
+ pos.offset = new MintMap.Offset(e.pixel.x, e.pixel.y);
400
+
401
+ _this.mapProps.onClick(pos);
402
+ });
403
+ map.addListener('mousemove', function (e) {
404
+ if (!_this.mapProps.onMouseMove) return;
379
405
  var pos = new MintMap.Position(e.latLng.lat(), e.latLng.lng());
380
406
  pos.offset = new MintMap.Offset(e.pixel.x, e.pixel.y);
381
- _this.mapProps.onClick && _this.mapProps.onClick(pos);
407
+
408
+ _this.mapProps.onMouseMove(pos);
382
409
  });
383
410
  this.map = map;
384
411
  this.mapInitialized = true;
@@ -127,7 +127,8 @@ var NaverMintMapController = function (_super) {
127
127
  var outLine = position.map(function (elem) {
128
128
  return Array.isArray(elem) ? new MintMap.Position(elem[1], elem[0]) : elem;
129
129
  });
130
- var paths = innerPositions ? tslib.__spreadArray([outLine], innerPositions, true) : [outLine];
130
+ var paths = [outLine];
131
+ innerPositions && paths.push.apply(paths, innerPositions);
131
132
  var pol_2 = new naver.maps.Polygon({
132
133
  map: this.map,
133
134
  paths: paths,
@@ -150,8 +151,18 @@ var NaverMintMapController = function (_super) {
150
151
 
151
152
  NaverMintMapController.prototype.updatePolygon = function (polygon, options) {
152
153
  if (polygon && polygon.native && polygon.native instanceof naver.maps.Polygon) {
154
+ var paths = void 0;
155
+
156
+ if (Array.isArray(options.position)) {
157
+ var outLine = options.position.map(function (elem) {
158
+ return Array.isArray(elem) ? new MintMap.Position(elem[1], elem[0]) : elem;
159
+ });
160
+ paths = [outLine];
161
+ options.innerPositions && paths.push.apply(paths, options.innerPositions);
162
+ }
163
+
153
164
  polygon.native.setOptions({
154
- paths: polygon.native.getPaths(),
165
+ paths: paths || polygon.native.getPaths(),
155
166
  visible: options.visible === undefined || options.visible,
156
167
  strokeColor: options.lineColor,
157
168
  strokeWeight: options.lineSize,
@@ -415,17 +426,25 @@ var NaverMintMapController = function (_super) {
415
426
  _this.dragged = true;
416
427
  }
417
428
  });
418
- map.addListener('idle', function () {
419
- _this.mapProps.onBoundsChanged && _this.mapProps.onBoundsChanged(_this.getCurrBounds());
429
+ map.addListener('idle', function (e) {
430
+ _this.map && _this.checkBoundsChangeThrottleTime() && _this.mapProps.onBoundsChanged && _this.mapProps.onBoundsChanged(_this.getCurrBounds());
420
431
  });
421
432
  map.addListener('zoom_changed', function () {
422
433
  _this.map && _this.mapProps.onZoomChanged && _this.mapProps.onZoomChanged(_this.map.getZoom());
423
434
  });
424
435
  map.addListener('click', function (e) {
425
- console.log('map click', e);
436
+ if (!_this.mapProps.onClick) return;
426
437
  var pos = new MintMap.Position(e.coord.y, e.coord.x);
427
438
  pos.offset = new MintMap.Offset(e.offset.x, e.offset.y);
428
- _this.mapProps.onClick && _this.mapProps.onClick(pos);
439
+
440
+ _this.mapProps.onClick(pos);
441
+ });
442
+ map.addListener('mousemove', function (e) {
443
+ if (!_this.mapProps.onMouseMove) return;
444
+ var pos = new MintMap.Position(e.coord.y, e.coord.x);
445
+ pos.offset = new MintMap.Offset(e.offset.x, e.offset.y);
446
+
447
+ _this.mapProps.onMouseMove(pos);
429
448
  });
430
449
  this.map = map;
431
450
  this.mapInitialized = true;
@@ -454,14 +473,14 @@ var NaverMintMapController = function (_super) {
454
473
  NaverMintMapController.prototype.destroyMap = function () {
455
474
  var _a;
456
475
 
457
- console.log("".concat(this.type, " map destroyed"));
458
-
459
476
  try {
460
477
  this.map && this.map.destroy();
461
478
  (_a = this.markerPool) === null || _a === void 0 ? void 0 : _a.destroy();
462
479
  } catch (e) {
463
480
  console.log('naver map destroy error', e);
464
481
  }
482
+
483
+ console.log("".concat(this.type, " map destroyed"));
465
484
  };
466
485
 
467
486
  NaverMintMapController.prototype.getCurrBounds = function () {
@@ -470,7 +489,7 @@ var NaverMintMapController = function (_super) {
470
489
  }
471
490
 
472
491
  var bounds = this.map.getBounds();
473
- return MintMap.Bounds.fromNWSE(new MintMap.Position(bounds.getMin().y, bounds.getMin().x), new MintMap.Position(bounds.getMax().y, bounds.getMax().x));
492
+ return MintMap.Bounds.fromNWSE(new MintMap.Position(bounds.getMax().y, bounds.getMin().x), new MintMap.Position(bounds.getMin().y, bounds.getMax().x));
474
493
  };
475
494
 
476
495
  NaverMintMapController.prototype.panningTo = function (targetCenter) {
package/dist/index.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { __awaiter, __generator, __extends, __spreadArray, __assign, __rest } from 'tslib';
1
+ import { __awaiter, __generator, __extends, __assign, __rest, __spreadArray } from 'tslib';
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';
@@ -319,6 +319,7 @@ var MintMapController = function () {
319
319
  function MintMapController(props) {
320
320
  this.mapApiLoaded = false;
321
321
  this.mapInitialized = false;
322
+ this.processedTime = 0;
322
323
  this.mapProps = props;
323
324
  }
324
325
 
@@ -363,6 +364,18 @@ var MintMapController = function () {
363
364
  return "".concat(baseUrl, "?").concat(params);
364
365
  };
365
366
 
367
+ MintMapController.prototype.checkBoundsChangeThrottleTime = function () {
368
+ if (!this.mapProps.boundsChangeThrottlingTime) return true;
369
+ var time = new Date().getTime();
370
+
371
+ if (this.processedTime > 0 && time - this.processedTime < this.mapProps.boundsChangeThrottlingTime) {
372
+ return false;
373
+ } else {
374
+ this.processedTime = time;
375
+ return true;
376
+ }
377
+ };
378
+
366
379
  return MintMapController;
367
380
  }();
368
381
 
@@ -511,7 +524,8 @@ var NaverMintMapController = function (_super) {
511
524
  var outLine = position.map(function (elem) {
512
525
  return Array.isArray(elem) ? new Position(elem[1], elem[0]) : elem;
513
526
  });
514
- var paths = innerPositions ? __spreadArray([outLine], innerPositions, true) : [outLine];
527
+ var paths = [outLine];
528
+ innerPositions && paths.push.apply(paths, innerPositions);
515
529
  var pol_2 = new naver.maps.Polygon({
516
530
  map: this.map,
517
531
  paths: paths,
@@ -534,8 +548,18 @@ var NaverMintMapController = function (_super) {
534
548
 
535
549
  NaverMintMapController.prototype.updatePolygon = function (polygon, options) {
536
550
  if (polygon && polygon.native && polygon.native instanceof naver.maps.Polygon) {
551
+ var paths = void 0;
552
+
553
+ if (Array.isArray(options.position)) {
554
+ var outLine = options.position.map(function (elem) {
555
+ return Array.isArray(elem) ? new Position(elem[1], elem[0]) : elem;
556
+ });
557
+ paths = [outLine];
558
+ options.innerPositions && paths.push.apply(paths, options.innerPositions);
559
+ }
560
+
537
561
  polygon.native.setOptions({
538
- paths: polygon.native.getPaths(),
562
+ paths: paths || polygon.native.getPaths(),
539
563
  visible: options.visible === undefined || options.visible,
540
564
  strokeColor: options.lineColor,
541
565
  strokeWeight: options.lineSize,
@@ -799,17 +823,25 @@ var NaverMintMapController = function (_super) {
799
823
  _this.dragged = true;
800
824
  }
801
825
  });
802
- map.addListener('idle', function () {
803
- _this.mapProps.onBoundsChanged && _this.mapProps.onBoundsChanged(_this.getCurrBounds());
826
+ map.addListener('idle', function (e) {
827
+ _this.map && _this.checkBoundsChangeThrottleTime() && _this.mapProps.onBoundsChanged && _this.mapProps.onBoundsChanged(_this.getCurrBounds());
804
828
  });
805
829
  map.addListener('zoom_changed', function () {
806
830
  _this.map && _this.mapProps.onZoomChanged && _this.mapProps.onZoomChanged(_this.map.getZoom());
807
831
  });
808
832
  map.addListener('click', function (e) {
809
- console.log('map click', e);
833
+ if (!_this.mapProps.onClick) return;
810
834
  var pos = new Position(e.coord.y, e.coord.x);
811
835
  pos.offset = new Offset(e.offset.x, e.offset.y);
812
- _this.mapProps.onClick && _this.mapProps.onClick(pos);
836
+
837
+ _this.mapProps.onClick(pos);
838
+ });
839
+ map.addListener('mousemove', function (e) {
840
+ if (!_this.mapProps.onMouseMove) return;
841
+ var pos = new Position(e.coord.y, e.coord.x);
842
+ pos.offset = new Offset(e.offset.x, e.offset.y);
843
+
844
+ _this.mapProps.onMouseMove(pos);
813
845
  });
814
846
  this.map = map;
815
847
  this.mapInitialized = true;
@@ -838,14 +870,14 @@ var NaverMintMapController = function (_super) {
838
870
  NaverMintMapController.prototype.destroyMap = function () {
839
871
  var _a;
840
872
 
841
- console.log("".concat(this.type, " map destroyed"));
842
-
843
873
  try {
844
874
  this.map && this.map.destroy();
845
875
  (_a = this.markerPool) === null || _a === void 0 ? void 0 : _a.destroy();
846
876
  } catch (e) {
847
877
  console.log('naver map destroy error', e);
848
878
  }
879
+
880
+ console.log("".concat(this.type, " map destroyed"));
849
881
  };
850
882
 
851
883
  NaverMintMapController.prototype.getCurrBounds = function () {
@@ -854,7 +886,7 @@ var NaverMintMapController = function (_super) {
854
886
  }
855
887
 
856
888
  var bounds = this.map.getBounds();
857
- return Bounds.fromNWSE(new Position(bounds.getMin().y, bounds.getMin().x), new Position(bounds.getMax().y, bounds.getMax().x));
889
+ return Bounds.fromNWSE(new Position(bounds.getMax().y, bounds.getMin().x), new Position(bounds.getMin().y, bounds.getMax().x));
858
890
  };
859
891
 
860
892
  NaverMintMapController.prototype.panningTo = function (targetCenter) {
@@ -896,7 +928,13 @@ var GoogleMintMapController = function (_super) {
896
928
  _this.dragged = false;
897
929
 
898
930
  _this.destroyMap = function () {
899
- console.log("".concat(_this.type, " map destroy feature is not supported"));
931
+ try {
932
+ _this.map && google.maps.event.clearInstanceListeners(_this.map);
933
+ } catch (e) {
934
+ console.log('google map destroy error', e);
935
+ }
936
+
937
+ console.log("".concat(_this.type, " map destroyed"));
900
938
  };
901
939
 
902
940
  console.log("".concat(_this.type, " controller loadded"));
@@ -984,7 +1022,8 @@ var GoogleMintMapController = function (_super) {
984
1022
  var outLine = position.map(function (elem) {
985
1023
  return Array.isArray(elem) ? new Position(elem[1], elem[0]) : elem;
986
1024
  });
987
- var paths = innerPositions ? __spreadArray([outLine], innerPositions, true) : [outLine];
1025
+ var paths = [outLine];
1026
+ innerPositions && paths.push.apply(paths, innerPositions);
988
1027
  var pol_2 = new google.maps.Polygon({
989
1028
  map: this.map,
990
1029
  paths: paths,
@@ -1009,6 +1048,16 @@ var GoogleMintMapController = function (_super) {
1009
1048
  GoogleMintMapController.prototype.updatePolygon = function (polygon, options) {
1010
1049
  if (polygon && polygon.native && polygon.native instanceof google.maps.Polygon) {
1011
1050
  var polygonOption = this.getValidOptions(options);
1051
+
1052
+ if (this.map && Array.isArray(options.position)) {
1053
+ var outLine = options.position.map(function (elem) {
1054
+ return Array.isArray(elem) ? new Position(elem[1], elem[0]) : elem;
1055
+ });
1056
+ var paths = [outLine];
1057
+ options.innerPositions && paths.push.apply(paths, options.innerPositions);
1058
+ polygonOption.paths = paths;
1059
+ }
1060
+
1012
1061
  polygon.native.setOptions(polygonOption);
1013
1062
  }
1014
1063
  };
@@ -1240,18 +1289,28 @@ var GoogleMintMapController = function (_super) {
1240
1289
  minZoom: (_c = this.mapProps.base) === null || _c === void 0 ? void 0 : _c.minZoomLevel,
1241
1290
  zoom: (_d = this.mapProps.base) === null || _d === void 0 ? void 0 : _d.zoomLevel,
1242
1291
  disableDefaultUI: true,
1243
- gestureHandling: 'greedy'
1292
+ gestureHandling: 'greedy',
1293
+ clickableIcons: false
1244
1294
  });
1245
1295
  map.addListener('idle', function () {
1246
- _this.mapProps.onBoundsChanged && _this.mapProps.onBoundsChanged(_this.getCurrBounds());
1296
+ _this.checkBoundsChangeThrottleTime() && _this.mapProps.onBoundsChanged && _this.mapProps.onBoundsChanged(_this.getCurrBounds());
1247
1297
  });
1248
1298
  map.addListener('zoom_changed', function () {
1249
1299
  _this.map && _this.mapProps.onZoomChanged && _this.mapProps.onZoomChanged(_this.map.getZoom());
1250
1300
  });
1251
1301
  map.addListener('click', function (e) {
1302
+ if (!_this.mapProps.onClick) return;
1252
1303
  var pos = new Position(e.latLng.lat(), e.latLng.lng());
1253
1304
  pos.offset = new Offset(e.pixel.x, e.pixel.y);
1254
- _this.mapProps.onClick && _this.mapProps.onClick(pos);
1305
+
1306
+ _this.mapProps.onClick(pos);
1307
+ });
1308
+ map.addListener('mousemove', function (e) {
1309
+ if (!_this.mapProps.onMouseMove) return;
1310
+ var pos = new Position(e.latLng.lat(), e.latLng.lng());
1311
+ pos.offset = new Offset(e.pixel.x, e.pixel.y);
1312
+
1313
+ _this.mapProps.onMouseMove(pos);
1255
1314
  });
1256
1315
  this.map = map;
1257
1316
  this.mapInitialized = true;
@@ -1353,7 +1412,11 @@ var Bounds = function () {
1353
1412
  };
1354
1413
 
1355
1414
  Bounds.prototype.getCenter = function () {
1356
- return new Position(this.nw.lat + (this.se.lat - this.nw.lat) / 2, this.nw.lng + (this.se.lng - this.nw.lng) / 2);
1415
+ return new Position(this.se.lat + (this.nw.lat - this.se.lat) / 2, this.nw.lng + (this.se.lng - this.nw.lng) / 2);
1416
+ };
1417
+
1418
+ Bounds.prototype.includesPosition = function (pos) {
1419
+ return this.nw.lng < pos.lng && this.se.lng > pos.lng && this.se.lat < pos.lat && this.nw.lat > pos.lat;
1357
1420
  };
1358
1421
 
1359
1422
  Bounds.prototype.getIncludedPositions = function (positions) {
@@ -1362,7 +1425,7 @@ var Bounds = function () {
1362
1425
  for (var _i = 0, positions_1 = positions; _i < positions_1.length; _i++) {
1363
1426
  var pos = positions_1[_i];
1364
1427
 
1365
- if (!(this.nw.lat > pos.lat || this.se.lat < pos.lat || this.nw.lng > pos.lng || this.se.lng < pos.lng)) {
1428
+ if (this.includesPosition(pos)) {
1366
1429
  result.push(pos);
1367
1430
  }
1368
1431
  }
@@ -1376,7 +1439,7 @@ var Bounds = function () {
1376
1439
  for (var _i = 0, positions_2 = positions; _i < positions_2.length; _i++) {
1377
1440
  var pos = positions_2[_i];
1378
1441
 
1379
- if (this.nw.lat > pos.lat || this.se.lat < pos.lat || this.nw.lng > pos.lng || this.se.lng < pos.lng) {
1442
+ if (!this.includesPosition(pos)) {
1380
1443
  return false;
1381
1444
  }
1382
1445
  }
@@ -1388,7 +1451,7 @@ var Bounds = function () {
1388
1451
  for (var _i = 0, positions_3 = positions; _i < positions_3.length; _i++) {
1389
1452
  var pos = positions_3[_i];
1390
1453
 
1391
- if (!(this.nw.lat > pos.lat || this.se.lat < pos.lat || this.nw.lng > pos.lng || this.se.lng < pos.lng)) {
1454
+ if (this.includesPosition(pos)) {
1392
1455
  return true;
1393
1456
  }
1394
1457
  }
@@ -1928,7 +1991,7 @@ function MapPolygonWrapper(_a) {
1928
1991
  useEffect(function () {
1929
1992
  return function () {
1930
1993
  if (polygonRef.current) {
1931
- console.log('polygon cleared', controller.clearDrawable(polygonRef.current));
1994
+ controller.clearDrawable(polygonRef.current);
1932
1995
  }
1933
1996
  };
1934
1997
  }, []);
@@ -2181,7 +2244,7 @@ function MapPolylineWrapper(_a) {
2181
2244
  useEffect(function () {
2182
2245
  return function () {
2183
2246
  if (polylineRef.current) {
2184
- console.log('polyline cleared', controller.clearDrawable(polylineRef.current));
2247
+ controller.clearDrawable(polylineRef.current);
2185
2248
  }
2186
2249
  };
2187
2250
  }, []);
package/dist/index.umd.js CHANGED
@@ -324,6 +324,7 @@
324
324
  function MintMapController(props) {
325
325
  this.mapApiLoaded = false;
326
326
  this.mapInitialized = false;
327
+ this.processedTime = 0;
327
328
  this.mapProps = props;
328
329
  }
329
330
 
@@ -368,6 +369,18 @@
368
369
  return "".concat(baseUrl, "?").concat(params);
369
370
  };
370
371
 
372
+ MintMapController.prototype.checkBoundsChangeThrottleTime = function () {
373
+ if (!this.mapProps.boundsChangeThrottlingTime) return true;
374
+ var time = new Date().getTime();
375
+
376
+ if (this.processedTime > 0 && time - this.processedTime < this.mapProps.boundsChangeThrottlingTime) {
377
+ return false;
378
+ } else {
379
+ this.processedTime = time;
380
+ return true;
381
+ }
382
+ };
383
+
371
384
  return MintMapController;
372
385
  }();
373
386
 
@@ -516,7 +529,8 @@
516
529
  var outLine = position.map(function (elem) {
517
530
  return Array.isArray(elem) ? new Position(elem[1], elem[0]) : elem;
518
531
  });
519
- var paths = innerPositions ? tslib.__spreadArray([outLine], innerPositions, true) : [outLine];
532
+ var paths = [outLine];
533
+ innerPositions && paths.push.apply(paths, innerPositions);
520
534
  var pol_2 = new naver.maps.Polygon({
521
535
  map: this.map,
522
536
  paths: paths,
@@ -539,8 +553,18 @@
539
553
 
540
554
  NaverMintMapController.prototype.updatePolygon = function (polygon, options) {
541
555
  if (polygon && polygon.native && polygon.native instanceof naver.maps.Polygon) {
556
+ var paths = void 0;
557
+
558
+ if (Array.isArray(options.position)) {
559
+ var outLine = options.position.map(function (elem) {
560
+ return Array.isArray(elem) ? new Position(elem[1], elem[0]) : elem;
561
+ });
562
+ paths = [outLine];
563
+ options.innerPositions && paths.push.apply(paths, options.innerPositions);
564
+ }
565
+
542
566
  polygon.native.setOptions({
543
- paths: polygon.native.getPaths(),
567
+ paths: paths || polygon.native.getPaths(),
544
568
  visible: options.visible === undefined || options.visible,
545
569
  strokeColor: options.lineColor,
546
570
  strokeWeight: options.lineSize,
@@ -804,17 +828,25 @@
804
828
  _this.dragged = true;
805
829
  }
806
830
  });
807
- map.addListener('idle', function () {
808
- _this.mapProps.onBoundsChanged && _this.mapProps.onBoundsChanged(_this.getCurrBounds());
831
+ map.addListener('idle', function (e) {
832
+ _this.map && _this.checkBoundsChangeThrottleTime() && _this.mapProps.onBoundsChanged && _this.mapProps.onBoundsChanged(_this.getCurrBounds());
809
833
  });
810
834
  map.addListener('zoom_changed', function () {
811
835
  _this.map && _this.mapProps.onZoomChanged && _this.mapProps.onZoomChanged(_this.map.getZoom());
812
836
  });
813
837
  map.addListener('click', function (e) {
814
- console.log('map click', e);
838
+ if (!_this.mapProps.onClick) return;
815
839
  var pos = new Position(e.coord.y, e.coord.x);
816
840
  pos.offset = new Offset(e.offset.x, e.offset.y);
817
- _this.mapProps.onClick && _this.mapProps.onClick(pos);
841
+
842
+ _this.mapProps.onClick(pos);
843
+ });
844
+ map.addListener('mousemove', function (e) {
845
+ if (!_this.mapProps.onMouseMove) return;
846
+ var pos = new Position(e.coord.y, e.coord.x);
847
+ pos.offset = new Offset(e.offset.x, e.offset.y);
848
+
849
+ _this.mapProps.onMouseMove(pos);
818
850
  });
819
851
  this.map = map;
820
852
  this.mapInitialized = true;
@@ -843,14 +875,14 @@
843
875
  NaverMintMapController.prototype.destroyMap = function () {
844
876
  var _a;
845
877
 
846
- console.log("".concat(this.type, " map destroyed"));
847
-
848
878
  try {
849
879
  this.map && this.map.destroy();
850
880
  (_a = this.markerPool) === null || _a === void 0 ? void 0 : _a.destroy();
851
881
  } catch (e) {
852
882
  console.log('naver map destroy error', e);
853
883
  }
884
+
885
+ console.log("".concat(this.type, " map destroyed"));
854
886
  };
855
887
 
856
888
  NaverMintMapController.prototype.getCurrBounds = function () {
@@ -859,7 +891,7 @@
859
891
  }
860
892
 
861
893
  var bounds = this.map.getBounds();
862
- return Bounds.fromNWSE(new Position(bounds.getMin().y, bounds.getMin().x), new Position(bounds.getMax().y, bounds.getMax().x));
894
+ return Bounds.fromNWSE(new Position(bounds.getMax().y, bounds.getMin().x), new Position(bounds.getMin().y, bounds.getMax().x));
863
895
  };
864
896
 
865
897
  NaverMintMapController.prototype.panningTo = function (targetCenter) {
@@ -901,7 +933,13 @@
901
933
  _this.dragged = false;
902
934
 
903
935
  _this.destroyMap = function () {
904
- console.log("".concat(_this.type, " map destroy feature is not supported"));
936
+ try {
937
+ _this.map && google.maps.event.clearInstanceListeners(_this.map);
938
+ } catch (e) {
939
+ console.log('google map destroy error', e);
940
+ }
941
+
942
+ console.log("".concat(_this.type, " map destroyed"));
905
943
  };
906
944
 
907
945
  console.log("".concat(_this.type, " controller loadded"));
@@ -989,7 +1027,8 @@
989
1027
  var outLine = position.map(function (elem) {
990
1028
  return Array.isArray(elem) ? new Position(elem[1], elem[0]) : elem;
991
1029
  });
992
- var paths = innerPositions ? tslib.__spreadArray([outLine], innerPositions, true) : [outLine];
1030
+ var paths = [outLine];
1031
+ innerPositions && paths.push.apply(paths, innerPositions);
993
1032
  var pol_2 = new google.maps.Polygon({
994
1033
  map: this.map,
995
1034
  paths: paths,
@@ -1014,6 +1053,16 @@
1014
1053
  GoogleMintMapController.prototype.updatePolygon = function (polygon, options) {
1015
1054
  if (polygon && polygon.native && polygon.native instanceof google.maps.Polygon) {
1016
1055
  var polygonOption = this.getValidOptions(options);
1056
+
1057
+ if (this.map && Array.isArray(options.position)) {
1058
+ var outLine = options.position.map(function (elem) {
1059
+ return Array.isArray(elem) ? new Position(elem[1], elem[0]) : elem;
1060
+ });
1061
+ var paths = [outLine];
1062
+ options.innerPositions && paths.push.apply(paths, options.innerPositions);
1063
+ polygonOption.paths = paths;
1064
+ }
1065
+
1017
1066
  polygon.native.setOptions(polygonOption);
1018
1067
  }
1019
1068
  };
@@ -1245,18 +1294,28 @@
1245
1294
  minZoom: (_c = this.mapProps.base) === null || _c === void 0 ? void 0 : _c.minZoomLevel,
1246
1295
  zoom: (_d = this.mapProps.base) === null || _d === void 0 ? void 0 : _d.zoomLevel,
1247
1296
  disableDefaultUI: true,
1248
- gestureHandling: 'greedy'
1297
+ gestureHandling: 'greedy',
1298
+ clickableIcons: false
1249
1299
  });
1250
1300
  map.addListener('idle', function () {
1251
- _this.mapProps.onBoundsChanged && _this.mapProps.onBoundsChanged(_this.getCurrBounds());
1301
+ _this.checkBoundsChangeThrottleTime() && _this.mapProps.onBoundsChanged && _this.mapProps.onBoundsChanged(_this.getCurrBounds());
1252
1302
  });
1253
1303
  map.addListener('zoom_changed', function () {
1254
1304
  _this.map && _this.mapProps.onZoomChanged && _this.mapProps.onZoomChanged(_this.map.getZoom());
1255
1305
  });
1256
1306
  map.addListener('click', function (e) {
1307
+ if (!_this.mapProps.onClick) return;
1257
1308
  var pos = new Position(e.latLng.lat(), e.latLng.lng());
1258
1309
  pos.offset = new Offset(e.pixel.x, e.pixel.y);
1259
- _this.mapProps.onClick && _this.mapProps.onClick(pos);
1310
+
1311
+ _this.mapProps.onClick(pos);
1312
+ });
1313
+ map.addListener('mousemove', function (e) {
1314
+ if (!_this.mapProps.onMouseMove) return;
1315
+ var pos = new Position(e.latLng.lat(), e.latLng.lng());
1316
+ pos.offset = new Offset(e.pixel.x, e.pixel.y);
1317
+
1318
+ _this.mapProps.onMouseMove(pos);
1260
1319
  });
1261
1320
  this.map = map;
1262
1321
  this.mapInitialized = true;
@@ -1358,7 +1417,11 @@
1358
1417
  };
1359
1418
 
1360
1419
  Bounds.prototype.getCenter = function () {
1361
- return new Position(this.nw.lat + (this.se.lat - this.nw.lat) / 2, this.nw.lng + (this.se.lng - this.nw.lng) / 2);
1420
+ return new Position(this.se.lat + (this.nw.lat - this.se.lat) / 2, this.nw.lng + (this.se.lng - this.nw.lng) / 2);
1421
+ };
1422
+
1423
+ Bounds.prototype.includesPosition = function (pos) {
1424
+ return this.nw.lng < pos.lng && this.se.lng > pos.lng && this.se.lat < pos.lat && this.nw.lat > pos.lat;
1362
1425
  };
1363
1426
 
1364
1427
  Bounds.prototype.getIncludedPositions = function (positions) {
@@ -1367,7 +1430,7 @@
1367
1430
  for (var _i = 0, positions_1 = positions; _i < positions_1.length; _i++) {
1368
1431
  var pos = positions_1[_i];
1369
1432
 
1370
- if (!(this.nw.lat > pos.lat || this.se.lat < pos.lat || this.nw.lng > pos.lng || this.se.lng < pos.lng)) {
1433
+ if (this.includesPosition(pos)) {
1371
1434
  result.push(pos);
1372
1435
  }
1373
1436
  }
@@ -1381,7 +1444,7 @@
1381
1444
  for (var _i = 0, positions_2 = positions; _i < positions_2.length; _i++) {
1382
1445
  var pos = positions_2[_i];
1383
1446
 
1384
- if (this.nw.lat > pos.lat || this.se.lat < pos.lat || this.nw.lng > pos.lng || this.se.lng < pos.lng) {
1447
+ if (!this.includesPosition(pos)) {
1385
1448
  return false;
1386
1449
  }
1387
1450
  }
@@ -1393,7 +1456,7 @@
1393
1456
  for (var _i = 0, positions_3 = positions; _i < positions_3.length; _i++) {
1394
1457
  var pos = positions_3[_i];
1395
1458
 
1396
- if (!(this.nw.lat > pos.lat || this.se.lat < pos.lat || this.nw.lng > pos.lng || this.se.lng < pos.lng)) {
1459
+ if (this.includesPosition(pos)) {
1397
1460
  return true;
1398
1461
  }
1399
1462
  }
@@ -1933,7 +1996,7 @@
1933
1996
  React.useEffect(function () {
1934
1997
  return function () {
1935
1998
  if (polygonRef.current) {
1936
- console.log('polygon cleared', controller.clearDrawable(polygonRef.current));
1999
+ controller.clearDrawable(polygonRef.current);
1937
2000
  }
1938
2001
  };
1939
2002
  }, []);
@@ -2186,7 +2249,7 @@
2186
2249
  React.useEffect(function () {
2187
2250
  return function () {
2188
2251
  if (polylineRef.current) {
2189
- console.log('polyline cleared', controller.clearDrawable(polylineRef.current));
2252
+ controller.clearDrawable(polylineRef.current);
2190
2253
  }
2191
2254
  };
2192
2255
  }, []);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mint-ui/map",
3
- "version": "0.2.0-beta",
3
+ "version": "0.3.0-beta",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.es.js",
6
6
  "browser": "./dist/index.umd.js",