@exterio/react-native-yamap-lite 1.0.1
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/LICENSE +20 -0
- package/README.md +510 -0
- package/YamapLite.podspec +21 -0
- package/android/build.gradle +101 -0
- package/android/gradle.properties +14 -0
- package/android/settings.gradle +1 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/yamaplite/ClusteredYamapLiteViewManager.kt +181 -0
- package/android/src/main/java/com/yamaplite/Components/ClusteredYamapLiteView.kt +169 -0
- package/android/src/main/java/com/yamaplite/Components/YamapLiteCircleView.kt +145 -0
- package/android/src/main/java/com/yamaplite/Components/YamapLiteMarkerView.kt +214 -0
- package/android/src/main/java/com/yamaplite/Components/YamapLitePolygon.kt +149 -0
- package/android/src/main/java/com/yamaplite/Components/YamapLitePolyline.kt +171 -0
- package/android/src/main/java/com/yamaplite/Components/YamapLiteView.kt +678 -0
- package/android/src/main/java/com/yamaplite/Events/CameraPositionChangeEvent.kt +38 -0
- package/android/src/main/java/com/yamaplite/Events/MapLoadEvent.kt +34 -0
- package/android/src/main/java/com/yamaplite/Events/PressEvent.kt +24 -0
- package/android/src/main/java/com/yamaplite/Utils/ImageCache.kt +45 -0
- package/android/src/main/java/com/yamaplite/Utils/PointParser.kt +39 -0
- package/android/src/main/java/com/yamaplite/Utils/ResolveImageHelper.kt +122 -0
- package/android/src/main/java/com/yamaplite/Utils/YamapUtils.kt +169 -0
- package/android/src/main/java/com/yamaplite/YamapLiteCircleViewManager.kt +67 -0
- package/android/src/main/java/com/yamaplite/YamapLiteMarkerViewManager.kt +82 -0
- package/android/src/main/java/com/yamaplite/YamapLitePackage.kt +41 -0
- package/android/src/main/java/com/yamaplite/YamapLitePolygonViewManager.kt +61 -0
- package/android/src/main/java/com/yamaplite/YamapLitePolylineViewManager.kt +75 -0
- package/android/src/main/java/com/yamaplite/YamapLiteViewManager.kt +176 -0
- package/ios/ClusteredYamapLiteView.h +15 -0
- package/ios/ClusteredYamapLiteView.mm +325 -0
- package/ios/ClusteredYamapLiteViewManager.mm +17 -0
- package/ios/Components/Circle.swift +108 -0
- package/ios/Components/ClusteredYamap.swift +190 -0
- package/ios/Components/Marker.swift +187 -0
- package/ios/Components/Polygon.swift +108 -0
- package/ios/Components/Polyline.swift +125 -0
- package/ios/Components/Yamap.swift +585 -0
- package/ios/Listeners/CameraListener.swift +54 -0
- package/ios/Listeners/ClusterListener.swift +38 -0
- package/ios/Listeners/MapInputListener.swift +35 -0
- package/ios/Listeners/MapLoadListener.swift +35 -0
- package/ios/Listeners/MapObjectTap.swift +12 -0
- package/ios/Listeners/UserLocationObjectListener.swift +29 -0
- package/ios/Models/YamapModels.swift +77 -0
- package/ios/Utils/ImageCache.swift +20 -0
- package/ios/Utils/PointsEqual.h +45 -0
- package/ios/Utils/ResolveImageHelper.swift +142 -0
- package/ios/YamapLiteCircleView.h +15 -0
- package/ios/YamapLiteCircleView.mm +102 -0
- package/ios/YamapLiteMarkerView.h +15 -0
- package/ios/YamapLiteMarkerView.mm +102 -0
- package/ios/YamapLitePolygonView.h +15 -0
- package/ios/YamapLitePolygonView.mm +120 -0
- package/ios/YamapLitePolylineView.h +15 -0
- package/ios/YamapLitePolylineView.mm +115 -0
- package/ios/YamapLiteView.h +15 -0
- package/ios/YamapLiteView.mm +361 -0
- package/ios/YamapLiteViewManager.mm +17 -0
- package/ios/YamapUtils.h +5 -0
- package/ios/YamapUtils.mm +205 -0
- package/lib/module/@types/index.js +8 -0
- package/lib/module/@types/index.js.map +1 -0
- package/lib/module/ClusteredYamapLiteViewNativeComponent.ts +98 -0
- package/lib/module/Components/Circle.js +20 -0
- package/lib/module/Components/Circle.js.map +1 -0
- package/lib/module/Components/ClusteredYamap.js +133 -0
- package/lib/module/Components/ClusteredYamap.js.map +1 -0
- package/lib/module/Components/Marker.js +40 -0
- package/lib/module/Components/Marker.js.map +1 -0
- package/lib/module/Components/Polygon.js +25 -0
- package/lib/module/Components/Polygon.js.map +1 -0
- package/lib/module/Components/Polyline.js +25 -0
- package/lib/module/Components/Polyline.js.map +1 -0
- package/lib/module/Components/Yamap.js +124 -0
- package/lib/module/Components/Yamap.js.map +1 -0
- package/lib/module/Components/index.js +9 -0
- package/lib/module/Components/index.js.map +1 -0
- package/lib/module/NativeYamapUtils.js +5 -0
- package/lib/module/NativeYamapUtils.js.map +1 -0
- package/lib/module/Utils/YamapUtils.js +14 -0
- package/lib/module/Utils/YamapUtils.js.map +1 -0
- package/lib/module/YamapCircleViewNativeComponent.ts +28 -0
- package/lib/module/YamapLiteViewNativeComponent.ts +93 -0
- package/lib/module/YamapMarkerViewNativeComponent.ts +32 -0
- package/lib/module/YamapPolygonViewNativeComponent.ts +28 -0
- package/lib/module/YamapPolylineViewNativeComponent.ts +31 -0
- package/lib/module/index.js +7 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/@types/index.d.ts +257 -0
- package/lib/typescript/src/@types/index.d.ts.map +1 -0
- package/lib/typescript/src/ClusteredYamapLiteViewNativeComponent.d.ts +82 -0
- package/lib/typescript/src/ClusteredYamapLiteViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/Components/Circle.d.ts +4 -0
- package/lib/typescript/src/Components/Circle.d.ts.map +1 -0
- package/lib/typescript/src/Components/ClusteredYamap.d.ts +3 -0
- package/lib/typescript/src/Components/ClusteredYamap.d.ts.map +1 -0
- package/lib/typescript/src/Components/Marker.d.ts +3 -0
- package/lib/typescript/src/Components/Marker.d.ts.map +1 -0
- package/lib/typescript/src/Components/Polygon.d.ts +4 -0
- package/lib/typescript/src/Components/Polygon.d.ts.map +1 -0
- package/lib/typescript/src/Components/Polyline.d.ts +4 -0
- package/lib/typescript/src/Components/Polyline.d.ts.map +1 -0
- package/lib/typescript/src/Components/Yamap.d.ts +3 -0
- package/lib/typescript/src/Components/Yamap.d.ts.map +1 -0
- package/lib/typescript/src/Components/index.d.ts +7 -0
- package/lib/typescript/src/Components/index.d.ts.map +1 -0
- package/lib/typescript/src/NativeYamapUtils.d.ts +30 -0
- package/lib/typescript/src/NativeYamapUtils.d.ts.map +1 -0
- package/lib/typescript/src/Utils/YamapUtils.d.ts +27 -0
- package/lib/typescript/src/Utils/YamapUtils.d.ts.map +1 -0
- package/lib/typescript/src/YamapCircleViewNativeComponent.d.ts +20 -0
- package/lib/typescript/src/YamapCircleViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/YamapLiteViewNativeComponent.d.ts +80 -0
- package/lib/typescript/src/YamapLiteViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/YamapMarkerViewNativeComponent.d.ts +25 -0
- package/lib/typescript/src/YamapMarkerViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/YamapPolygonViewNativeComponent.d.ts +20 -0
- package/lib/typescript/src/YamapPolygonViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/YamapPolylineViewNativeComponent.d.ts +23 -0
- package/lib/typescript/src/YamapPolylineViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +5 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +189 -0
- package/src/@types/index.ts +314 -0
- package/src/ClusteredYamapLiteViewNativeComponent.ts +98 -0
- package/src/Components/Circle.tsx +22 -0
- package/src/Components/ClusteredYamap.tsx +194 -0
- package/src/Components/Marker.tsx +50 -0
- package/src/Components/Polygon.tsx +27 -0
- package/src/Components/Polyline.tsx +27 -0
- package/src/Components/Yamap.tsx +176 -0
- package/src/Components/index.ts +6 -0
- package/src/NativeYamapUtils.ts +47 -0
- package/src/Utils/YamapUtils.ts +63 -0
- package/src/YamapCircleViewNativeComponent.ts +28 -0
- package/src/YamapLiteViewNativeComponent.ts +93 -0
- package/src/YamapMarkerViewNativeComponent.ts +32 -0
- package/src/YamapPolygonViewNativeComponent.ts +28 -0
- package/src/YamapPolylineViewNativeComponent.ts +31 -0
- package/src/index.tsx +5 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import {
|
|
2
|
+
forwardRef,
|
|
3
|
+
useImperativeHandle,
|
|
4
|
+
useRef,
|
|
5
|
+
type ForwardedRef,
|
|
6
|
+
} from 'react';
|
|
7
|
+
import { findNodeHandle, Image, type NativeSyntheticEvent } from 'react-native';
|
|
8
|
+
import type {
|
|
9
|
+
ClusteredYamapProps,
|
|
10
|
+
Point,
|
|
11
|
+
ScreenPoint,
|
|
12
|
+
YaMapRef,
|
|
13
|
+
} from '../@types';
|
|
14
|
+
import { YamapUtils } from '../Utils/YamapUtils';
|
|
15
|
+
import ClusteredYamapLiteView from '../ClusteredYamapLiteViewNativeComponent';
|
|
16
|
+
|
|
17
|
+
export const ClusteredYamap = forwardRef(
|
|
18
|
+
(props: ClusteredYamapProps, ref: ForwardedRef<YaMapRef>) => {
|
|
19
|
+
const nativeRef = useRef(null);
|
|
20
|
+
const latestProps = useRef(props);
|
|
21
|
+
latestProps.current = props;
|
|
22
|
+
|
|
23
|
+
const {
|
|
24
|
+
userLocationIcon,
|
|
25
|
+
interactive = true,
|
|
26
|
+
zoomGesturesEnabled = true,
|
|
27
|
+
scrollGesturesEnabled = true,
|
|
28
|
+
tiltGesturesEnabled = true,
|
|
29
|
+
rotateGesturesEnabled = true,
|
|
30
|
+
fastTapEnabled = true,
|
|
31
|
+
nightMode = false,
|
|
32
|
+
showUserPosition = false,
|
|
33
|
+
userLocationAccuracyFillColor = '#00FF00',
|
|
34
|
+
userLocationAccuracyStrokeColor = '#000000',
|
|
35
|
+
userLocationAccuracyStrokeWidth = 2,
|
|
36
|
+
userLocationIconScale = 1,
|
|
37
|
+
clusteredMarkers = [],
|
|
38
|
+
renderMarker = () => null,
|
|
39
|
+
clusterColor = '#FF0000',
|
|
40
|
+
children: userChildren,
|
|
41
|
+
onMapPress,
|
|
42
|
+
onMapLongPress,
|
|
43
|
+
onCameraPositionReceived: _onCameraPositionReceived,
|
|
44
|
+
onVisibleRegionReceived: _onVisibleRegionReceived,
|
|
45
|
+
onWorldToScreenPointsReceived: _onWorldToScreenPointsReceived,
|
|
46
|
+
onScreenToWorldPointsReceived: _onScreenToWorldPointsReceived,
|
|
47
|
+
...otherProps
|
|
48
|
+
} = props;
|
|
49
|
+
|
|
50
|
+
useImperativeHandle(
|
|
51
|
+
ref,
|
|
52
|
+
() => ({
|
|
53
|
+
getCameraPosition: async () => {
|
|
54
|
+
const result = await YamapUtils.getCameraPosition(
|
|
55
|
+
findNodeHandle(nativeRef.current)!
|
|
56
|
+
);
|
|
57
|
+
latestProps.current.onCameraPositionReceived?.({
|
|
58
|
+
nativeEvent: result,
|
|
59
|
+
});
|
|
60
|
+
return result;
|
|
61
|
+
},
|
|
62
|
+
getVisibleRegion: async () => {
|
|
63
|
+
const result = await YamapUtils.getVisibleRegion(
|
|
64
|
+
findNodeHandle(nativeRef.current)!
|
|
65
|
+
);
|
|
66
|
+
latestProps.current.onVisibleRegionReceived?.({
|
|
67
|
+
nativeEvent: result,
|
|
68
|
+
});
|
|
69
|
+
return result;
|
|
70
|
+
},
|
|
71
|
+
getScreenPoints: async (points: Point[]) => {
|
|
72
|
+
const result = await YamapUtils.getScreenPoints(
|
|
73
|
+
findNodeHandle(nativeRef.current)!,
|
|
74
|
+
points
|
|
75
|
+
);
|
|
76
|
+
latestProps.current.onWorldToScreenPointsReceived?.({
|
|
77
|
+
nativeEvent: { points: result.points },
|
|
78
|
+
});
|
|
79
|
+
return result.points;
|
|
80
|
+
},
|
|
81
|
+
getWorldPoints: async (points: ScreenPoint[]) => {
|
|
82
|
+
const result = await YamapUtils.getWorldPoints(
|
|
83
|
+
findNodeHandle(nativeRef.current)!,
|
|
84
|
+
points
|
|
85
|
+
);
|
|
86
|
+
latestProps.current.onScreenToWorldPointsReceived?.({
|
|
87
|
+
nativeEvent: { points: result.points },
|
|
88
|
+
});
|
|
89
|
+
return result.points;
|
|
90
|
+
},
|
|
91
|
+
setZoom: async (
|
|
92
|
+
zoom: number,
|
|
93
|
+
duration?: number,
|
|
94
|
+
animation?: 'LINEAR' | 'SMOOTH'
|
|
95
|
+
) => {
|
|
96
|
+
await YamapUtils.setZoom(
|
|
97
|
+
findNodeHandle(nativeRef.current)!,
|
|
98
|
+
zoom,
|
|
99
|
+
duration ?? 500,
|
|
100
|
+
animation ?? 'SMOOTH'
|
|
101
|
+
);
|
|
102
|
+
},
|
|
103
|
+
setCenter: async (
|
|
104
|
+
center: Point,
|
|
105
|
+
zoom?: number,
|
|
106
|
+
azimuth?: number,
|
|
107
|
+
tilt?: number,
|
|
108
|
+
duration?: number,
|
|
109
|
+
animation?: 'LINEAR' | 'SMOOTH'
|
|
110
|
+
) => {
|
|
111
|
+
await YamapUtils.setCenter(
|
|
112
|
+
findNodeHandle(nativeRef.current)!,
|
|
113
|
+
center.lat,
|
|
114
|
+
center.lon,
|
|
115
|
+
zoom ?? 10,
|
|
116
|
+
azimuth ?? 0,
|
|
117
|
+
tilt ?? 0,
|
|
118
|
+
duration ?? 500,
|
|
119
|
+
animation ?? 'SMOOTH'
|
|
120
|
+
);
|
|
121
|
+
},
|
|
122
|
+
fitAllMarkers: async () => {
|
|
123
|
+
await YamapUtils.fitAllMarkers(findNodeHandle(nativeRef.current)!);
|
|
124
|
+
},
|
|
125
|
+
fitMarkers: async (_markers: any[]) => {
|
|
126
|
+
await YamapUtils.fitAllMarkers(findNodeHandle(nativeRef.current)!);
|
|
127
|
+
},
|
|
128
|
+
getMapObjectCount: async () => {
|
|
129
|
+
return YamapUtils.getMapObjectCount(
|
|
130
|
+
findNodeHandle(nativeRef.current)!
|
|
131
|
+
);
|
|
132
|
+
},
|
|
133
|
+
setTrafficVisible: (_visible: boolean) => {
|
|
134
|
+
// Traffic layer is not available in lite SDK
|
|
135
|
+
},
|
|
136
|
+
}),
|
|
137
|
+
[]
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
const userLocationIconUri = userLocationIcon
|
|
141
|
+
? Image.resolveAssetSource(userLocationIcon).uri
|
|
142
|
+
: '';
|
|
143
|
+
|
|
144
|
+
const clusteredMarkersPoints = clusteredMarkers.map(
|
|
145
|
+
(marker) => marker.point as Point
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
const handleMapPress = (event: NativeSyntheticEvent<Point>) => {
|
|
149
|
+
if (onMapPress) {
|
|
150
|
+
onMapPress({
|
|
151
|
+
lat: event.nativeEvent.lat,
|
|
152
|
+
lon: event.nativeEvent.lon,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const handleMapLongPress = (event: NativeSyntheticEvent<Point>) => {
|
|
158
|
+
if (onMapLongPress) {
|
|
159
|
+
onMapLongPress({
|
|
160
|
+
lat: event.nativeEvent.lat,
|
|
161
|
+
lon: event.nativeEvent.lon,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
return (
|
|
167
|
+
<ClusteredYamapLiteView
|
|
168
|
+
ref={nativeRef}
|
|
169
|
+
userLocationIcon={userLocationIconUri}
|
|
170
|
+
zoomGesturesEnabled={interactive ? zoomGesturesEnabled : false}
|
|
171
|
+
scrollGesturesEnabled={interactive ? scrollGesturesEnabled : false}
|
|
172
|
+
tiltGesturesEnabled={interactive ? tiltGesturesEnabled : false}
|
|
173
|
+
rotateGesturesEnabled={interactive ? rotateGesturesEnabled : false}
|
|
174
|
+
fastTapEnabled={interactive ? fastTapEnabled : false}
|
|
175
|
+
nightMode={nightMode}
|
|
176
|
+
showUserPosition={showUserPosition}
|
|
177
|
+
userLocationAccuracyFillColor={userLocationAccuracyFillColor}
|
|
178
|
+
userLocationAccuracyStrokeColor={userLocationAccuracyStrokeColor}
|
|
179
|
+
userLocationAccuracyStrokeWidth={userLocationAccuracyStrokeWidth}
|
|
180
|
+
userLocationIconScale={userLocationIconScale}
|
|
181
|
+
clusteredMarkers={clusteredMarkersPoints}
|
|
182
|
+
clusterColor={clusterColor}
|
|
183
|
+
onMapPress={handleMapPress}
|
|
184
|
+
onMapLongPress={handleMapLongPress}
|
|
185
|
+
{...otherProps}
|
|
186
|
+
>
|
|
187
|
+
{clusteredMarkers.map((marker, index) =>
|
|
188
|
+
renderMarker({ point: marker.point, data: marker.data }, index)
|
|
189
|
+
)}
|
|
190
|
+
{userChildren}
|
|
191
|
+
</ClusteredYamapLiteView>
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
forwardRef,
|
|
3
|
+
useEffect,
|
|
4
|
+
useImperativeHandle,
|
|
5
|
+
useRef,
|
|
6
|
+
useState,
|
|
7
|
+
} from 'react';
|
|
8
|
+
import type { MarkerProps, MarkerRef, Point } from '../@types';
|
|
9
|
+
import { Image, type NativeSyntheticEvent } from 'react-native';
|
|
10
|
+
import YamapLiteMarkerView from '../YamapMarkerViewNativeComponent';
|
|
11
|
+
|
|
12
|
+
export const Marker = forwardRef<MarkerRef, MarkerProps>(
|
|
13
|
+
({ onPress, source, zIndex, point: pointProp, ...props }, ref) => {
|
|
14
|
+
const [point, setPoint] = useState<Point>(pointProp);
|
|
15
|
+
const prevPointPropRef = useRef(pointProp);
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (
|
|
19
|
+
pointProp.lat !== prevPointPropRef.current.lat ||
|
|
20
|
+
pointProp.lon !== prevPointPropRef.current.lon
|
|
21
|
+
) {
|
|
22
|
+
prevPointPropRef.current = pointProp;
|
|
23
|
+
setPoint(pointProp);
|
|
24
|
+
}
|
|
25
|
+
}, [pointProp]);
|
|
26
|
+
|
|
27
|
+
useImperativeHandle(ref, () => ({
|
|
28
|
+
animatedMoveTo: (newPoint: Point, _duration: number) => {
|
|
29
|
+
setPoint(newPoint);
|
|
30
|
+
},
|
|
31
|
+
animatedRotateTo: (_angle: number, _duration: number) => {},
|
|
32
|
+
}));
|
|
33
|
+
|
|
34
|
+
const handleMarkerPress = (event: NativeSyntheticEvent<Point>) => {
|
|
35
|
+
onPress?.(event.nativeEvent);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const markerIconUri = source ? Image.resolveAssetSource(source).uri : '';
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<YamapLiteMarkerView
|
|
42
|
+
{...props}
|
|
43
|
+
point={point}
|
|
44
|
+
zInd={zIndex ?? 1}
|
|
45
|
+
source={markerIconUri}
|
|
46
|
+
onMarkerPress={handleMarkerPress}
|
|
47
|
+
/>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Point, PolygonProps } from '../@types';
|
|
3
|
+
import { type NativeSyntheticEvent } from 'react-native';
|
|
4
|
+
import YamapLitePolygonView from '../YamapPolygonViewNativeComponent';
|
|
5
|
+
|
|
6
|
+
export const Polygon: React.FC<PolygonProps> = ({
|
|
7
|
+
onPress,
|
|
8
|
+
zIndex,
|
|
9
|
+
...props
|
|
10
|
+
}) => {
|
|
11
|
+
const handlePolygonPress = (event: NativeSyntheticEvent<Point>) => {
|
|
12
|
+
if (onPress) {
|
|
13
|
+
onPress({
|
|
14
|
+
lat: event.nativeEvent.lat,
|
|
15
|
+
lon: event.nativeEvent.lon,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<YamapLitePolygonView
|
|
22
|
+
{...props}
|
|
23
|
+
onPolygonPress={handlePolygonPress}
|
|
24
|
+
zInd={zIndex}
|
|
25
|
+
/>
|
|
26
|
+
);
|
|
27
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Point, PolylineProps } from '../@types';
|
|
3
|
+
import { type NativeSyntheticEvent } from 'react-native';
|
|
4
|
+
import YamapLitePolylineView from '../YamapPolylineViewNativeComponent';
|
|
5
|
+
|
|
6
|
+
export const Polyline: React.FC<PolylineProps> = ({
|
|
7
|
+
onPress,
|
|
8
|
+
zIndex,
|
|
9
|
+
...props
|
|
10
|
+
}) => {
|
|
11
|
+
const handlePolylinePress = (event: NativeSyntheticEvent<Point>) => {
|
|
12
|
+
if (onPress) {
|
|
13
|
+
onPress({
|
|
14
|
+
lat: event.nativeEvent.lat,
|
|
15
|
+
lon: event.nativeEvent.lon,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<YamapLitePolylineView
|
|
22
|
+
{...props}
|
|
23
|
+
onPolylinePress={handlePolylinePress}
|
|
24
|
+
zInd={zIndex}
|
|
25
|
+
/>
|
|
26
|
+
);
|
|
27
|
+
};
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import {
|
|
2
|
+
forwardRef,
|
|
3
|
+
useImperativeHandle,
|
|
4
|
+
useRef,
|
|
5
|
+
type ForwardedRef,
|
|
6
|
+
} from 'react';
|
|
7
|
+
import { findNodeHandle, Image, type NativeSyntheticEvent } from 'react-native';
|
|
8
|
+
import type { Point, ScreenPoint, YaMapProps, YaMapRef } from '../@types';
|
|
9
|
+
import YamapLiteView from '../YamapLiteViewNativeComponent';
|
|
10
|
+
import { YamapUtils } from '../Utils/YamapUtils';
|
|
11
|
+
|
|
12
|
+
export const YaMap = forwardRef(
|
|
13
|
+
(props: YaMapProps, ref: ForwardedRef<YaMapRef>) => {
|
|
14
|
+
const nativeRef = useRef(null);
|
|
15
|
+
// Always holds the latest props without closing over stale values in imperative handle
|
|
16
|
+
const latestProps = useRef(props);
|
|
17
|
+
latestProps.current = props;
|
|
18
|
+
|
|
19
|
+
const {
|
|
20
|
+
userLocationIcon,
|
|
21
|
+
interactive = true,
|
|
22
|
+
zoomGesturesEnabled = true,
|
|
23
|
+
scrollGesturesEnabled = true,
|
|
24
|
+
tiltGesturesEnabled = true,
|
|
25
|
+
rotateGesturesEnabled = true,
|
|
26
|
+
fastTapEnabled = true,
|
|
27
|
+
nightMode = false,
|
|
28
|
+
showUserPosition = false,
|
|
29
|
+
userLocationAccuracyFillColor = '#00FF00',
|
|
30
|
+
userLocationAccuracyStrokeColor = '#000000',
|
|
31
|
+
userLocationAccuracyStrokeWidth = 2,
|
|
32
|
+
userLocationIconScale = 1,
|
|
33
|
+
onMapPress,
|
|
34
|
+
onMapLongPress,
|
|
35
|
+
// Destructure backward-compat callbacks so they don't leak into otherProps
|
|
36
|
+
onCameraPositionReceived: _onCameraPositionReceived,
|
|
37
|
+
onVisibleRegionReceived: _onVisibleRegionReceived,
|
|
38
|
+
onWorldToScreenPointsReceived: _onWorldToScreenPointsReceived,
|
|
39
|
+
onScreenToWorldPointsReceived: _onScreenToWorldPointsReceived,
|
|
40
|
+
...otherProps
|
|
41
|
+
} = props;
|
|
42
|
+
|
|
43
|
+
useImperativeHandle(
|
|
44
|
+
ref,
|
|
45
|
+
() => ({
|
|
46
|
+
getCameraPosition: async () => {
|
|
47
|
+
const result = await YamapUtils.getCameraPosition(
|
|
48
|
+
findNodeHandle(nativeRef.current)!
|
|
49
|
+
);
|
|
50
|
+
latestProps.current.onCameraPositionReceived?.({
|
|
51
|
+
nativeEvent: result,
|
|
52
|
+
});
|
|
53
|
+
return result;
|
|
54
|
+
},
|
|
55
|
+
getVisibleRegion: async () => {
|
|
56
|
+
const result = await YamapUtils.getVisibleRegion(
|
|
57
|
+
findNodeHandle(nativeRef.current)!
|
|
58
|
+
);
|
|
59
|
+
latestProps.current.onVisibleRegionReceived?.({
|
|
60
|
+
nativeEvent: result,
|
|
61
|
+
});
|
|
62
|
+
return result;
|
|
63
|
+
},
|
|
64
|
+
getScreenPoints: async (points: Point[]) => {
|
|
65
|
+
const result = await YamapUtils.getScreenPoints(
|
|
66
|
+
findNodeHandle(nativeRef.current)!,
|
|
67
|
+
points
|
|
68
|
+
);
|
|
69
|
+
latestProps.current.onWorldToScreenPointsReceived?.({
|
|
70
|
+
nativeEvent: { points: result.points },
|
|
71
|
+
});
|
|
72
|
+
return result.points;
|
|
73
|
+
},
|
|
74
|
+
getWorldPoints: async (points: ScreenPoint[]) => {
|
|
75
|
+
const result = await YamapUtils.getWorldPoints(
|
|
76
|
+
findNodeHandle(nativeRef.current)!,
|
|
77
|
+
points
|
|
78
|
+
);
|
|
79
|
+
latestProps.current.onScreenToWorldPointsReceived?.({
|
|
80
|
+
nativeEvent: { points: result.points },
|
|
81
|
+
});
|
|
82
|
+
return result.points;
|
|
83
|
+
},
|
|
84
|
+
setZoom: async (
|
|
85
|
+
zoom: number,
|
|
86
|
+
duration?: number,
|
|
87
|
+
animation?: 'LINEAR' | 'SMOOTH'
|
|
88
|
+
) => {
|
|
89
|
+
await YamapUtils.setZoom(
|
|
90
|
+
findNodeHandle(nativeRef.current)!,
|
|
91
|
+
zoom,
|
|
92
|
+
duration ?? 500,
|
|
93
|
+
animation ?? 'SMOOTH'
|
|
94
|
+
);
|
|
95
|
+
},
|
|
96
|
+
setCenter: async (
|
|
97
|
+
center: Point,
|
|
98
|
+
zoom?: number,
|
|
99
|
+
azimuth?: number,
|
|
100
|
+
tilt?: number,
|
|
101
|
+
duration?: number,
|
|
102
|
+
animation?: 'LINEAR' | 'SMOOTH'
|
|
103
|
+
) => {
|
|
104
|
+
await YamapUtils.setCenter(
|
|
105
|
+
findNodeHandle(nativeRef.current)!,
|
|
106
|
+
center.lat,
|
|
107
|
+
center.lon,
|
|
108
|
+
zoom ?? 10,
|
|
109
|
+
azimuth ?? 0,
|
|
110
|
+
tilt ?? 0,
|
|
111
|
+
duration ?? 500,
|
|
112
|
+
animation ?? 'SMOOTH'
|
|
113
|
+
);
|
|
114
|
+
},
|
|
115
|
+
fitAllMarkers: async () => {
|
|
116
|
+
await YamapUtils.fitAllMarkers(findNodeHandle(nativeRef.current)!);
|
|
117
|
+
},
|
|
118
|
+
fitMarkers: async (_markers: any[]) => {
|
|
119
|
+
await YamapUtils.fitAllMarkers(findNodeHandle(nativeRef.current)!);
|
|
120
|
+
},
|
|
121
|
+
getMapObjectCount: async () => {
|
|
122
|
+
return YamapUtils.getMapObjectCount(
|
|
123
|
+
findNodeHandle(nativeRef.current)!
|
|
124
|
+
);
|
|
125
|
+
},
|
|
126
|
+
setTrafficVisible: (_visible: boolean) => {
|
|
127
|
+
// Traffic layer is not available in lite SDK
|
|
128
|
+
},
|
|
129
|
+
}),
|
|
130
|
+
[]
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
const userLocationIconUri = userLocationIcon
|
|
134
|
+
? Image.resolveAssetSource(userLocationIcon).uri
|
|
135
|
+
: '';
|
|
136
|
+
|
|
137
|
+
const handleMapPress = (event: NativeSyntheticEvent<Point>) => {
|
|
138
|
+
if (onMapPress) {
|
|
139
|
+
onMapPress({
|
|
140
|
+
lat: event.nativeEvent.lat,
|
|
141
|
+
lon: event.nativeEvent.lon,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const handleMapLongPress = (event: NativeSyntheticEvent<Point>) => {
|
|
147
|
+
if (onMapLongPress) {
|
|
148
|
+
onMapLongPress({
|
|
149
|
+
lat: event.nativeEvent.lat,
|
|
150
|
+
lon: event.nativeEvent.lon,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
return (
|
|
156
|
+
<YamapLiteView
|
|
157
|
+
ref={nativeRef}
|
|
158
|
+
userLocationIcon={userLocationIconUri}
|
|
159
|
+
zoomGesturesEnabled={interactive ? zoomGesturesEnabled : false}
|
|
160
|
+
scrollGesturesEnabled={interactive ? scrollGesturesEnabled : false}
|
|
161
|
+
tiltGesturesEnabled={interactive ? tiltGesturesEnabled : false}
|
|
162
|
+
rotateGesturesEnabled={interactive ? rotateGesturesEnabled : false}
|
|
163
|
+
fastTapEnabled={interactive ? fastTapEnabled : false}
|
|
164
|
+
nightMode={nightMode}
|
|
165
|
+
showUserPosition={showUserPosition}
|
|
166
|
+
userLocationAccuracyFillColor={userLocationAccuracyFillColor}
|
|
167
|
+
userLocationAccuracyStrokeColor={userLocationAccuracyStrokeColor}
|
|
168
|
+
userLocationAccuracyStrokeWidth={userLocationAccuracyStrokeWidth}
|
|
169
|
+
userLocationIconScale={userLocationIconScale}
|
|
170
|
+
onMapPress={handleMapPress}
|
|
171
|
+
onMapLongPress={handleMapLongPress}
|
|
172
|
+
{...otherProps}
|
|
173
|
+
/>
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type TurboModule, TurboModuleRegistry } from 'react-native';
|
|
2
|
+
import type { Double } from 'react-native/Libraries/Types/CodegenTypes';
|
|
3
|
+
import type { Point, ScreenPoint, VisibleRegion } from './@types';
|
|
4
|
+
|
|
5
|
+
export interface Spec extends TurboModule {
|
|
6
|
+
getCameraPosition(viewId: Double): Promise<{
|
|
7
|
+
lat: Double;
|
|
8
|
+
lon: Double;
|
|
9
|
+
zoom: Double;
|
|
10
|
+
azimuth: Double;
|
|
11
|
+
tilt: Double;
|
|
12
|
+
}>;
|
|
13
|
+
getScreenPoints(
|
|
14
|
+
viewId: Double,
|
|
15
|
+
points: Point[]
|
|
16
|
+
): Promise<{ points: ScreenPoint[] }>;
|
|
17
|
+
getVisibleRegion(viewId: Double): Promise<VisibleRegion>;
|
|
18
|
+
getWorldPoints(
|
|
19
|
+
viewId: Double,
|
|
20
|
+
points: ScreenPoint[]
|
|
21
|
+
): Promise<{ points: Point[] }>;
|
|
22
|
+
fitAllMarkers(viewId: Double): Promise<void>;
|
|
23
|
+
getMapObjectCount(viewId: Double): Promise<Double>;
|
|
24
|
+
setZoom(
|
|
25
|
+
viewId: Double,
|
|
26
|
+
zoom: Double,
|
|
27
|
+
duration: Double,
|
|
28
|
+
animation: string
|
|
29
|
+
): Promise<void>;
|
|
30
|
+
setCenter(
|
|
31
|
+
viewId: Double,
|
|
32
|
+
latitude: Double,
|
|
33
|
+
longitude: Double,
|
|
34
|
+
zoom: Double,
|
|
35
|
+
azimuth: Double,
|
|
36
|
+
tilt: Double,
|
|
37
|
+
duration: Double,
|
|
38
|
+
animation: string
|
|
39
|
+
): Promise<void>;
|
|
40
|
+
|
|
41
|
+
init(apiKey: string): Promise<void>;
|
|
42
|
+
getLocale(): Promise<string>;
|
|
43
|
+
setLocale(locale: string): Promise<void>;
|
|
44
|
+
resetLocale(): Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export default TurboModuleRegistry.getEnforcing<Spec>('YamapUtils');
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Platform, NativeModules } from 'react-native';
|
|
2
|
+
|
|
3
|
+
const LINKING_ERROR =
|
|
4
|
+
`The package '@exterio/react-native-yamap-lite' doesn't seem to be linked. Make sure: \n\n` +
|
|
5
|
+
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
6
|
+
'- You rebuilt the app after installing the package\n' +
|
|
7
|
+
'- You are not using Expo managed workflow\n';
|
|
8
|
+
|
|
9
|
+
interface IYamapUtilsModule {
|
|
10
|
+
getCameraPosition(viewId: number): Promise<{
|
|
11
|
+
lat: number;
|
|
12
|
+
lon: number;
|
|
13
|
+
zoom: number;
|
|
14
|
+
azimuth: number;
|
|
15
|
+
tilt: number;
|
|
16
|
+
}>;
|
|
17
|
+
getVisibleRegion(viewId: number): Promise<import('../@types').VisibleRegion>;
|
|
18
|
+
getScreenPoints(
|
|
19
|
+
viewId: number,
|
|
20
|
+
points: import('../@types').Point[]
|
|
21
|
+
): Promise<{ points: import('../@types').ScreenPoint[] }>;
|
|
22
|
+
getWorldPoints(
|
|
23
|
+
viewId: number,
|
|
24
|
+
points: import('../@types').ScreenPoint[]
|
|
25
|
+
): Promise<{ points: import('../@types').Point[] }>;
|
|
26
|
+
init(apiKey: string): Promise<void>;
|
|
27
|
+
getLocale(): Promise<string>;
|
|
28
|
+
setLocale(locale: string): Promise<void>;
|
|
29
|
+
resetLocale(): Promise<void>;
|
|
30
|
+
setZoom(
|
|
31
|
+
viewId: number,
|
|
32
|
+
zoom: number,
|
|
33
|
+
duration: number,
|
|
34
|
+
animation: 'LINEAR' | 'SMOOTH'
|
|
35
|
+
): Promise<void>;
|
|
36
|
+
setCenter(
|
|
37
|
+
viewId: number,
|
|
38
|
+
latitude: number,
|
|
39
|
+
longitude: number,
|
|
40
|
+
zoom: number,
|
|
41
|
+
azimuth: number,
|
|
42
|
+
tilt: number,
|
|
43
|
+
duration: number,
|
|
44
|
+
animation: 'LINEAR' | 'SMOOTH'
|
|
45
|
+
): Promise<void>;
|
|
46
|
+
fitAllMarkers(viewId: number): Promise<void>;
|
|
47
|
+
getMapObjectCount(viewId: number): Promise<number>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const YamapUtilsModule = true
|
|
51
|
+
? require('../NativeYamapUtils').default
|
|
52
|
+
: NativeModules.TurboExample;
|
|
53
|
+
|
|
54
|
+
export const YamapUtils: IYamapUtilsModule = YamapUtilsModule
|
|
55
|
+
? YamapUtilsModule
|
|
56
|
+
: new Proxy(
|
|
57
|
+
{},
|
|
58
|
+
{
|
|
59
|
+
get() {
|
|
60
|
+
throw new Error(LINKING_ERROR);
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
2
|
+
import type { HostComponent, ViewProps, ColorValue } from 'react-native';
|
|
3
|
+
import type {
|
|
4
|
+
DirectEventHandler,
|
|
5
|
+
Double,
|
|
6
|
+
Float,
|
|
7
|
+
Int32,
|
|
8
|
+
} from 'react-native/Libraries/Types/CodegenTypes';
|
|
9
|
+
|
|
10
|
+
interface Point {
|
|
11
|
+
lat: Double;
|
|
12
|
+
lon: Double;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface NativeProps extends ViewProps {
|
|
16
|
+
fillColor?: ColorValue;
|
|
17
|
+
strokeColor?: ColorValue;
|
|
18
|
+
strokeWidth?: Float;
|
|
19
|
+
zInd?: Int32;
|
|
20
|
+
onCirclePress?: DirectEventHandler<Readonly<Point>>;
|
|
21
|
+
center: Point;
|
|
22
|
+
radius: Float;
|
|
23
|
+
handled?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type YamapLiteCircleViewComponent = HostComponent<NativeProps>;
|
|
27
|
+
|
|
28
|
+
export default codegenNativeComponent<NativeProps>('YamapLiteCircleView');
|