@mint-ui/map 0.5.3-beta → 0.5.5-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/dist/components/mint-map/core/advanced/MapBuildingProjection.js +2 -2
- package/dist/components/mint-map/core/advanced/shapes/CircleMarker.js +3 -2
- package/dist/components/mint-map/core/advanced/shapes/PolygonMarker.js +36 -46
- package/dist/components/mint-map/core/advanced/shapes/base/SVGPolygon.js +5 -5
- package/dist/components/mint-map/core/hooks/MarkerMovingHook.js +2 -2
- package/dist/components/mint-map/core/util/{calculate.d.ts → geo.d.ts} +0 -28
- package/dist/components/mint-map/core/util/geo.js +159 -0
- package/dist/components/mint-map/core/util/index.d.ts +2 -1
- package/dist/components/mint-map/core/util/polygon.d.ts +40 -0
- package/dist/components/mint-map/core/util/{calculate.js → polygon.js} +13 -159
- package/dist/components/mint-map/core/wrapper/MapCanvasWrapper.js +2 -2
- package/dist/components/mint-map/google/GoogleMintMapController.js +1 -1
- package/dist/components/mint-map/kakao/KakaoMintMapController.js +1 -1
- package/dist/components/mint-map/naver/NaverMintMapController.d.ts +2 -1
- package/dist/components/mint-map/naver/NaverMintMapController.js +10 -1
- package/dist/components/mint-map/types/MapDrawables.js +2 -2
- package/dist/components/mint-map/types/MapTypes.js +2 -2
- package/dist/index.es.js +215 -211
- package/dist/index.js +4 -3
- package/dist/index.umd.js +215 -211
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var tslib = require('tslib');
|
|
6
6
|
var React = require('react');
|
|
7
7
|
var MapTypes = require('../../types/MapTypes.js');
|
|
8
|
-
var
|
|
8
|
+
var geo = require('../util/geo.js');
|
|
9
9
|
var MapMarkerWrapper = require('../wrapper/MapMarkerWrapper.js');
|
|
10
10
|
var MapPolygonWrapper = require('../wrapper/MapPolygonWrapper.js');
|
|
11
11
|
|
|
@@ -82,7 +82,7 @@ function MapBuildingProjection(props) {
|
|
|
82
82
|
position: basePolygonPath
|
|
83
83
|
};
|
|
84
84
|
var height = numberOfFloor * heightOfFloor;
|
|
85
|
-
var projectionHeight =
|
|
85
|
+
var projectionHeight = geo.GeoCalulator.convertMeterToLatitudeValue(height); //roof
|
|
86
86
|
|
|
87
87
|
var roofPaths = [];
|
|
88
88
|
|
|
@@ -11,7 +11,8 @@ var MapTypes = require('../../../types/MapTypes.js');
|
|
|
11
11
|
require('../../../types/MapEventTypes.js');
|
|
12
12
|
var SVGCircle = require('./base/SVGCircle.js');
|
|
13
13
|
require('../../util/animation.js');
|
|
14
|
-
var
|
|
14
|
+
var geo = require('../../util/geo.js');
|
|
15
|
+
require('../../util/polygon.js');
|
|
15
16
|
|
|
16
17
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
17
18
|
|
|
@@ -103,7 +104,7 @@ function CircleMarker(_a) {
|
|
|
103
104
|
radiusUnit = _a.radiusUnit;
|
|
104
105
|
|
|
105
106
|
if (radiusUnit === 'METER') {
|
|
106
|
-
var latMargin =
|
|
107
|
+
var latMargin = geo.GeoCalulator.convertMeterToLatitudeValue(radius);
|
|
107
108
|
var targetPos = new MapTypes.Position(center.lat + latMargin, center.lng);
|
|
108
109
|
var tempComputedRadius = calcRadius(center, targetPos);
|
|
109
110
|
setComputedRadius(tempComputedRadius);
|
|
@@ -10,8 +10,10 @@ require('../../../types/MapDrawables.js');
|
|
|
10
10
|
var MapTypes = require('../../../types/MapTypes.js');
|
|
11
11
|
require('../../../types/MapEventTypes.js');
|
|
12
12
|
require('../../util/animation.js');
|
|
13
|
-
|
|
13
|
+
require('../../util/geo.js');
|
|
14
14
|
require('tslib');
|
|
15
|
+
var polygon = require('../../util/polygon.js');
|
|
16
|
+
var NaverMintMapController = require('../../../naver/NaverMintMapController.js');
|
|
15
17
|
|
|
16
18
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
17
19
|
|
|
@@ -85,11 +87,9 @@ function PolygonMarker(_a) {
|
|
|
85
87
|
|
|
86
88
|
var _l = React.useState([]),
|
|
87
89
|
innerOffsets = _l[0],
|
|
88
|
-
setInnerOffsets = _l[1]; //
|
|
90
|
+
setInnerOffsets = _l[1]; //polygon props ref
|
|
89
91
|
|
|
90
92
|
|
|
91
|
-
var offsetCache = React.useRef(new Map()); //polygon props ref
|
|
92
|
-
|
|
93
93
|
var polygonPropsRef = React.useRef({
|
|
94
94
|
position: position,
|
|
95
95
|
innerPositions: innerPositions,
|
|
@@ -100,7 +100,6 @@ function PolygonMarker(_a) {
|
|
|
100
100
|
|
|
101
101
|
React.useEffect(function () {
|
|
102
102
|
// console.log('polygon changed');
|
|
103
|
-
offsetCache.current.clear();
|
|
104
103
|
polygonPropsRef.current = {
|
|
105
104
|
position: position,
|
|
106
105
|
innerPositions: innerPositions,
|
|
@@ -122,53 +121,44 @@ function PolygonMarker(_a) {
|
|
|
122
121
|
innerPositions = _a.innerPositions,
|
|
123
122
|
simplifyPath = _a.simplifyPath,
|
|
124
123
|
simplifyTolerance = _a.simplifyTolerance,
|
|
125
|
-
lastReapeated = _a.lastReapeated;
|
|
126
|
-
var prevCache = offsetCache.current.get(zoomLevel.current);
|
|
127
|
-
|
|
128
|
-
if (prevCache) {
|
|
129
|
-
var offsets_1 = [];
|
|
130
|
-
offsets_1.push.apply(offsets_1, prevCache.offsets);
|
|
131
|
-
setOffsets(offsets_1);
|
|
132
|
-
var innerOffsets_1 = [];
|
|
133
|
-
innerOffsets_1.push.apply(innerOffsets_1, prevCache.innerOffsets);
|
|
134
|
-
setInnerOffsets(innerOffsets_1);
|
|
135
|
-
setPolygonStart(prevCache.start);
|
|
136
|
-
} else {
|
|
137
|
-
// path
|
|
138
|
-
var simplified = simplifyPath ? calculate.PolygonCalculator.simplifyPoints(position, simplifyTolerance, lastReapeated) : position;
|
|
139
|
-
var offsets_2 = simplified.map(function (pos) {
|
|
140
|
-
var off = controller.positionToOffset(pos);
|
|
141
|
-
return new MapTypes.Offset(Math.floor(off.x), Math.floor(off.y));
|
|
142
|
-
});
|
|
143
|
-
setOffsets(offsets_2); //inner path
|
|
124
|
+
lastReapeated = _a.lastReapeated; // path
|
|
144
125
|
|
|
145
|
-
|
|
126
|
+
var maxLat = undefined;
|
|
127
|
+
var minLng = undefined;
|
|
128
|
+
var offsets = position.map(function (pos) {
|
|
129
|
+
if (maxLat === undefined || maxLat < pos.lat) {
|
|
130
|
+
maxLat = pos.lat;
|
|
131
|
+
}
|
|
146
132
|
|
|
147
|
-
if (
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
var simplified_1 = simplifyPath ? calculate.PolygonCalculator.simplifyPoints(innerPosition, simplifyTolerance, lastReapeated) : innerPosition;
|
|
151
|
-
var offsets_3 = simplified_1.map(function (pos) {
|
|
152
|
-
var off = controller.positionToOffset(pos);
|
|
153
|
-
return new MapTypes.Offset(Math.floor(off.x), Math.floor(off.y));
|
|
154
|
-
});
|
|
155
|
-
innerPath.push(offsets_3);
|
|
156
|
-
}
|
|
133
|
+
if (minLng === undefined || minLng > pos.lng) {
|
|
134
|
+
minLng = pos.lng;
|
|
135
|
+
} //offset 계산 정확도를 위해 네이버 맵은 전용 projection 베이스의 function 을 사용한다.
|
|
157
136
|
|
|
158
|
-
setInnerOffsets(innerPath);
|
|
159
|
-
} //start point
|
|
160
137
|
|
|
138
|
+
return controller instanceof NaverMintMapController.NaverMintMapController ? controller.naverPositionToOffset(pos) : controller.positionToOffset(pos);
|
|
139
|
+
});
|
|
140
|
+
var simplified = simplifyPath ? polygon.PolygonCalculator.simplifyPoints(offsets, simplifyTolerance, lastReapeated) : offsets;
|
|
141
|
+
setOffsets(simplified); //inner path
|
|
161
142
|
|
|
162
|
-
|
|
163
|
-
var startPosition = regionInfo.maxLat && regionInfo.minLng ? new MapTypes.Position(regionInfo.maxLat, regionInfo.minLng) : undefined;
|
|
164
|
-
setPolygonStart(startPosition); //cache set
|
|
143
|
+
var innerPath = [];
|
|
165
144
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
145
|
+
if (innerPositions) {
|
|
146
|
+
for (var _i = 0, innerPositions_1 = innerPositions; _i < innerPositions_1.length; _i++) {
|
|
147
|
+
var innerPosition = innerPositions_1[_i];
|
|
148
|
+
var offsets_1 = innerPosition.map(function (pos) {
|
|
149
|
+
//offset 계산 정확도를 위해 네이버 맵은 전용 projection 베이스의 function 을 사용한다.
|
|
150
|
+
return controller instanceof NaverMintMapController.NaverMintMapController ? controller.naverPositionToOffset(pos) : controller.positionToOffset(pos);
|
|
151
|
+
});
|
|
152
|
+
var simplified_1 = simplifyPath ? polygon.PolygonCalculator.simplifyPoints(offsets_1, simplifyTolerance, lastReapeated) : offsets_1;
|
|
153
|
+
innerPath.push(simplified_1);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
setInnerOffsets(innerPath);
|
|
157
|
+
} //start point
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
var startPosition = maxLat && minLng ? new MapTypes.Position(maxLat, minLng) : undefined;
|
|
161
|
+
setPolygonStart(startPosition);
|
|
172
162
|
}, []);
|
|
173
163
|
return React__default["default"].createElement(React__default["default"].Fragment, null, polygonStart && React__default["default"].createElement(MapMarkerWrapper.MapMarkerWrapper, {
|
|
174
164
|
position: polygonStart,
|
|
@@ -57,10 +57,10 @@ function SVGPolygon(_a) {
|
|
|
57
57
|
var width = maxX - minX;
|
|
58
58
|
var height = maxY - minY;
|
|
59
59
|
return {
|
|
60
|
-
containerLeft:
|
|
61
|
-
containerTop:
|
|
62
|
-
containerWidth:
|
|
63
|
-
containerHeight:
|
|
60
|
+
containerLeft: minX,
|
|
61
|
+
containerTop: minY,
|
|
62
|
+
containerWidth: width,
|
|
63
|
+
containerHeight: height
|
|
64
64
|
};
|
|
65
65
|
}, []);
|
|
66
66
|
var getD = React.useCallback(function (_a) {
|
|
@@ -134,7 +134,7 @@ function SVGPolygon(_a) {
|
|
|
134
134
|
height: height,
|
|
135
135
|
fill: mode === 'POLYLINE' ? 'none' : background,
|
|
136
136
|
stroke: mode === 'POLYLINE' ? 'black' : 'green',
|
|
137
|
-
strokeLinejoin: "
|
|
137
|
+
strokeLinejoin: "miter",
|
|
138
138
|
strokeLinecap: "butt",
|
|
139
139
|
d: d
|
|
140
140
|
}, shapeProperties))), React__default["default"].createElement("div", {
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var MintMapProvider = require('../provider/MintMapProvider.js');
|
|
7
7
|
var animation = require('../util/animation.js');
|
|
8
|
-
var
|
|
8
|
+
var geo = require('../util/geo.js');
|
|
9
9
|
require('../../types/MapDrawables.js');
|
|
10
10
|
var MapTypes = require('../../types/MapTypes.js');
|
|
11
11
|
require('../../types/MapEventTypes.js');
|
|
@@ -71,7 +71,7 @@ function useMarkerMoving(_a) {
|
|
|
71
71
|
|
|
72
72
|
while (true) {
|
|
73
73
|
//계산
|
|
74
|
-
|
|
74
|
+
geo.GeoCalulator.computeNextPositionAndDistances(context_1); //타겟에 도착했으면, 원래 얼마나 더 갈수 있었는지 체크해서
|
|
75
75
|
//그 만큼 더 가도록 계속 처리하기위해 다시 계산
|
|
76
76
|
|
|
77
77
|
if (context_1.nextPos === context_1.pos2) {
|
|
@@ -3,34 +3,6 @@ declare class PositionMirror {
|
|
|
3
3
|
lng: number;
|
|
4
4
|
constructor(lat: number, lng: number);
|
|
5
5
|
}
|
|
6
|
-
export declare class PolygonCalculator {
|
|
7
|
-
static getRegionInfo(positions: PositionMirror[]): {
|
|
8
|
-
maxLat: number | undefined;
|
|
9
|
-
minLat: number | undefined;
|
|
10
|
-
maxLng: number | undefined;
|
|
11
|
-
minLng: number | undefined;
|
|
12
|
-
centerLat: number | undefined;
|
|
13
|
-
centerLng: number | undefined;
|
|
14
|
-
};
|
|
15
|
-
static getRegionStart(positions: PositionMirror[]): PositionMirror;
|
|
16
|
-
static getRegionEnd(positions: PositionMirror[]): PositionMirror;
|
|
17
|
-
static getCenter(positions: PositionMirror[]): PositionMirror;
|
|
18
|
-
static intersects(positions1: PositionMirror[], positions2: PositionMirror[]): boolean;
|
|
19
|
-
static getIncludedPositions(polygon: PositionMirror[], position: PositionMirror | PositionMirror[]): PositionMirror[];
|
|
20
|
-
private static convertPolygonToLinePoints;
|
|
21
|
-
private static convertPositionToPoints;
|
|
22
|
-
private static getCrossPoint;
|
|
23
|
-
private static toFixedPosition;
|
|
24
|
-
private static getCrossPointAll;
|
|
25
|
-
private static findCrossPoint;
|
|
26
|
-
static readonly TOLERANCE_NAVER_STYLE = 0.0001;
|
|
27
|
-
static readonly TOLERANCE_GOOGLE_STYLE = 0.00001;
|
|
28
|
-
static simplifyPoints(polygon: PositionMirror[], tolerance?: number, lastRepeated?: boolean): PositionMirror[];
|
|
29
|
-
private static simplify;
|
|
30
|
-
private static perpendicularDistance;
|
|
31
|
-
static calculatePolygonSize(polygon: PositionMirror[], innerPolygons?: PositionMirror[][]): number;
|
|
32
|
-
private static calculatePolygonSizeMain;
|
|
33
|
-
}
|
|
34
6
|
export interface NextPositionContext {
|
|
35
7
|
pos1: PositionMirror;
|
|
36
8
|
pos2: PositionMirror;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var PositionMirror =
|
|
6
|
+
/** @class */
|
|
7
|
+
function () {
|
|
8
|
+
function PositionMirror(lat, lng) {
|
|
9
|
+
this.lat = lat;
|
|
10
|
+
this.lng = lng;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return PositionMirror;
|
|
14
|
+
}();
|
|
15
|
+
|
|
16
|
+
var GeoCalulator =
|
|
17
|
+
/** @class */
|
|
18
|
+
function () {
|
|
19
|
+
function GeoCalulator() {}
|
|
20
|
+
|
|
21
|
+
GeoCalulator.computeDistanceKiloMeter = function (pos1, pos2) {
|
|
22
|
+
var dLat = this.deg2rad(pos2.lat - pos1.lat);
|
|
23
|
+
var dLon = this.deg2rad(pos2.lng - pos1.lng);
|
|
24
|
+
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);
|
|
25
|
+
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
26
|
+
var d = this.EARTH_EQUATORIAL_RADIUS_KM * c; // Distance in km
|
|
27
|
+
|
|
28
|
+
return d;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
GeoCalulator.deg2rad = function (deg) {
|
|
32
|
+
return deg * (Math.PI / 180);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
GeoCalulator.convertMeterToLatitudeValue = function (meter) {
|
|
36
|
+
return meter * this.LATITUDE_POSITION_VALUE_PER_METER;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
GeoCalulator.convertLatitudeToMeterValue = function (lat) {
|
|
40
|
+
return lat * this.METER_VALUE_PER_LATITUDE;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
GeoCalulator.convertLongitudeToMeterValue = function (lat, lng) {
|
|
44
|
+
return lng * this.calculateLongitudeValueWithLatitudeInMeter(lat);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
GeoCalulator.getCacheUnitOfLongitudeValueWithLatitudeInMeter = function (lat) {
|
|
48
|
+
return lat.toFixed(2);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
GeoCalulator.getCacheOfLongitudeValueWithLatitudeInMeter = function (latUnit) {
|
|
52
|
+
return this.CACHE_OF_LNG_PER_METER.get(latUnit);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
GeoCalulator.setCacheOfLongitudeValueWithLatitudeInMeter = function (latUnit, lngValue) {
|
|
56
|
+
if (this.CACHE_OF_LNG_PER_METER.size > 10) {
|
|
57
|
+
this.CACHE_OF_LNG_PER_METER.clear();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
this.CACHE_OF_LNG_PER_METER.set(latUnit, lngValue);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
GeoCalulator.calculateLongitudeValueWithLatitudeInMeter = function (lat) {
|
|
64
|
+
// const t = Date.now()
|
|
65
|
+
// Cache check
|
|
66
|
+
var latUnit = this.getCacheUnitOfLongitudeValueWithLatitudeInMeter(lat);
|
|
67
|
+
var fromCache = this.getCacheOfLongitudeValueWithLatitudeInMeter(latUnit);
|
|
68
|
+
|
|
69
|
+
if (fromCache !== undefined) {
|
|
70
|
+
// console.log(`cache hit!! ${Date.now() - t} ms`, fromCache, latUnit, this.CACHE_OF_LNG_PER_METER.size);
|
|
71
|
+
return fromCache;
|
|
72
|
+
} // Convert latitude and longitude to radians
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
var latRad = lat * Math.PI / 180; // Calculate Earth's radius at the given latitude
|
|
76
|
+
|
|
77
|
+
var radius = this.EARTH_EQUATORIAL_RADIUS * Math.sqrt(1 - Math.pow(this.EARTH_ECCENTRICITY * Math.sin(latRad), 2)); // Calculate the length of one degree of longitude in meters
|
|
78
|
+
|
|
79
|
+
var distance = 2 * Math.PI * radius * Math.cos(latRad) / 360; // Cache set
|
|
80
|
+
|
|
81
|
+
this.setCacheOfLongitudeValueWithLatitudeInMeter(latUnit, distance); // console.log(`calculated ${Date.now() - t} ms`)
|
|
82
|
+
|
|
83
|
+
return distance;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
GeoCalulator.computeNextPositionAndDistances = function (context) {
|
|
87
|
+
var pos1 = context.pos1,
|
|
88
|
+
pos2 = context.pos2,
|
|
89
|
+
prevPos2 = context.prevPos2,
|
|
90
|
+
velocityKmh = context.velocityKmh,
|
|
91
|
+
prevVelocityKmh = context.prevVelocityKmh,
|
|
92
|
+
elapsedTimeMs = context.elapsedTimeMs; // console.log('velocityKmh / elapsedTimeMs',velocityKmh , elapsedTimeMs);
|
|
93
|
+
//총 가야할 거리 (km)
|
|
94
|
+
|
|
95
|
+
if (pos2 !== prevPos2) {
|
|
96
|
+
//목표가 바뀌면 거리 및 비율 재계산
|
|
97
|
+
context.totalDistance = this.computeDistanceKiloMeter(pos1, pos2);
|
|
98
|
+
context.currDistance = 0;
|
|
99
|
+
context.prevPos2 = pos2;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
var totalDistance = context.totalDistance; // console.log('totalDistance', totalDistance);
|
|
103
|
+
//ms 속으로 환산
|
|
104
|
+
|
|
105
|
+
if (velocityKmh !== prevVelocityKmh) {
|
|
106
|
+
//속도가 바뀌면 재계산
|
|
107
|
+
context.vPerMs = velocityKmh / this.MS_FROM_HOUR;
|
|
108
|
+
context.prevVelocityKmh = velocityKmh;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
var vPerMs = context.vPerMs; //console.log('vPerMs', vPerMs);
|
|
112
|
+
//실제 가는 거리 계산
|
|
113
|
+
|
|
114
|
+
var nextDistance = context.distanceRemain ? context.distanceRemain : context.currDistance + elapsedTimeMs * vPerMs; //console.log('nextDistance', nextDistance);
|
|
115
|
+
//목표점까지 이동 후에도 남는 거리
|
|
116
|
+
|
|
117
|
+
context.currDistance = nextDistance;
|
|
118
|
+
|
|
119
|
+
if (totalDistance < context.currDistance) {
|
|
120
|
+
//이동 거리가 현재 목표점을 넘어가는 경우
|
|
121
|
+
context.distanceRemain = context.currDistance - totalDistance;
|
|
122
|
+
context.nextPos = pos2;
|
|
123
|
+
return context;
|
|
124
|
+
} else {
|
|
125
|
+
context.distanceRemain = 0;
|
|
126
|
+
} //각 축으로 나가야할 비율
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
var ratio = nextDistance / totalDistance; //console.log('ratio', ratio);
|
|
130
|
+
//방향값 체크
|
|
131
|
+
|
|
132
|
+
var latCalib = pos2.lat > pos1.lat ? 1 : -1;
|
|
133
|
+
var lngCalib = pos2.lng > pos1.lng ? 1 : -1; //각 축에 보정된 새로운 지점 리턴
|
|
134
|
+
|
|
135
|
+
var newPos = new PositionMirror(pos1.lat + (pos2.lat - pos1.lat) * ratio, pos1.lng + (pos2.lng - pos1.lng) * ratio);
|
|
136
|
+
|
|
137
|
+
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)) {
|
|
138
|
+
newPos = pos2;
|
|
139
|
+
} // console.log('newPos', newPos);
|
|
140
|
+
//console.log('==============================================================\n');
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
context.nextPos = newPos;
|
|
144
|
+
return context;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
GeoCalulator.EARTH_EQUATORIAL_RADIUS = 6378137; //meter (6,378,137 m)
|
|
148
|
+
|
|
149
|
+
GeoCalulator.EARTH_EQUATORIAL_RADIUS_KM = GeoCalulator.EARTH_EQUATORIAL_RADIUS / 1000;
|
|
150
|
+
GeoCalulator.EARTH_ECCENTRICITY = 0.08181919;
|
|
151
|
+
GeoCalulator.METER_VALUE_PER_LATITUDE = 110.32 * 1000; //위도 기준 1도는 110.32km
|
|
152
|
+
|
|
153
|
+
GeoCalulator.LATITUDE_POSITION_VALUE_PER_METER = 1 / GeoCalulator.METER_VALUE_PER_LATITUDE;
|
|
154
|
+
GeoCalulator.CACHE_OF_LNG_PER_METER = new Map();
|
|
155
|
+
GeoCalulator.MS_FROM_HOUR = 60 * 60 * 1000;
|
|
156
|
+
return GeoCalulator;
|
|
157
|
+
}();
|
|
158
|
+
|
|
159
|
+
exports.GeoCalulator = GeoCalulator;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
declare class PositionMirror {
|
|
2
|
+
lat: number;
|
|
3
|
+
lng: number;
|
|
4
|
+
constructor(lat: number, lng: number);
|
|
5
|
+
}
|
|
6
|
+
declare class OffsetMirror {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
constructor(x: number, y: number);
|
|
10
|
+
equals(other?: OffsetMirror): boolean | undefined;
|
|
11
|
+
}
|
|
12
|
+
export declare class PolygonCalculator {
|
|
13
|
+
static getRegionInfo(positions: PositionMirror[]): {
|
|
14
|
+
maxLat: number | undefined;
|
|
15
|
+
minLat: number | undefined;
|
|
16
|
+
maxLng: number | undefined;
|
|
17
|
+
minLng: number | undefined;
|
|
18
|
+
centerLat: number | undefined;
|
|
19
|
+
centerLng: number | undefined;
|
|
20
|
+
};
|
|
21
|
+
static getRegionStart(positions: PositionMirror[]): PositionMirror;
|
|
22
|
+
static getRegionEnd(positions: PositionMirror[]): PositionMirror;
|
|
23
|
+
static getCenter(positions: PositionMirror[]): PositionMirror;
|
|
24
|
+
static intersects(positions1: PositionMirror[], positions2: PositionMirror[]): boolean;
|
|
25
|
+
static getIncludedPositions(polygon: PositionMirror[], position: PositionMirror | PositionMirror[]): PositionMirror[];
|
|
26
|
+
private static convertPolygonToLinePoints;
|
|
27
|
+
private static convertPositionToPoints;
|
|
28
|
+
private static getCrossPoint;
|
|
29
|
+
private static toFixedPosition;
|
|
30
|
+
private static getCrossPointAll;
|
|
31
|
+
private static findCrossPoint;
|
|
32
|
+
static readonly TOLERANCE_NAVER_STYLE = 1;
|
|
33
|
+
static readonly TOLERANCE_GOOGLE_STYLE = 1;
|
|
34
|
+
static simplifyPoints(polygon: OffsetMirror[], tolerance?: number, lastRepeated?: boolean): OffsetMirror[];
|
|
35
|
+
private static simplify;
|
|
36
|
+
private static perpendicularDistance;
|
|
37
|
+
static calculatePolygonSize(polygon: PositionMirror[], innerPolygons?: PositionMirror[][]): number;
|
|
38
|
+
private static calculatePolygonSizeMain;
|
|
39
|
+
}
|
|
40
|
+
export {};
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var geo = require('./geo.js');
|
|
6
|
+
|
|
5
7
|
var LinePoints =
|
|
6
8
|
/** @class */
|
|
7
9
|
function () {
|
|
@@ -201,11 +203,7 @@ function () {
|
|
|
201
203
|
|
|
202
204
|
PolygonCalculator.simplifyPoints = function (polygon, tolerance, lastRepeated) {
|
|
203
205
|
var target = lastRepeated ? polygon.slice(0, polygon.length - 1) : polygon;
|
|
204
|
-
return this.simplify(target.
|
|
205
|
-
return [position.lng, position.lat];
|
|
206
|
-
}), tolerance !== undefined ? tolerance : this.TOLERANCE_NAVER_STYLE).map(function (point) {
|
|
207
|
-
return new PositionMirror(point[1], point[0]);
|
|
208
|
-
});
|
|
206
|
+
return this.simplify(target, tolerance !== undefined ? tolerance : this.TOLERANCE_NAVER_STYLE);
|
|
209
207
|
};
|
|
210
208
|
|
|
211
209
|
PolygonCalculator.simplify = function (points, tolerance) {
|
|
@@ -239,12 +237,12 @@ function () {
|
|
|
239
237
|
|
|
240
238
|
|
|
241
239
|
PolygonCalculator.perpendicularDistance = function (point, lineStart, lineEnd) {
|
|
242
|
-
var x = point
|
|
243
|
-
var y = point
|
|
244
|
-
var x1 = lineStart
|
|
245
|
-
var y1 = lineStart
|
|
246
|
-
var x2 = lineEnd
|
|
247
|
-
var y2 = lineEnd
|
|
240
|
+
var x = point.x;
|
|
241
|
+
var y = point.y;
|
|
242
|
+
var x1 = lineStart.x;
|
|
243
|
+
var y1 = lineStart.y;
|
|
244
|
+
var x2 = lineEnd.x;
|
|
245
|
+
var y2 = lineEnd.y;
|
|
248
246
|
var numerator = Math.abs((y2 - y1) * x - (x2 - x1) * y + x2 * y1 - y2 * x1);
|
|
249
247
|
var denominator = Math.sqrt(Math.pow(y2 - y1, 2) + Math.pow(x2 - x1, 2));
|
|
250
248
|
return numerator / denominator;
|
|
@@ -264,8 +262,8 @@ function () {
|
|
|
264
262
|
PolygonCalculator.calculatePolygonSizeMain = function (polygon) {
|
|
265
263
|
var vertices = polygon.map(function (pos) {
|
|
266
264
|
return {
|
|
267
|
-
x: GeoCalulator.convertLongitudeToMeterValue(pos.lat, pos.lng),
|
|
268
|
-
y: GeoCalulator.convertLatitudeToMeterValue(pos.lat)
|
|
265
|
+
x: geo.GeoCalulator.convertLongitudeToMeterValue(pos.lat, pos.lng),
|
|
266
|
+
y: geo.GeoCalulator.convertLatitudeToMeterValue(pos.lat)
|
|
269
267
|
};
|
|
270
268
|
});
|
|
271
269
|
var n = vertices.length;
|
|
@@ -281,153 +279,9 @@ function () {
|
|
|
281
279
|
return area;
|
|
282
280
|
};
|
|
283
281
|
|
|
284
|
-
PolygonCalculator.TOLERANCE_NAVER_STYLE =
|
|
285
|
-
PolygonCalculator.TOLERANCE_GOOGLE_STYLE =
|
|
282
|
+
PolygonCalculator.TOLERANCE_NAVER_STYLE = 1;
|
|
283
|
+
PolygonCalculator.TOLERANCE_GOOGLE_STYLE = 1;
|
|
286
284
|
return PolygonCalculator;
|
|
287
285
|
}();
|
|
288
286
|
|
|
289
|
-
var GeoCalulator =
|
|
290
|
-
/** @class */
|
|
291
|
-
function () {
|
|
292
|
-
function GeoCalulator() {}
|
|
293
|
-
|
|
294
|
-
GeoCalulator.computeDistanceKiloMeter = function (pos1, pos2) {
|
|
295
|
-
var dLat = this.deg2rad(pos2.lat - pos1.lat);
|
|
296
|
-
var dLon = this.deg2rad(pos2.lng - pos1.lng);
|
|
297
|
-
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);
|
|
298
|
-
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
299
|
-
var d = this.EARTH_EQUATORIAL_RADIUS_KM * c; // Distance in km
|
|
300
|
-
|
|
301
|
-
return d;
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
GeoCalulator.deg2rad = function (deg) {
|
|
305
|
-
return deg * (Math.PI / 180);
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
GeoCalulator.convertMeterToLatitudeValue = function (meter) {
|
|
309
|
-
return meter * this.LATITUDE_POSITION_VALUE_PER_METER;
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
GeoCalulator.convertLatitudeToMeterValue = function (lat) {
|
|
313
|
-
return lat * this.METER_VALUE_PER_LATITUDE;
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
GeoCalulator.convertLongitudeToMeterValue = function (lat, lng) {
|
|
317
|
-
return lng * this.calculateLongitudeValueWithLatitudeInMeter(lat);
|
|
318
|
-
};
|
|
319
|
-
|
|
320
|
-
GeoCalulator.getCacheUnitOfLongitudeValueWithLatitudeInMeter = function (lat) {
|
|
321
|
-
return lat.toFixed(2);
|
|
322
|
-
};
|
|
323
|
-
|
|
324
|
-
GeoCalulator.getCacheOfLongitudeValueWithLatitudeInMeter = function (latUnit) {
|
|
325
|
-
return this.CACHE_OF_LNG_PER_METER.get(latUnit);
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
GeoCalulator.setCacheOfLongitudeValueWithLatitudeInMeter = function (latUnit, lngValue) {
|
|
329
|
-
if (this.CACHE_OF_LNG_PER_METER.size > 10) {
|
|
330
|
-
this.CACHE_OF_LNG_PER_METER.clear();
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
this.CACHE_OF_LNG_PER_METER.set(latUnit, lngValue);
|
|
334
|
-
};
|
|
335
|
-
|
|
336
|
-
GeoCalulator.calculateLongitudeValueWithLatitudeInMeter = function (lat) {
|
|
337
|
-
// const t = Date.now()
|
|
338
|
-
// Cache check
|
|
339
|
-
var latUnit = this.getCacheUnitOfLongitudeValueWithLatitudeInMeter(lat);
|
|
340
|
-
var fromCache = this.getCacheOfLongitudeValueWithLatitudeInMeter(latUnit);
|
|
341
|
-
|
|
342
|
-
if (fromCache !== undefined) {
|
|
343
|
-
// console.log(`cache hit!! ${Date.now() - t} ms`, fromCache, latUnit, this.CACHE_OF_LNG_PER_METER.size);
|
|
344
|
-
return fromCache;
|
|
345
|
-
} // Convert latitude and longitude to radians
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
var latRad = lat * Math.PI / 180; // Calculate Earth's radius at the given latitude
|
|
349
|
-
|
|
350
|
-
var radius = this.EARTH_EQUATORIAL_RADIUS * Math.sqrt(1 - Math.pow(this.EARTH_ECCENTRICITY * Math.sin(latRad), 2)); // Calculate the length of one degree of longitude in meters
|
|
351
|
-
|
|
352
|
-
var distance = 2 * Math.PI * radius * Math.cos(latRad) / 360; // Cache set
|
|
353
|
-
|
|
354
|
-
this.setCacheOfLongitudeValueWithLatitudeInMeter(latUnit, distance); // console.log(`calculated ${Date.now() - t} ms`)
|
|
355
|
-
|
|
356
|
-
return distance;
|
|
357
|
-
};
|
|
358
|
-
|
|
359
|
-
GeoCalulator.computeNextPositionAndDistances = function (context) {
|
|
360
|
-
var pos1 = context.pos1,
|
|
361
|
-
pos2 = context.pos2,
|
|
362
|
-
prevPos2 = context.prevPos2,
|
|
363
|
-
velocityKmh = context.velocityKmh,
|
|
364
|
-
prevVelocityKmh = context.prevVelocityKmh,
|
|
365
|
-
elapsedTimeMs = context.elapsedTimeMs; // console.log('velocityKmh / elapsedTimeMs',velocityKmh , elapsedTimeMs);
|
|
366
|
-
//총 가야할 거리 (km)
|
|
367
|
-
|
|
368
|
-
if (pos2 !== prevPos2) {
|
|
369
|
-
//목표가 바뀌면 거리 및 비율 재계산
|
|
370
|
-
context.totalDistance = this.computeDistanceKiloMeter(pos1, pos2);
|
|
371
|
-
context.currDistance = 0;
|
|
372
|
-
context.prevPos2 = pos2;
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
var totalDistance = context.totalDistance; // console.log('totalDistance', totalDistance);
|
|
376
|
-
//ms 속으로 환산
|
|
377
|
-
|
|
378
|
-
if (velocityKmh !== prevVelocityKmh) {
|
|
379
|
-
//속도가 바뀌면 재계산
|
|
380
|
-
context.vPerMs = velocityKmh / this.MS_FROM_HOUR;
|
|
381
|
-
context.prevVelocityKmh = velocityKmh;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
var vPerMs = context.vPerMs; //console.log('vPerMs', vPerMs);
|
|
385
|
-
//실제 가는 거리 계산
|
|
386
|
-
|
|
387
|
-
var nextDistance = context.distanceRemain ? context.distanceRemain : context.currDistance + elapsedTimeMs * vPerMs; //console.log('nextDistance', nextDistance);
|
|
388
|
-
//목표점까지 이동 후에도 남는 거리
|
|
389
|
-
|
|
390
|
-
context.currDistance = nextDistance;
|
|
391
|
-
|
|
392
|
-
if (totalDistance < context.currDistance) {
|
|
393
|
-
//이동 거리가 현재 목표점을 넘어가는 경우
|
|
394
|
-
context.distanceRemain = context.currDistance - totalDistance;
|
|
395
|
-
context.nextPos = pos2;
|
|
396
|
-
return context;
|
|
397
|
-
} else {
|
|
398
|
-
context.distanceRemain = 0;
|
|
399
|
-
} //각 축으로 나가야할 비율
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
var ratio = nextDistance / totalDistance; //console.log('ratio', ratio);
|
|
403
|
-
//방향값 체크
|
|
404
|
-
|
|
405
|
-
var latCalib = pos2.lat > pos1.lat ? 1 : -1;
|
|
406
|
-
var lngCalib = pos2.lng > pos1.lng ? 1 : -1; //각 축에 보정된 새로운 지점 리턴
|
|
407
|
-
|
|
408
|
-
var newPos = new PositionMirror(pos1.lat + (pos2.lat - pos1.lat) * ratio, pos1.lng + (pos2.lng - pos1.lng) * ratio);
|
|
409
|
-
|
|
410
|
-
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)) {
|
|
411
|
-
newPos = pos2;
|
|
412
|
-
} // console.log('newPos', newPos);
|
|
413
|
-
//console.log('==============================================================\n');
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
context.nextPos = newPos;
|
|
417
|
-
return context;
|
|
418
|
-
};
|
|
419
|
-
|
|
420
|
-
GeoCalulator.EARTH_EQUATORIAL_RADIUS = 6378137; //meter (6,378,137 m)
|
|
421
|
-
|
|
422
|
-
GeoCalulator.EARTH_EQUATORIAL_RADIUS_KM = GeoCalulator.EARTH_EQUATORIAL_RADIUS / 1000;
|
|
423
|
-
GeoCalulator.EARTH_ECCENTRICITY = 0.08181919;
|
|
424
|
-
GeoCalulator.METER_VALUE_PER_LATITUDE = 110.32 * 1000; //위도 기준 1도는 110.32km
|
|
425
|
-
|
|
426
|
-
GeoCalulator.LATITUDE_POSITION_VALUE_PER_METER = 1 / GeoCalulator.METER_VALUE_PER_LATITUDE;
|
|
427
|
-
GeoCalulator.CACHE_OF_LNG_PER_METER = new Map();
|
|
428
|
-
GeoCalulator.MS_FROM_HOUR = 60 * 60 * 1000;
|
|
429
|
-
return GeoCalulator;
|
|
430
|
-
}();
|
|
431
|
-
|
|
432
|
-
exports.GeoCalulator = GeoCalulator;
|
|
433
287
|
exports.PolygonCalculator = PolygonCalculator;
|
|
@@ -163,7 +163,7 @@ function MapCanvasWrapper(_a) {
|
|
|
163
163
|
|
|
164
164
|
if (map) {
|
|
165
165
|
// const center = controller.getCenter()
|
|
166
|
-
// center.offset =
|
|
166
|
+
// center.offset = positionToOffset(center)
|
|
167
167
|
// if(center.offset){
|
|
168
168
|
// prevX.current = center.offset.x
|
|
169
169
|
// prevY.current = center.offset.y
|
|
@@ -183,7 +183,7 @@ function MapCanvasWrapper(_a) {
|
|
|
183
183
|
|
|
184
184
|
if (containerRef.current) {
|
|
185
185
|
// const pos = controller.getCenter()
|
|
186
|
-
// pos.offset =
|
|
186
|
+
// pos.offset = positionToOffset(pos)
|
|
187
187
|
// const deltaX = prevX.current - pos.offset.x
|
|
188
188
|
// const deltaY = prevY.current - pos.offset.y
|
|
189
189
|
// offsetProvider.current.x += deltaX
|