@mint-ui/map 0.1.1-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.
- package/.eslintrc.js +110 -0
- package/LICENSE +21 -0
- package/README.md +15 -0
- package/dist/components/mint-map/MintMap.d.ts +81 -0
- package/dist/components/mint-map/MintMap.js +206 -0
- package/dist/components/mint-map/MintMap.module.scss.js +13 -0
- package/dist/components/mint-map/core/MintMapController.d.ts +32 -0
- package/dist/components/mint-map/core/MintMapController.js +56 -0
- package/dist/components/mint-map/core/MintMapCore.d.ts +3 -0
- package/dist/components/mint-map/core/MintMapCore.js +69 -0
- package/dist/components/mint-map/core/MintMapCore.module.scss.js +13 -0
- package/dist/components/mint-map/core/advanced/MapBuildingProjection.d.ts +15 -0
- package/dist/components/mint-map/core/advanced/MapBuildingProjection.js +173 -0
- package/dist/components/mint-map/core/hooks/MarkerMovingHook.d.ts +6 -0
- package/dist/components/mint-map/core/hooks/MarkerMovingHook.js +145 -0
- package/dist/components/mint-map/core/index.d.ts +7 -0
- package/dist/components/mint-map/core/provider/MintMapProvider.d.ts +8 -0
- package/dist/components/mint-map/core/provider/MintMapProvider.js +30 -0
- package/dist/components/mint-map/core/util/animation.d.ts +16 -0
- package/dist/components/mint-map/core/util/animation.js +70 -0
- package/dist/components/mint-map/core/util/calculate.d.ts +29 -0
- package/dist/components/mint-map/core/util/calculate.js +167 -0
- package/dist/components/mint-map/core/util/waiting.d.ts +1 -0
- package/dist/components/mint-map/core/wrapper/MapControlWrapper.d.ts +11 -0
- package/dist/components/mint-map/core/wrapper/MapControlWrapper.js +77 -0
- package/dist/components/mint-map/core/wrapper/MapMarkerWrapper.d.ts +23 -0
- package/dist/components/mint-map/core/wrapper/MapMarkerWrapper.js +163 -0
- package/dist/components/mint-map/core/wrapper/MapPolygonWrapper.d.ts +5 -0
- package/dist/components/mint-map/core/wrapper/MapPolygonWrapper.js +39 -0
- package/dist/components/mint-map/core/wrapper/MapPolylineWrapper.d.ts +5 -0
- package/dist/components/mint-map/core/wrapper/MapPolylineWrapper.js +39 -0
- package/dist/components/mint-map/core/wrapper/MintMapWrapper.module.scss.js +13 -0
- package/dist/components/mint-map/google/GoogleMintMapController.d.ts +34 -0
- package/dist/components/mint-map/index.d.ts +2 -0
- package/dist/components/mint-map/naver/NaverMintMapController.d.ts +33 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +1096 -0
- package/dist/index.js +23 -0
- package/dist/index.umd.js +1113 -0
- package/package.json +74 -0
- package/test.ts +7 -0
package/dist/index.es.js
ADDED
|
@@ -0,0 +1,1096 @@
|
|
|
1
|
+
import { __awaiter, __generator, __extends, __rest, __assign, __spreadArray } from 'tslib';
|
|
2
|
+
import React, { createContext, useContext, useRef, useState, useEffect } from 'react';
|
|
3
|
+
import classNames from 'classnames/bind';
|
|
4
|
+
import styleInject from 'style-inject';
|
|
5
|
+
import { createPortal } from 'react-dom';
|
|
6
|
+
|
|
7
|
+
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}";
|
|
8
|
+
var styles$2 = {"loading-point-container":"MintMap-module_loading-point-container__znk6l","ani-blink":"MintMap-module_ani-blink__K89JK","blink":"MintMap-module_blink__mqfeV","ani-fade-in":"MintMap-module_ani-fade-in__lpHuy","fade-in":"MintMap-module_fade-in__jHpv1","ani-fade-out":"MintMap-module_ani-fade-out__5-esw","fade-out":"MintMap-module_fade-out__CIjGe","ani-expansion":"MintMap-module_ani-expansion__S2vOZ","expansion":"MintMap-module_expansion__WMo5-"};
|
|
9
|
+
styleInject(css_248z$2);
|
|
10
|
+
|
|
11
|
+
var MintMapControllerContext = createContext(null);
|
|
12
|
+
function MintMapProvider(_a) {
|
|
13
|
+
var controller = _a.controller,
|
|
14
|
+
children = _a.children;
|
|
15
|
+
return React.createElement(MintMapControllerContext.Provider, {
|
|
16
|
+
value: controller
|
|
17
|
+
}, children);
|
|
18
|
+
}
|
|
19
|
+
function MintMapProvider.useMintMapController() {
|
|
20
|
+
var controller = useContext(MintMapControllerContext);
|
|
21
|
+
|
|
22
|
+
if (controller === null) {
|
|
23
|
+
throw new Error('controller is not initialized');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return controller;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
var css_248z$1 = ".MintMapCore-module_mint-map-root__SMfwn {\n position: relative;\n height: 100%;\n overflow: hidden;\n}\n\n.MintMapCore-module_mint-map-container__8MIIr {\n height: 100%;\n}";
|
|
30
|
+
var styles$1 = {"mint-map-root":"MintMapCore-module_mint-map-root__SMfwn","mint-map-container":"MintMapCore-module_mint-map-container__8MIIr"};
|
|
31
|
+
styleInject(css_248z$1);
|
|
32
|
+
|
|
33
|
+
var cn$2 = classNames.bind(styles$1);
|
|
34
|
+
function MintMapCore(_a) {
|
|
35
|
+
var _this = this;
|
|
36
|
+
|
|
37
|
+
var onLoad = _a.onLoad,
|
|
38
|
+
_b = _a.visible,
|
|
39
|
+
visible = _b === void 0 ? true : _b,
|
|
40
|
+
children = _a.children;
|
|
41
|
+
var controller = MintMapProvider.useMintMapController();
|
|
42
|
+
var elementRef = useRef(null);
|
|
43
|
+
|
|
44
|
+
var _c = useState(false),
|
|
45
|
+
mapInitialized = _c[0],
|
|
46
|
+
setMapInitialized = _c[1];
|
|
47
|
+
|
|
48
|
+
useEffect(function () {
|
|
49
|
+
(function () {
|
|
50
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
51
|
+
var map_1;
|
|
52
|
+
return __generator(this, function (_a) {
|
|
53
|
+
switch (_a.label) {
|
|
54
|
+
case 0:
|
|
55
|
+
if (!(elementRef && elementRef.current)) return [3, 2];
|
|
56
|
+
return [4, controller.initializingMap(elementRef.current)];
|
|
57
|
+
|
|
58
|
+
case 1:
|
|
59
|
+
map_1 = _a.sent();
|
|
60
|
+
setTimeout(function () {
|
|
61
|
+
setMapInitialized(true);
|
|
62
|
+
onLoad && onLoad(map_1, controller);
|
|
63
|
+
}, 100);
|
|
64
|
+
_a.label = 2;
|
|
65
|
+
|
|
66
|
+
case 2:
|
|
67
|
+
return [2];
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
})();
|
|
72
|
+
|
|
73
|
+
return function () {
|
|
74
|
+
controller && controller.destroyMap();
|
|
75
|
+
};
|
|
76
|
+
}, [controller, elementRef]);
|
|
77
|
+
return React.createElement("div", {
|
|
78
|
+
className: cn$2('mint-map-root'),
|
|
79
|
+
style: {
|
|
80
|
+
visibility: visible ? 'inherit' : 'hidden'
|
|
81
|
+
}
|
|
82
|
+
}, mapInitialized && children, React.createElement("div", {
|
|
83
|
+
className: cn$2('mint-map-container'),
|
|
84
|
+
ref: elementRef
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
var LinePoints = function () {
|
|
89
|
+
function LinePoints(x1, y1, x2, y2) {
|
|
90
|
+
this.x1 = x1;
|
|
91
|
+
this.y1 = y1;
|
|
92
|
+
this.x2 = x2;
|
|
93
|
+
this.y2 = y2;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return LinePoints;
|
|
97
|
+
}();
|
|
98
|
+
|
|
99
|
+
var PolygonCalculator = function () {
|
|
100
|
+
function PolygonCalculator() {}
|
|
101
|
+
|
|
102
|
+
PolygonCalculator.getCenter = function (positions) {
|
|
103
|
+
var maxX, minX, maxY, minY;
|
|
104
|
+
|
|
105
|
+
for (var _i = 0, positions_1 = positions; _i < positions_1.length; _i++) {
|
|
106
|
+
var pos = positions_1[_i];
|
|
107
|
+
|
|
108
|
+
if (maxX === undefined || pos.lat > maxX) {
|
|
109
|
+
maxX = pos.lat;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (minX === undefined || pos.lat < minX) {
|
|
113
|
+
minX = pos.lat;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (maxY === undefined || pos.lng > maxY) {
|
|
117
|
+
maxY = pos.lng;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (minY === undefined || pos.lng < minY) {
|
|
121
|
+
minY = pos.lng;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (maxX && minX && maxY && minY) {
|
|
126
|
+
return new MintMap.Position(minX + (maxX - minX) / 2, minY + (maxY - minY) / 2);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
throw new Error('Calculate Center Error!!!');
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
PolygonCalculator.intersects = function (positions1, positions2) {
|
|
133
|
+
var lines = [];
|
|
134
|
+
|
|
135
|
+
for (var i = 0; i < positions2.length - 1; i++) {
|
|
136
|
+
lines.push(this.convertPositionToPoints(positions2[i], positions2[i + 1]));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
for (var i = 0; i < positions1.length - 1; i++) {
|
|
140
|
+
var targetLinePoints = this.convertPositionToPoints(positions1[i], positions1[i + 1]);
|
|
141
|
+
|
|
142
|
+
if (this.findCrossPoint(lines, targetLinePoints)) {
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return false;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
PolygonCalculator.convertPositionToPoints = function (pos1, pos2) {
|
|
151
|
+
return new LinePoints(pos1.lng, pos1.lat, pos2.lng, pos2.lat);
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
PolygonCalculator.findCrossPoint = function (sr, tr) {
|
|
155
|
+
for (var _i = 0, sr_1 = sr; _i < sr_1.length; _i++) {
|
|
156
|
+
var tmp = sr_1[_i];
|
|
157
|
+
var p1 = (tmp.x1 - tmp.x2) * (tr.y1 - tr.y2) - (tmp.y1 - tmp.y2) * (tr.x1 - tr.x2);
|
|
158
|
+
|
|
159
|
+
if (p1 != 0) {
|
|
160
|
+
var x = ((tmp.x1 * tmp.y2 - tmp.y1 * tmp.x2) * (tr.x1 - tr.x2) - (tmp.x1 - tmp.x2) * (tr.x1 * tr.y2 - tr.y1 * tr.x2)) / p1;
|
|
161
|
+
var y = ((tmp.x1 * tmp.y2 - tmp.y1 * tmp.x2) * (tr.y1 - tr.y2) - (tmp.y1 - tmp.y2) * (tr.x1 * tr.y2 - tr.y1 * tr.x2)) / p1;
|
|
162
|
+
|
|
163
|
+
if ((x - tmp.x1) * (x - tmp.x2) <= 0 && (y - tmp.y1) * (y - tmp.y2) <= 0 && (x - tr.x1) * (x - tr.x2) <= 0 && (y - tr.y1) * (y - tr.y2) <= 0) {
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return false;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
return PolygonCalculator;
|
|
173
|
+
}();
|
|
174
|
+
|
|
175
|
+
var calculate.GeoCalulator = function () {
|
|
176
|
+
function GeoCalulator() {}
|
|
177
|
+
|
|
178
|
+
GeoCalulator.computeDistanceKiloMeter = function (pos1, pos2) {
|
|
179
|
+
var dLat = this.deg2rad(pos2.lat - pos1.lat);
|
|
180
|
+
var dLon = this.deg2rad(pos2.lng - pos1.lng);
|
|
181
|
+
var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(this.deg2rad(pos1.lat)) * Math.cos(this.deg2rad(pos2.lat)) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
|
|
182
|
+
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
183
|
+
var d = this.EARTH_RADIUS * c;
|
|
184
|
+
return d;
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
GeoCalulator.deg2rad = function (deg) {
|
|
188
|
+
return deg * (Math.PI / 180);
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
GeoCalulator.convertMeterToLatitudeValue = function (meter) {
|
|
192
|
+
return meter * this.LATITUDE_POSITION_VALUE_PER_METER;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
GeoCalulator.computeNextPositionAndDistances = function (context) {
|
|
196
|
+
var pos1 = context.pos1,
|
|
197
|
+
pos2 = context.pos2,
|
|
198
|
+
prevPos2 = context.prevPos2,
|
|
199
|
+
velocityKmh = context.velocityKmh,
|
|
200
|
+
prevVelocityKmh = context.prevVelocityKmh,
|
|
201
|
+
elapsedTimeMs = context.elapsedTimeMs;
|
|
202
|
+
|
|
203
|
+
if (pos2 !== prevPos2) {
|
|
204
|
+
context.totalDistance = this.computeDistanceKiloMeter(pos1, pos2);
|
|
205
|
+
context.currDistance = 0;
|
|
206
|
+
context.prevPos2 = pos2;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
var totalDistance = context.totalDistance;
|
|
210
|
+
|
|
211
|
+
if (velocityKmh !== prevVelocityKmh) {
|
|
212
|
+
context.vPerMs = velocityKmh / this.MS_FROM_HOUR;
|
|
213
|
+
context.prevVelocityKmh = velocityKmh;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
var vPerMs = context.vPerMs;
|
|
217
|
+
var nextDistance = context.distanceRemain ? context.distanceRemain : context.currDistance + elapsedTimeMs * vPerMs;
|
|
218
|
+
context.currDistance = nextDistance;
|
|
219
|
+
|
|
220
|
+
if (totalDistance < context.currDistance) {
|
|
221
|
+
context.distanceRemain = context.currDistance - totalDistance;
|
|
222
|
+
context.nextPos = pos2;
|
|
223
|
+
return context;
|
|
224
|
+
} else {
|
|
225
|
+
context.distanceRemain = 0;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
var ratio = nextDistance / totalDistance;
|
|
229
|
+
var latCalib = pos2.lat > pos1.lat ? 1 : -1;
|
|
230
|
+
var lngCalib = pos2.lng > pos1.lng ? 1 : -1;
|
|
231
|
+
var newPos = new MintMap.Position(pos1.lat + (pos2.lat - pos1.lat) * ratio, pos1.lng + (pos2.lng - pos1.lng) * ratio);
|
|
232
|
+
|
|
233
|
+
if ((latCalib === 1 && pos2.lat <= newPos.lat || latCalib === -1 && pos2.lat >= newPos.lat) && (lngCalib === 1 && pos2.lng <= newPos.lng || lngCalib === -1 && pos2.lng >= newPos.lng)) {
|
|
234
|
+
newPos = pos2;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
context.nextPos = newPos;
|
|
238
|
+
return context;
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
GeoCalulator.EARTH_RADIUS = 6371;
|
|
242
|
+
GeoCalulator.LATITUDE_POSITION_VALUE_PER_METER = 1 / (110 * 1000);
|
|
243
|
+
GeoCalulator.MS_FROM_HOUR = 60 * 60 * 1000;
|
|
244
|
+
return GeoCalulator;
|
|
245
|
+
}();
|
|
246
|
+
|
|
247
|
+
var MintMap.Position = function () {
|
|
248
|
+
function Position(lat, lng) {
|
|
249
|
+
this.lat = 0;
|
|
250
|
+
this.lng = 0;
|
|
251
|
+
this.lat = lat;
|
|
252
|
+
this.lng = lng;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return Position;
|
|
256
|
+
}();
|
|
257
|
+
|
|
258
|
+
var Drawable = function () {
|
|
259
|
+
function Drawable() {}
|
|
260
|
+
|
|
261
|
+
return Drawable;
|
|
262
|
+
}();
|
|
263
|
+
|
|
264
|
+
var MintMap.Marker = function (_super) {
|
|
265
|
+
__extends(Marker, _super);
|
|
266
|
+
|
|
267
|
+
function Marker(options) {
|
|
268
|
+
var _this = _super.call(this) || this;
|
|
269
|
+
|
|
270
|
+
_this.options = options;
|
|
271
|
+
return _this;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return Marker;
|
|
275
|
+
}(Drawable);
|
|
276
|
+
|
|
277
|
+
var MintMap.Polyline = function (_super) {
|
|
278
|
+
__extends(Polyline, _super);
|
|
279
|
+
|
|
280
|
+
function Polyline(options) {
|
|
281
|
+
var _this = _super.call(this) || this;
|
|
282
|
+
|
|
283
|
+
_this.options = options;
|
|
284
|
+
return _this;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return Polyline;
|
|
288
|
+
}(Drawable);
|
|
289
|
+
|
|
290
|
+
var MintMap.Polygon = function (_super) {
|
|
291
|
+
__extends(Polygon, _super);
|
|
292
|
+
|
|
293
|
+
function Polygon(options) {
|
|
294
|
+
var _this = _super.call(this) || this;
|
|
295
|
+
|
|
296
|
+
_this.options = options;
|
|
297
|
+
return _this;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
Polygon.prototype.getCenter = function () {
|
|
301
|
+
if (Array.isArray(this.options.position) && this.options.position.length > 0) {
|
|
302
|
+
var paths = this.options.position.map(function (elem) {
|
|
303
|
+
return elem instanceof MintMap.Position ? elem : new MintMap.Position(elem[0], elem[1]);
|
|
304
|
+
});
|
|
305
|
+
return PolygonCalculator.getCenter(paths);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
throw new Error('center 를 찾을 수 없습니다.');
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
return Polygon;
|
|
312
|
+
}(Drawable);
|
|
313
|
+
var cn$1 = classNames.bind(styles$2);
|
|
314
|
+
function MintMap(_a) {
|
|
315
|
+
var _this = this;
|
|
316
|
+
|
|
317
|
+
var mapType = _a.mapType,
|
|
318
|
+
children = _a.children,
|
|
319
|
+
props = __rest(_a, ["mapType", "children"]);
|
|
320
|
+
|
|
321
|
+
var _b = useState(),
|
|
322
|
+
controller = _b[0],
|
|
323
|
+
setController = _b[1];
|
|
324
|
+
|
|
325
|
+
useEffect(function () {
|
|
326
|
+
if (mapType && mapType.length > 0) {
|
|
327
|
+
setController(undefined);
|
|
328
|
+
|
|
329
|
+
(function () {
|
|
330
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
331
|
+
var moduleName, controllerModule, newController;
|
|
332
|
+
return __generator(this, function (_a) {
|
|
333
|
+
switch (_a.label) {
|
|
334
|
+
case 0:
|
|
335
|
+
moduleName = getMapModulePrefix(mapType);
|
|
336
|
+
return [4, import("./".concat(mapType, "/").concat(moduleName, "MintMapController"))];
|
|
337
|
+
|
|
338
|
+
case 1:
|
|
339
|
+
controllerModule = _a.sent();
|
|
340
|
+
newController = new controllerModule.default(__assign({
|
|
341
|
+
mapType: mapType
|
|
342
|
+
}, props));
|
|
343
|
+
newController.loadMapApi().then(function () {
|
|
344
|
+
setController(newController);
|
|
345
|
+
});
|
|
346
|
+
return [2];
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
})();
|
|
351
|
+
} else {
|
|
352
|
+
setController(undefined);
|
|
353
|
+
}
|
|
354
|
+
}, [mapType]);
|
|
355
|
+
return React.createElement(React.Fragment, null, controller ? React.createElement(MintMapProvider, {
|
|
356
|
+
controller: controller
|
|
357
|
+
}, React.createElement(MintMapCore, __assign({
|
|
358
|
+
mapType: mapType
|
|
359
|
+
}, props), children)) : React.createElement(PointLoading, {
|
|
360
|
+
text: "Loading"
|
|
361
|
+
}));
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function PointLoading(_a) {
|
|
365
|
+
var text = _a.text,
|
|
366
|
+
_b = _a.pointCount,
|
|
367
|
+
pointCount = _b === void 0 ? 4 : _b,
|
|
368
|
+
_c = _a.speedMs,
|
|
369
|
+
speedMs = _c === void 0 ? 200 : _c;
|
|
370
|
+
var pointStringPool = useState(Array.from(Array(pointCount)).map(function (_el, idx) {
|
|
371
|
+
return Array.from(Array(idx + 1)).map(function () {
|
|
372
|
+
return '.';
|
|
373
|
+
}).join('');
|
|
374
|
+
}))[0];
|
|
375
|
+
|
|
376
|
+
var _d = useState(''),
|
|
377
|
+
pointString = _d[0],
|
|
378
|
+
setPointString = _d[1];
|
|
379
|
+
|
|
380
|
+
useEffect(function () {
|
|
381
|
+
var pointStringIndex = 0;
|
|
382
|
+
var interval = setInterval(function () {
|
|
383
|
+
pointStringIndex += 1;
|
|
384
|
+
|
|
385
|
+
if (pointStringIndex >= pointCount) {
|
|
386
|
+
pointStringIndex = 0;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
setPointString(pointStringPool[pointStringIndex]);
|
|
390
|
+
}, speedMs);
|
|
391
|
+
return function () {
|
|
392
|
+
interval && clearInterval(interval);
|
|
393
|
+
};
|
|
394
|
+
}, []);
|
|
395
|
+
return React.createElement("div", {
|
|
396
|
+
className: cn$1('loading-point-container')
|
|
397
|
+
}, React.createElement("div", {
|
|
398
|
+
style: {
|
|
399
|
+
width: '300px',
|
|
400
|
+
fontSize: '16px',
|
|
401
|
+
fontWeight: 600,
|
|
402
|
+
color: 'gray',
|
|
403
|
+
transform: 'translateX(130px)'
|
|
404
|
+
}
|
|
405
|
+
}, "".concat(text, " ").concat(pointString)));
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
var getMapModulePrefix = function (mapType) {
|
|
409
|
+
return mapType.substring(0, 1).toUpperCase() + mapType.substring(1).toLowerCase();
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
var MintMapController = function () {
|
|
413
|
+
function MintMapController(props) {
|
|
414
|
+
this.mapApiLoaded = false;
|
|
415
|
+
this.mapInitialized = false;
|
|
416
|
+
this.mapProps = props;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
MintMapController.prototype.getMap = function () {
|
|
420
|
+
return this.map;
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
MintMapController.prototype.getMapType = function () {
|
|
424
|
+
return this.type;
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
MintMapController.prototype.loadScript = function (url, id) {
|
|
428
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
429
|
+
return __generator(this, function (_a) {
|
|
430
|
+
return [2, new Promise(function (resolve) {
|
|
431
|
+
if (id && document.getElementById(id)) {
|
|
432
|
+
console.log("already loaded script => ".concat(id));
|
|
433
|
+
resolve();
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
var script = document.createElement('script');
|
|
438
|
+
script.src = url;
|
|
439
|
+
script.async = true;
|
|
440
|
+
script.defer = true;
|
|
441
|
+
script.addEventListener('load', function () {
|
|
442
|
+
resolve();
|
|
443
|
+
});
|
|
444
|
+
document.body.appendChild(script);
|
|
445
|
+
})];
|
|
446
|
+
});
|
|
447
|
+
});
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
MintMapController.prototype.buildUrl = function (baseUrl, param) {
|
|
451
|
+
var params = Object.entries(param).map(function (_a) {
|
|
452
|
+
var key = _a[0],
|
|
453
|
+
value = _a[1];
|
|
454
|
+
var temp = encodeURIComponent(Array.isArray(value) ? value.join(',') : value);
|
|
455
|
+
return "".concat(key, "=").concat(temp);
|
|
456
|
+
}).join('&');
|
|
457
|
+
return "".concat(baseUrl, "?").concat(params);
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
return MintMapController;
|
|
461
|
+
}();
|
|
462
|
+
|
|
463
|
+
var css_248z = ".MintMapWrapper-module_mint-map-control-wrapper__DDb4y {\n position: absolute;\n z-index: 101;\n}\n\n.MintMapWrapper-module_mint-map-overlay-wrapper__Jn4wV {\n position: absolute;\n z-index: 1;\n}";
|
|
464
|
+
var styles = {"mint-map-control-wrapper":"MintMapWrapper-module_mint-map-control-wrapper__DDb4y","mint-map-overlay-wrapper":"MintMapWrapper-module_mint-map-overlay-wrapper__Jn4wV"};
|
|
465
|
+
styleInject(css_248z);
|
|
466
|
+
|
|
467
|
+
var cn = classNames.bind(styles);
|
|
468
|
+
|
|
469
|
+
var getSizeString = function (size) {
|
|
470
|
+
return typeof size === 'string' ? size.replace(/ /g, '') : "".concat(size, "px");
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
var getAlignPosition = function (value, align) {
|
|
474
|
+
if (typeof value === 'string') {
|
|
475
|
+
var trimmed = value.replace(/ /g, '');
|
|
476
|
+
console.log('trimmed:', trimmed);
|
|
477
|
+
var isPercent = trimmed.endsWith('%');
|
|
478
|
+
|
|
479
|
+
if (!isPercent && !trimmed.endsWith('px')) {
|
|
480
|
+
throw new Error("Size [".concat(value, "] is not valid string value."));
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
var numberPart = isPercent ? trimmed.substring(0, trimmed.length - 2) : trimmed.substring(0, trimmed.length - 3);
|
|
484
|
+
var unit = isPercent ? '%' : 'px';
|
|
485
|
+
var numberValue = Number(numberPart);
|
|
486
|
+
|
|
487
|
+
if (isNaN(numberValue)) {
|
|
488
|
+
throw new Error("Size [".concat(value, "] is not valid % or pixel number value."));
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
if (align === 'center') {
|
|
492
|
+
return "calc(50% - ".concat(numberValue / 2).concat(unit, ")");
|
|
493
|
+
} else if (align === 'right' || align === 'bottom') {
|
|
494
|
+
return "calc(100% - ".concat(numberValue).concat(unit, ")");
|
|
495
|
+
} else {
|
|
496
|
+
return '0px';
|
|
497
|
+
}
|
|
498
|
+
} else if (typeof value === 'number') {
|
|
499
|
+
if (align === 'center') {
|
|
500
|
+
return "calc(50% - ".concat(value / 2, "px)");
|
|
501
|
+
} else if (align === 'right' || align === 'bottom') {
|
|
502
|
+
return "calc(100% - ".concat(value, "px)");
|
|
503
|
+
} else {
|
|
504
|
+
return '0px';
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
throw new Error("Size [".concat(value, "] is not valid. (Should be % or pixel number)"));
|
|
509
|
+
};
|
|
510
|
+
|
|
511
|
+
function MapControlWrapper(_a) {
|
|
512
|
+
var _b = _a.width,
|
|
513
|
+
width = _b === void 0 ? 100 : _b,
|
|
514
|
+
_c = _a.height,
|
|
515
|
+
height = _c === void 0 ? 40 : _c,
|
|
516
|
+
_d = _a.positionHorizontal,
|
|
517
|
+
positionHorizontal = _d === void 0 ? 'left' : _d,
|
|
518
|
+
_e = _a.positionVertical,
|
|
519
|
+
positionVertical = _e === void 0 ? 'top' : _e,
|
|
520
|
+
children = _a.children;
|
|
521
|
+
return React.createElement("div", {
|
|
522
|
+
className: cn('mint-map-control-wrapper'),
|
|
523
|
+
style: {
|
|
524
|
+
width: getSizeString(width),
|
|
525
|
+
height: getSizeString(height),
|
|
526
|
+
left: getAlignPosition(width, positionHorizontal),
|
|
527
|
+
top: getAlignPosition(height, positionVertical)
|
|
528
|
+
}
|
|
529
|
+
}, children);
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
var AnimationPlayer = function () {
|
|
533
|
+
function AnimationPlayer(drawFunction, fps) {
|
|
534
|
+
this.prevtime = 0;
|
|
535
|
+
this.elapsedTime = 0;
|
|
536
|
+
this.fps = null;
|
|
537
|
+
this.baseDrawGapTime = null;
|
|
538
|
+
this.deltaTime = 0;
|
|
539
|
+
this.playing = false;
|
|
540
|
+
this.draw = drawFunction;
|
|
541
|
+
this.fps = fps || null;
|
|
542
|
+
|
|
543
|
+
if (fps !== undefined) {
|
|
544
|
+
this.baseDrawGapTime = 1000 / fps;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
this.init();
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
AnimationPlayer.prototype.init = function () {
|
|
551
|
+
this.deltaTime = 0;
|
|
552
|
+
this.prevtime = 0;
|
|
553
|
+
this.elapsedTime = 0;
|
|
554
|
+
this.playing = false;
|
|
555
|
+
};
|
|
556
|
+
|
|
557
|
+
AnimationPlayer.prototype.start = function () {
|
|
558
|
+
this.init();
|
|
559
|
+
this.resume();
|
|
560
|
+
};
|
|
561
|
+
|
|
562
|
+
AnimationPlayer.prototype.stop = function () {
|
|
563
|
+
this.playing = false;
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
AnimationPlayer.prototype.resume = function () {
|
|
567
|
+
this.playing = true;
|
|
568
|
+
window.requestAnimationFrame(this.makeFrame.bind(this));
|
|
569
|
+
};
|
|
570
|
+
|
|
571
|
+
AnimationPlayer.prototype.makeFrame = function (timestamp) {
|
|
572
|
+
if (this.prevtime === 0) {
|
|
573
|
+
this.prevtime = timestamp;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
this.deltaTime += timestamp - this.prevtime;
|
|
577
|
+
this.prevtime = timestamp;
|
|
578
|
+
|
|
579
|
+
if (!this.baseDrawGapTime || this.baseDrawGapTime <= this.deltaTime) {
|
|
580
|
+
this.elapsedTime += this.deltaTime;
|
|
581
|
+
var stopFlag = this.draw(this.deltaTime, this.elapsedTime);
|
|
582
|
+
this.deltaTime = 0;
|
|
583
|
+
|
|
584
|
+
if (stopFlag) {
|
|
585
|
+
this.stop();
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
if (this.playing) {
|
|
590
|
+
window.requestAnimationFrame(this.makeFrame.bind(this));
|
|
591
|
+
}
|
|
592
|
+
};
|
|
593
|
+
|
|
594
|
+
return AnimationPlayer;
|
|
595
|
+
}();
|
|
596
|
+
|
|
597
|
+
function nextIndex(array, currIdx) {
|
|
598
|
+
var next = currIdx + 1;
|
|
599
|
+
|
|
600
|
+
if (next > array.length - 1) {
|
|
601
|
+
next = 0;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
return next;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
function useMarkerMoving(_a) {
|
|
608
|
+
var _b = _a.marker,
|
|
609
|
+
marker = _b === void 0 ? undefined : _b,
|
|
610
|
+
_c = _a.positions,
|
|
611
|
+
positions = _c === void 0 ? [] : _c,
|
|
612
|
+
_d = _a.positionClosed,
|
|
613
|
+
positionClosed = _d === void 0 ? false : _d,
|
|
614
|
+
_e = _a.loop,
|
|
615
|
+
loop = _e === void 0 ? false : _e,
|
|
616
|
+
_f = _a.fps,
|
|
617
|
+
fps = _f === void 0 ? 1 : _f,
|
|
618
|
+
_g = _a.startPositionIndex,
|
|
619
|
+
startPositionIndex = _g === void 0 ? 0 : _g,
|
|
620
|
+
_h = _a.velocity,
|
|
621
|
+
velocity = _h === void 0 ? 10 : _h,
|
|
622
|
+
onMovingStart = _a.onMovingStart,
|
|
623
|
+
onMovingEnd = _a.onMovingEnd;
|
|
624
|
+
var controller = MintMapProvider.useMintMapController();
|
|
625
|
+
useEffect(function () {
|
|
626
|
+
contextRef.current && (contextRef.current.velocityKmh = velocity);
|
|
627
|
+
}, [velocity]);
|
|
628
|
+
var contextRef = useRef();
|
|
629
|
+
useEffect(function () {
|
|
630
|
+
if (marker) {
|
|
631
|
+
var currTargetIndex_1 = nextIndex(positions, startPositionIndex);
|
|
632
|
+
var stopNext_1 = false;
|
|
633
|
+
var loopCount_1 = 0;
|
|
634
|
+
var context_1 = contextRef.current = {
|
|
635
|
+
pos1: positions[startPositionIndex],
|
|
636
|
+
pos2: positions[currTargetIndex_1],
|
|
637
|
+
velocityKmh: velocity
|
|
638
|
+
};
|
|
639
|
+
var nextOption_1 = {
|
|
640
|
+
position: context_1.nextPos,
|
|
641
|
+
anchor: marker.options.anchor
|
|
642
|
+
};
|
|
643
|
+
|
|
644
|
+
var draw = function (frameGapTime, _elapsedTime) {
|
|
645
|
+
if (!marker) {
|
|
646
|
+
console.log('myMarker is not exist!!!');
|
|
647
|
+
return true;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
context_1.elapsedTimeMs = frameGapTime;
|
|
651
|
+
|
|
652
|
+
while (true) {
|
|
653
|
+
calculate.GeoCalulator.computeNextPositionAndDistances(context_1);
|
|
654
|
+
|
|
655
|
+
if (context_1.nextPos === context_1.pos2) {
|
|
656
|
+
if (currTargetIndex_1 === startPositionIndex) {
|
|
657
|
+
loopCount_1 += 1;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
if (!loop && loopCount_1 > 0) {
|
|
661
|
+
stopNext_1 = true;
|
|
662
|
+
break;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
context_1.pos1 = positions[currTargetIndex_1];
|
|
666
|
+
currTargetIndex_1 = nextIndex(positions, currTargetIndex_1);
|
|
667
|
+
|
|
668
|
+
if (currTargetIndex_1 === 0 && !positionClosed) {
|
|
669
|
+
context_1.pos1 = positions[currTargetIndex_1];
|
|
670
|
+
currTargetIndex_1 = nextIndex(positions, currTargetIndex_1);
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
context_1.pos2 = positions[currTargetIndex_1];
|
|
674
|
+
} else {
|
|
675
|
+
break;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
nextOption_1.position = context_1.nextPos;
|
|
680
|
+
marker.options.position = nextOption_1.position;
|
|
681
|
+
controller.updateMarker(marker, nextOption_1);
|
|
682
|
+
|
|
683
|
+
if (stopNext_1) {
|
|
684
|
+
onMovingEnd && onMovingEnd();
|
|
685
|
+
return true;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
return false;
|
|
689
|
+
};
|
|
690
|
+
|
|
691
|
+
player.current = new AnimationPlayer(draw, fps);
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
return function () {
|
|
695
|
+
player.current && player.current.stop();
|
|
696
|
+
};
|
|
697
|
+
}, [marker]);
|
|
698
|
+
var player = useRef();
|
|
699
|
+
|
|
700
|
+
var _j = useState('stop'),
|
|
701
|
+
playbackStatus = _j[0],
|
|
702
|
+
setPlaybackStatus = _j[1];
|
|
703
|
+
|
|
704
|
+
useEffect(function () {
|
|
705
|
+
var _a, _b, _c;
|
|
706
|
+
|
|
707
|
+
if (playbackStatus === 'start') {
|
|
708
|
+
(_a = player === null || player === void 0 ? void 0 : player.current) === null || _a === void 0 ? void 0 : _a.start();
|
|
709
|
+
onMovingStart && onMovingStart();
|
|
710
|
+
} else if (playbackStatus === 'resume') {
|
|
711
|
+
(_b = player === null || player === void 0 ? void 0 : player.current) === null || _b === void 0 ? void 0 : _b.resume();
|
|
712
|
+
} else if (playbackStatus === 'stop') {
|
|
713
|
+
(_c = player === null || player === void 0 ? void 0 : player.current) === null || _c === void 0 ? void 0 : _c.stop();
|
|
714
|
+
}
|
|
715
|
+
}, [playbackStatus]);
|
|
716
|
+
|
|
717
|
+
var start = function () {
|
|
718
|
+
setPlaybackStatus('start');
|
|
719
|
+
};
|
|
720
|
+
|
|
721
|
+
var stop = function () {
|
|
722
|
+
setPlaybackStatus('stop');
|
|
723
|
+
};
|
|
724
|
+
|
|
725
|
+
var resume = function () {
|
|
726
|
+
setPlaybackStatus('resume');
|
|
727
|
+
};
|
|
728
|
+
|
|
729
|
+
return [start, stop, resume];
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
var offsetCalibration = function (mapType, divElement, options) {
|
|
733
|
+
if (mapType === 'google') {
|
|
734
|
+
divElement.style.transform = "translate(50%, 100%) translate(-".concat(options.anchor ? options.anchor.x : '0', "px, -").concat(options.anchor ? options.anchor.y : '0', "px)");
|
|
735
|
+
}
|
|
736
|
+
};
|
|
737
|
+
|
|
738
|
+
function MapMarkerWrapper(_a) {
|
|
739
|
+
var startAnimationClassName = _a.startAnimationClassName,
|
|
740
|
+
endAnimationClassName = _a.endAnimationClassName,
|
|
741
|
+
_b = _a.topOnClick,
|
|
742
|
+
topOnClick = _b === void 0 ? false : _b,
|
|
743
|
+
_c = _a.topOnHover,
|
|
744
|
+
topOnHover = _c === void 0 ? false : _c,
|
|
745
|
+
movingAnimation = _a.movingAnimation,
|
|
746
|
+
children = _a.children,
|
|
747
|
+
options = __rest(_a, ["startAnimationClassName", "endAnimationClassName", "topOnClick", "topOnHover", "movingAnimation", "children"]);
|
|
748
|
+
|
|
749
|
+
var controller = MintMapProvider.useMintMapController();
|
|
750
|
+
var divRef = useRef(document.createElement('div'));
|
|
751
|
+
var divElement = divRef.current;
|
|
752
|
+
var divCloneRef = useRef();
|
|
753
|
+
var markerRef = useRef();
|
|
754
|
+
|
|
755
|
+
var _d = useState({}),
|
|
756
|
+
movingState = _d[0],
|
|
757
|
+
setMovingState = _d[1];
|
|
758
|
+
|
|
759
|
+
useEffect(function () {
|
|
760
|
+
if (movingState.autoStart) {
|
|
761
|
+
setTimeout(function () {
|
|
762
|
+
start();
|
|
763
|
+
}, movingState.delay);
|
|
764
|
+
}
|
|
765
|
+
}, [movingState]);
|
|
766
|
+
useEffect(function () {
|
|
767
|
+
setMovingState(__assign(__assign({}, movingAnimation), {
|
|
768
|
+
marker: markerRef.current
|
|
769
|
+
}));
|
|
770
|
+
}, [movingAnimation]);
|
|
771
|
+
var start = useMarkerMoving(movingState)[0];
|
|
772
|
+
|
|
773
|
+
var onClickHandler = function (e) {
|
|
774
|
+
var _a;
|
|
775
|
+
|
|
776
|
+
var marker = markerRef.current;
|
|
777
|
+
|
|
778
|
+
if (marker) {
|
|
779
|
+
controller.setMapDragged(false);
|
|
780
|
+
var clickHandler = (_a = options === null || options === void 0 ? void 0 : options.event) === null || _a === void 0 ? void 0 : _a.get('click');
|
|
781
|
+
var next = true;
|
|
782
|
+
|
|
783
|
+
if (clickHandler) {
|
|
784
|
+
var hasNext = clickHandler(e);
|
|
785
|
+
hasNext !== undefined && (next = hasNext);
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
next && !topOnHover && topOnClick && controller.markerToTheTop(marker);
|
|
789
|
+
}
|
|
790
|
+
};
|
|
791
|
+
|
|
792
|
+
var onMouseOverHandler = function (e) {
|
|
793
|
+
var _a;
|
|
794
|
+
|
|
795
|
+
var marker = markerRef.current;
|
|
796
|
+
|
|
797
|
+
if (marker) {
|
|
798
|
+
var mouseOverHandler = (_a = options === null || options === void 0 ? void 0 : options.event) === null || _a === void 0 ? void 0 : _a.get('mouseover');
|
|
799
|
+
var next = true;
|
|
800
|
+
|
|
801
|
+
if (mouseOverHandler) {
|
|
802
|
+
var hasNext = mouseOverHandler(e);
|
|
803
|
+
hasNext !== undefined && (next = hasNext);
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
next && topOnHover && controller.markerToTheTop(marker);
|
|
807
|
+
}
|
|
808
|
+
};
|
|
809
|
+
|
|
810
|
+
useEffect(function () {
|
|
811
|
+
divElement.addEventListener('click', onClickHandler);
|
|
812
|
+
divElement.addEventListener('mouseover', onMouseOverHandler);
|
|
813
|
+
return function () {
|
|
814
|
+
if (divCloneRef.current && endAnimationClassName) {
|
|
815
|
+
divCloneRef.current.classList.add(endAnimationClassName);
|
|
816
|
+
|
|
817
|
+
var aniListener_1 = function () {
|
|
818
|
+
divCloneRef.current && divCloneRef.current.removeEventListener('animationend', aniListener_1);
|
|
819
|
+
|
|
820
|
+
if (markerRef.current) {
|
|
821
|
+
console.log('drawable cleared', controller.clearDrawable(markerRef.current));
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
divCloneRef.current = undefined;
|
|
825
|
+
};
|
|
826
|
+
|
|
827
|
+
divCloneRef.current.addEventListener('animationend', aniListener_1);
|
|
828
|
+
divElement.append(divCloneRef.current);
|
|
829
|
+
} else {
|
|
830
|
+
divElement.removeEventListener('click', onClickHandler);
|
|
831
|
+
divElement.removeEventListener('mouseover', onMouseOverHandler);
|
|
832
|
+
|
|
833
|
+
if (markerRef.current) {
|
|
834
|
+
console.log('drawable cleared', controller.clearDrawable(markerRef.current));
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
};
|
|
838
|
+
}, []);
|
|
839
|
+
useEffect(function () {
|
|
840
|
+
if (options) {
|
|
841
|
+
if (markerRef.current) {
|
|
842
|
+
controller.updateMarker(markerRef.current, options);
|
|
843
|
+
offsetCalibration(controller.getMapType(), divElement, options);
|
|
844
|
+
} else {
|
|
845
|
+
markerRef.current = new MintMap.Marker(options);
|
|
846
|
+
markerRef.current.element = divElement;
|
|
847
|
+
controller.createMarker(markerRef.current);
|
|
848
|
+
offsetCalibration(controller.getMapType(), divElement, options);
|
|
849
|
+
|
|
850
|
+
if (movingAnimation) {
|
|
851
|
+
setMovingState(__assign(__assign({}, movingAnimation), {
|
|
852
|
+
marker: markerRef.current
|
|
853
|
+
}));
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
if (startAnimationClassName) {
|
|
857
|
+
divElement.style.visibility = 'hidden';
|
|
858
|
+
setTimeout(function () {
|
|
859
|
+
var _a, _b;
|
|
860
|
+
|
|
861
|
+
divCloneRef.current = divElement.firstElementChild;
|
|
862
|
+
divElement.style.visibility = 'visible';
|
|
863
|
+
(_a = divElement.firstElementChild) === null || _a === void 0 ? void 0 : _a.classList.add(startAnimationClassName);
|
|
864
|
+
|
|
865
|
+
var aniListener = function () {
|
|
866
|
+
var _a, _b;
|
|
867
|
+
|
|
868
|
+
(_a = divElement.firstElementChild) === null || _a === void 0 ? void 0 : _a.classList.remove(startAnimationClassName);
|
|
869
|
+
(_b = divElement.firstElementChild) === null || _b === void 0 ? void 0 : _b.removeEventListener('animationend', aniListener);
|
|
870
|
+
};
|
|
871
|
+
|
|
872
|
+
(_b = divElement.firstElementChild) === null || _b === void 0 ? void 0 : _b.addEventListener('animationend', aniListener);
|
|
873
|
+
});
|
|
874
|
+
} else {
|
|
875
|
+
setTimeout(function () {
|
|
876
|
+
divCloneRef.current = divElement.firstElementChild;
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
}, [options]);
|
|
882
|
+
return createPortal(children, divElement);
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
function MapPolygonWrapper(_a) {
|
|
886
|
+
var children = _a.children,
|
|
887
|
+
options = __rest(_a, ["children"]);
|
|
888
|
+
|
|
889
|
+
var controller = MintMapProvider.useMintMapController();
|
|
890
|
+
useEffect(function () {
|
|
891
|
+
return function () {
|
|
892
|
+
if (polygonRef.current) {
|
|
893
|
+
console.log('polygon cleared', controller.clearDrawable(polygonRef.current));
|
|
894
|
+
}
|
|
895
|
+
};
|
|
896
|
+
}, []);
|
|
897
|
+
var polygonRef = useRef();
|
|
898
|
+
useEffect(function () {
|
|
899
|
+
if (options) {
|
|
900
|
+
if (polygonRef.current) {
|
|
901
|
+
controller.updatePolygon(polygonRef.current, options);
|
|
902
|
+
} else {
|
|
903
|
+
var polygon = new MintMap.Polygon(options);
|
|
904
|
+
polygonRef.current = polygon;
|
|
905
|
+
controller.createPolygon(polygon);
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
}, [options]);
|
|
909
|
+
return React.createElement(React.Fragment, null, options && children);
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
function MapPolylineWrapper(_a) {
|
|
913
|
+
var children = _a.children,
|
|
914
|
+
options = __rest(_a, ["children"]);
|
|
915
|
+
|
|
916
|
+
var controller = MintMapProvider.useMintMapController();
|
|
917
|
+
useEffect(function () {
|
|
918
|
+
return function () {
|
|
919
|
+
if (polylineRef.current) {
|
|
920
|
+
console.log('polyline cleared', controller.clearDrawable(polylineRef.current));
|
|
921
|
+
}
|
|
922
|
+
};
|
|
923
|
+
}, []);
|
|
924
|
+
var polylineRef = useRef();
|
|
925
|
+
useEffect(function () {
|
|
926
|
+
if (options) {
|
|
927
|
+
if (polylineRef.current) {
|
|
928
|
+
controller.updatePolyline(polylineRef.current, options);
|
|
929
|
+
} else {
|
|
930
|
+
var polyline = new MintMap.Polyline(options);
|
|
931
|
+
polylineRef.current = polyline;
|
|
932
|
+
controller.createPolyline(polyline);
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
}, [options]);
|
|
936
|
+
return React.createElement(React.Fragment, null, options && children);
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
function getMaxLat(items) {
|
|
940
|
+
var max;
|
|
941
|
+
|
|
942
|
+
for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
|
|
943
|
+
var item = items_1[_i];
|
|
944
|
+
|
|
945
|
+
if (!max || max.lat < item.lat) {
|
|
946
|
+
max = item;
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
return max;
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
function getLngMinMaxPos(items, maxFlag) {
|
|
954
|
+
var data = __spreadArray([], items, true);
|
|
955
|
+
|
|
956
|
+
data.sort(function (a, b) {
|
|
957
|
+
var maxA = getLngMinMax(a.position, maxFlag);
|
|
958
|
+
var maxB = getLngMinMax(b.position, maxFlag);
|
|
959
|
+
return maxA.lat < maxB.lat ? maxFlag ? 1 : -1 : maxFlag ? -1 : 1;
|
|
960
|
+
});
|
|
961
|
+
return data[0];
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
function getLngMinMax(items, maxFlag) {
|
|
965
|
+
var val;
|
|
966
|
+
|
|
967
|
+
for (var _i = 0, items_2 = items; _i < items_2.length; _i++) {
|
|
968
|
+
var item = items_2[_i];
|
|
969
|
+
|
|
970
|
+
if (!val || maxFlag && val.lat < item.lat || !maxFlag && val.lat > item.lat) {
|
|
971
|
+
val = item;
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
return val;
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
function MapBuildingProjection(props) {
|
|
979
|
+
var basePolygonPath = props.basePolygonPath,
|
|
980
|
+
numberOfFloor = props.numberOfFloor,
|
|
981
|
+
_a = props.heightOfFloor,
|
|
982
|
+
heightOfFloor = _a === void 0 ? 4 : _a,
|
|
983
|
+
_b = props.lineColor,
|
|
984
|
+
lineColor = _b === void 0 ? 'blue' : _b,
|
|
985
|
+
_c = props.lineOpacity,
|
|
986
|
+
lineOpacity = _c === void 0 ? 1 : _c,
|
|
987
|
+
_d = props.fillColor,
|
|
988
|
+
fillColor = _d === void 0 ? 'lightblue' : _d,
|
|
989
|
+
_e = props.fillOpacity,
|
|
990
|
+
fillOpacity = _e === void 0 ? 1 : _e,
|
|
991
|
+
_f = props.title,
|
|
992
|
+
title = _f === void 0 ? '빌딩11' : _f,
|
|
993
|
+
titleElement = props.titleElement;
|
|
994
|
+
|
|
995
|
+
var _g = useState(),
|
|
996
|
+
basePolygon = _g[0],
|
|
997
|
+
setBasePolygon = _g[1];
|
|
998
|
+
|
|
999
|
+
var roofPolygon = useRef();
|
|
1000
|
+
var wallPolygons = useRef();
|
|
1001
|
+
var titlePosition = useRef();
|
|
1002
|
+
useEffect(function () {
|
|
1003
|
+
var base = {
|
|
1004
|
+
position: basePolygonPath
|
|
1005
|
+
};
|
|
1006
|
+
var height = numberOfFloor * heightOfFloor;
|
|
1007
|
+
var projectionHeight = calculate.GeoCalulator.convertMeterToLatitudeValue(height);
|
|
1008
|
+
var roofPaths = [];
|
|
1009
|
+
|
|
1010
|
+
for (var _i = 0, basePolygonPath_1 = basePolygonPath; _i < basePolygonPath_1.length; _i++) {
|
|
1011
|
+
var pos = basePolygonPath_1[_i];
|
|
1012
|
+
roofPaths.push(new MintMap.Position(pos.lat + projectionHeight, pos.lng));
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
roofPolygon.current = {
|
|
1016
|
+
position: roofPaths
|
|
1017
|
+
};
|
|
1018
|
+
wallPolygons.current = [];
|
|
1019
|
+
|
|
1020
|
+
for (var i = 0; i < basePolygonPath.length; i++) {
|
|
1021
|
+
var start = basePolygonPath[i];
|
|
1022
|
+
var startNext = basePolygonPath[i + 1] || basePolygonPath[0];
|
|
1023
|
+
var end = roofPaths[i];
|
|
1024
|
+
var endNext = roofPaths[i + 1] || roofPaths[0];
|
|
1025
|
+
wallPolygons.current.push({
|
|
1026
|
+
position: [start, startNext, endNext, end]
|
|
1027
|
+
});
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
wallPolygons.current.sort(function (a, b) {
|
|
1031
|
+
var maxA = getMaxLat(a.position);
|
|
1032
|
+
var maxB = getMaxLat(b.position);
|
|
1033
|
+
return maxA.lat < maxB.lat ? 1 : -1;
|
|
1034
|
+
});
|
|
1035
|
+
|
|
1036
|
+
if (title || titleElement) {
|
|
1037
|
+
var maxPos = getMaxLat(wallPolygons.current[0].position);
|
|
1038
|
+
var maxLngPos = getLngMinMaxPos(wallPolygons.current, true);
|
|
1039
|
+
var minLngPos = getLngMinMaxPos(wallPolygons.current, false);
|
|
1040
|
+
var maxLng = getLngMinMax(maxLngPos.position, true);
|
|
1041
|
+
var minLng = getLngMinMax(minLngPos.position, false);
|
|
1042
|
+
var mid = minLng.lng + (maxLng.lng - minLng.lng) / 2;
|
|
1043
|
+
titlePosition.current = {
|
|
1044
|
+
position: new MintMap.Position(maxPos.lat, mid)
|
|
1045
|
+
};
|
|
1046
|
+
} else {
|
|
1047
|
+
titlePosition.current = undefined;
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
setBasePolygon(base);
|
|
1051
|
+
}, [props]);
|
|
1052
|
+
return React.createElement(React.Fragment, null, basePolygon && React.createElement(MapPolygonWrapper, __assign({}, basePolygon, {
|
|
1053
|
+
lineColor: lineColor,
|
|
1054
|
+
lineOpacity: lineOpacity,
|
|
1055
|
+
fillColor: fillColor,
|
|
1056
|
+
fillOpacity: fillOpacity
|
|
1057
|
+
})), wallPolygons.current && wallPolygons.current.map(function (poly, idx) {
|
|
1058
|
+
return React.createElement(MapPolygonWrapper, __assign({
|
|
1059
|
+
key: "walls-".concat(idx)
|
|
1060
|
+
}, poly, {
|
|
1061
|
+
lineColor: lineColor,
|
|
1062
|
+
lineOpacity: lineOpacity,
|
|
1063
|
+
fillColor: fillColor,
|
|
1064
|
+
fillOpacity: fillOpacity
|
|
1065
|
+
}));
|
|
1066
|
+
}), roofPolygon.current && React.createElement(MapPolygonWrapper, __assign({}, roofPolygon.current, {
|
|
1067
|
+
lineColor: lineColor,
|
|
1068
|
+
lineOpacity: lineOpacity,
|
|
1069
|
+
fillColor: fillColor,
|
|
1070
|
+
fillOpacity: fillOpacity
|
|
1071
|
+
})), titlePosition.current && React.createElement(MapMarkerWrapper, __assign({}, titlePosition.current), titleElement ? titleElement : React.createElement("div", {
|
|
1072
|
+
style: {
|
|
1073
|
+
width: '150px',
|
|
1074
|
+
height: '30px',
|
|
1075
|
+
display: 'flex',
|
|
1076
|
+
alignItems: 'center',
|
|
1077
|
+
justifyContent: 'center',
|
|
1078
|
+
position: 'absolute',
|
|
1079
|
+
left: 'calc(50% - 75px)',
|
|
1080
|
+
top: '-35px'
|
|
1081
|
+
}
|
|
1082
|
+
}, React.createElement("div", {
|
|
1083
|
+
style: {
|
|
1084
|
+
maxWidth: '150px',
|
|
1085
|
+
border: '1px solid gray',
|
|
1086
|
+
borderRadius: '5px',
|
|
1087
|
+
padding: '2px 5px',
|
|
1088
|
+
background: 'white',
|
|
1089
|
+
fontSize: '12px',
|
|
1090
|
+
fontWeight: 600,
|
|
1091
|
+
color: '#006fd1'
|
|
1092
|
+
}
|
|
1093
|
+
}, "".concat(title, " (").concat(numberOfFloor, "\uCE35)")))));
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
export { MapBuildingProjection, MapControlWrapper, MapMarkerWrapper, MapPolygonWrapper, MapPolylineWrapper, MintMap, MintMapController, MintMapProvider };
|