@granite-js/naver-map 1.0.0
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/CHANGELOG.md +7 -0
- package/GraniteNaverMap.podspec +81 -0
- package/android/build.gradle +160 -0
- package/android/gradle.properties +5 -0
- package/android/src/builtinProvider/java/run/granite/navermap/builtinProvider/BuiltInGraniteNaverMapProvider.kt +549 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/run/granite/navermap/GraniteNaverMapEvents.kt +91 -0
- package/android/src/main/java/run/granite/navermap/GraniteNaverMapPackage.kt +16 -0
- package/android/src/main/java/run/granite/navermap/GraniteNaverMapProvider.kt +242 -0
- package/android/src/main/java/run/granite/navermap/GraniteNaverMapRegistry.kt +116 -0
- package/android/src/main/java/run/granite/navermap/GraniteNaverMapView.kt +732 -0
- package/android/src/newarch/java/run/granite/navermap/GraniteNaverMapViewManager.kt +446 -0
- package/android/src/oldarch/java/run/granite/navermap/GraniteNaverMapViewManager.kt +249 -0
- package/dist/module/NaverMapView.js +110 -0
- package/dist/module/NaverMapView.js.map +1 -0
- package/dist/module/index.js +6 -0
- package/dist/module/index.js.map +1 -0
- package/dist/module/internals/colorUtils.js +624 -0
- package/dist/module/internals/colorUtils.js.map +1 -0
- package/dist/module/internals/context.js +8 -0
- package/dist/module/internals/context.js.map +1 -0
- package/dist/module/internals/id.js +10 -0
- package/dist/module/internals/id.js.map +1 -0
- package/dist/module/internals/useMapOverlay.js +44 -0
- package/dist/module/internals/useMapOverlay.js.map +1 -0
- package/dist/module/internals/usePreservedReference.js +36 -0
- package/dist/module/internals/usePreservedReference.js.map +1 -0
- package/dist/module/overlays/ArrowheadPath.js +37 -0
- package/dist/module/overlays/ArrowheadPath.js.map +1 -0
- package/dist/module/overlays/Circle.js +35 -0
- package/dist/module/overlays/Circle.js.map +1 -0
- package/dist/module/overlays/GroundOverlay.js +30 -0
- package/dist/module/overlays/GroundOverlay.js.map +1 -0
- package/dist/module/overlays/InfoWindow.js +32 -0
- package/dist/module/overlays/InfoWindow.js.map +1 -0
- package/dist/module/overlays/Marker.js +37 -0
- package/dist/module/overlays/Marker.js.map +1 -0
- package/dist/module/overlays/Path.js +41 -0
- package/dist/module/overlays/Path.js.map +1 -0
- package/dist/module/overlays/Polygon.js +51 -0
- package/dist/module/overlays/Polygon.js.map +1 -0
- package/dist/module/overlays/Polyline.js +60 -0
- package/dist/module/overlays/Polyline.js.map +1 -0
- package/dist/module/overlays/index.js +11 -0
- package/dist/module/overlays/index.js.map +1 -0
- package/dist/module/package.json +1 -0
- package/dist/module/specs/GraniteNaverMapViewNativeComponent.ts +352 -0
- package/dist/module/types/Coord.js +2 -0
- package/dist/module/types/Coord.js.map +1 -0
- package/dist/module/types/index.js +29 -0
- package/dist/module/types/index.js.map +1 -0
- package/dist/typescript/NaverMapView.d.ts +41 -0
- package/dist/typescript/index.d.ts +3 -0
- package/dist/typescript/internals/colorUtils.d.ts +10 -0
- package/dist/typescript/internals/context.d.ts +8 -0
- package/dist/typescript/internals/id.d.ts +1 -0
- package/dist/typescript/internals/useMapOverlay.d.ts +15 -0
- package/dist/typescript/internals/usePreservedReference.d.ts +6 -0
- package/dist/typescript/overlays/ArrowheadPath.d.ts +11 -0
- package/dist/typescript/overlays/Circle.d.ts +10 -0
- package/dist/typescript/overlays/GroundOverlay.d.ts +11 -0
- package/dist/typescript/overlays/InfoWindow.d.ts +14 -0
- package/dist/typescript/overlays/Marker.d.ts +16 -0
- package/dist/typescript/overlays/Path.d.ts +15 -0
- package/dist/typescript/overlays/Polygon.d.ts +10 -0
- package/dist/typescript/overlays/Polyline.d.ts +11 -0
- package/dist/typescript/overlays/index.d.ts +16 -0
- package/dist/typescript/specs/GraniteNaverMapViewNativeComponent.d.ts +92 -0
- package/dist/typescript/types/Coord.d.ts +4 -0
- package/dist/typescript/types/index.d.ts +55 -0
- package/ios/GraniteNaverMap-Bridging-Header.h +20 -0
- package/ios/GraniteNaverMapProvider.swift +312 -0
- package/ios/GraniteNaverMapRegistry.swift +91 -0
- package/ios/GraniteNaverMapView.h +15 -0
- package/ios/GraniteNaverMapView.mm +390 -0
- package/ios/GraniteNaverMapViewImpl.swift +496 -0
- package/ios/GraniteNaverMapViewManager.m +67 -0
- package/ios/GraniteNaverMapViewManager.swift +133 -0
- package/ios/GraniteNaverMapViewWrapper.swift +215 -0
- package/ios/builtinProvider/BuiltInNaverMapProvider.swift +489 -0
- package/ios/builtinProvider/GraniteNaverMapMarkerData.swift +66 -0
- package/ios/builtinProvider/NMFMarker+Extension.swift +65 -0
- package/ios/builtinProvider/RCTConvert+NMFMapView.h +17 -0
- package/ios/builtinProvider/RCTConvert+NMFMapView.m +67 -0
- package/package.json +103 -0
- package/src/NaverMapView.tsx +168 -0
- package/src/index.tsx +3 -0
- package/src/internals/colorUtils.ts +697 -0
- package/src/internals/context.ts +14 -0
- package/src/internals/id.ts +9 -0
- package/src/internals/useMapOverlay.ts +59 -0
- package/src/internals/usePreservedReference.ts +41 -0
- package/src/overlays/ArrowheadPath.ts +71 -0
- package/src/overlays/Circle.ts +68 -0
- package/src/overlays/GroundOverlay.ts +62 -0
- package/src/overlays/InfoWindow.ts +68 -0
- package/src/overlays/Marker.ts +83 -0
- package/src/overlays/Path.ts +87 -0
- package/src/overlays/Polygon.ts +83 -0
- package/src/overlays/Polyline.ts +93 -0
- package/src/overlays/index.ts +23 -0
- package/src/specs/GraniteNaverMapViewNativeComponent.ts +352 -0
- package/src/types/Coord.ts +4 -0
- package/src/types/index.ts +78 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useEffect, useLayoutEffect } from 'react';
|
|
2
|
+
import type { View } from 'react-native';
|
|
3
|
+
import { type MapContextValue, useMapContext } from './context';
|
|
4
|
+
import { useOverlayId } from './id';
|
|
5
|
+
|
|
6
|
+
interface MapOverlayProps<EventListeners, Props> {
|
|
7
|
+
registrySelector: (c: MapContextValue) => Map<string, Partial<EventListeners>>;
|
|
8
|
+
methods: MapOverlayMethods<Props>;
|
|
9
|
+
props: Props;
|
|
10
|
+
eventListeners: Partial<EventListeners>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface MapOverlayMethods<Props> {
|
|
14
|
+
add: (v: View, id: string, args: Props) => void;
|
|
15
|
+
update: (v: View, id: string, args: Props) => void;
|
|
16
|
+
remove: (v: View, id: string) => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function useMapOverlay<EventListeners, Props>({
|
|
20
|
+
props,
|
|
21
|
+
eventListeners,
|
|
22
|
+
methods,
|
|
23
|
+
registrySelector,
|
|
24
|
+
}: MapOverlayProps<EventListeners, Props>) {
|
|
25
|
+
const id = useOverlayId();
|
|
26
|
+
const mapContext = useMapContext();
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (!mapContext) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const registry = registrySelector(mapContext);
|
|
34
|
+
registry.set(id, eventListeners);
|
|
35
|
+
return () => {
|
|
36
|
+
registry.delete(id);
|
|
37
|
+
};
|
|
38
|
+
}, [id, mapContext, registrySelector, eventListeners]);
|
|
39
|
+
|
|
40
|
+
useLayoutEffect(() => {
|
|
41
|
+
console.log('[useMapOverlay] useLayoutEffect - mapContext:', mapContext ? 'exists' : 'null', 'id:', id);
|
|
42
|
+
if (!mapContext) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const { mapView } = mapContext;
|
|
47
|
+
console.log('[useMapOverlay] calling methods.add for id:', id);
|
|
48
|
+
methods.add(mapView, id, props);
|
|
49
|
+
return () => methods.remove(mapView, id);
|
|
50
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
51
|
+
}, [id, mapContext, methods]);
|
|
52
|
+
|
|
53
|
+
useLayoutEffect(() => {
|
|
54
|
+
if (!mapContext) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
methods.update(mapContext.mapView, id, props);
|
|
58
|
+
}, [id, mapContext, methods, props]);
|
|
59
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns a memoized reference that only changes when the object's content changes.
|
|
5
|
+
* This is useful for preventing unnecessary re-renders when object references change
|
|
6
|
+
* but the content remains the same.
|
|
7
|
+
*/
|
|
8
|
+
export function usePreservedReference<T>(value: T): T {
|
|
9
|
+
const ref = useRef<T>(value);
|
|
10
|
+
|
|
11
|
+
if (!shallowEqual(ref.current, value)) {
|
|
12
|
+
ref.current = value;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return ref.current;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function shallowEqual<T>(a: T, b: T): boolean {
|
|
19
|
+
if (a === b) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const keysA = Object.keys(a) as (keyof T)[];
|
|
28
|
+
const keysB = Object.keys(b) as (keyof T)[];
|
|
29
|
+
|
|
30
|
+
if (keysA.length !== keysB.length) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
for (const key of keysA) {
|
|
35
|
+
if (a[key] !== b[key]) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { type View } from 'react-native';
|
|
2
|
+
import { processColorInput } from '../internals/colorUtils';
|
|
3
|
+
import { useMapOverlay } from '../internals/useMapOverlay';
|
|
4
|
+
import { usePreservedReference } from '../internals/usePreservedReference';
|
|
5
|
+
import { Commands } from '../specs/GraniteNaverMapViewNativeComponent';
|
|
6
|
+
import type { Coord } from '../types/Coord';
|
|
7
|
+
|
|
8
|
+
export interface ArrowheadPathProps {
|
|
9
|
+
coordinates: Coord[];
|
|
10
|
+
color?: number | string;
|
|
11
|
+
outlineColor?: number | string;
|
|
12
|
+
width?: number;
|
|
13
|
+
outlineWidth?: number;
|
|
14
|
+
headSizeRatio?: number;
|
|
15
|
+
zIndex?: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const add = (v: View, id: string, args: ArrowheadPathProps) => {
|
|
19
|
+
const color = processColorInput(args.color, 0xff000000);
|
|
20
|
+
const outlineColor = processColorInput(args.outlineColor, 0xffffffff);
|
|
21
|
+
const coordsJson = JSON.stringify(args.coordinates);
|
|
22
|
+
|
|
23
|
+
Commands.addArrowheadPath(
|
|
24
|
+
v as any,
|
|
25
|
+
id,
|
|
26
|
+
coordsJson,
|
|
27
|
+
args.width ?? 5,
|
|
28
|
+
args.outlineWidth ?? 1,
|
|
29
|
+
color,
|
|
30
|
+
outlineColor,
|
|
31
|
+
args.headSizeRatio ?? 3,
|
|
32
|
+
args.zIndex ?? 0
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const update = (v: View, id: string, args: ArrowheadPathProps) => {
|
|
37
|
+
const color = processColorInput(args.color, 0xff000000);
|
|
38
|
+
const outlineColor = processColorInput(args.outlineColor, 0xffffffff);
|
|
39
|
+
const coordsJson = JSON.stringify(args.coordinates);
|
|
40
|
+
|
|
41
|
+
Commands.updateArrowheadPath(
|
|
42
|
+
v as any,
|
|
43
|
+
id,
|
|
44
|
+
coordsJson,
|
|
45
|
+
args.width ?? 5,
|
|
46
|
+
args.outlineWidth ?? 1,
|
|
47
|
+
color,
|
|
48
|
+
outlineColor,
|
|
49
|
+
args.headSizeRatio ?? 3,
|
|
50
|
+
args.zIndex ?? 0
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const remove = (v: View, id: string) => {
|
|
55
|
+
Commands.removeArrowheadPath(v as any, id);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const methods = { add, update, remove };
|
|
59
|
+
|
|
60
|
+
export function ArrowheadPath(props: ArrowheadPathProps) {
|
|
61
|
+
const preserved = usePreservedReference(props);
|
|
62
|
+
|
|
63
|
+
useMapOverlay<object, ArrowheadPathProps>({
|
|
64
|
+
registrySelector: (c) => c.markers,
|
|
65
|
+
methods,
|
|
66
|
+
props: preserved,
|
|
67
|
+
eventListeners: {},
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { type View } from 'react-native';
|
|
2
|
+
import { processColorInput } from '../internals/colorUtils';
|
|
3
|
+
import { useMapOverlay } from '../internals/useMapOverlay';
|
|
4
|
+
import { usePreservedReference } from '../internals/usePreservedReference';
|
|
5
|
+
import { Commands } from '../specs/GraniteNaverMapViewNativeComponent';
|
|
6
|
+
import type { Coord } from '../types/Coord';
|
|
7
|
+
|
|
8
|
+
export interface CircleProps {
|
|
9
|
+
center: Coord;
|
|
10
|
+
radius: number;
|
|
11
|
+
fillColor?: number | string;
|
|
12
|
+
strokeColor?: number | string;
|
|
13
|
+
strokeWidth?: number;
|
|
14
|
+
zIndex?: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const add = (v: View, id: string, args: CircleProps) => {
|
|
18
|
+
const fillColor = processColorInput(args.fillColor, 0x80000000);
|
|
19
|
+
const strokeColor = processColorInput(args.strokeColor, 0xff000000);
|
|
20
|
+
|
|
21
|
+
Commands.addCircle(
|
|
22
|
+
v as any,
|
|
23
|
+
id,
|
|
24
|
+
args.center.latitude,
|
|
25
|
+
args.center.longitude,
|
|
26
|
+
args.radius,
|
|
27
|
+
fillColor,
|
|
28
|
+
strokeColor,
|
|
29
|
+
args.strokeWidth ?? 0,
|
|
30
|
+
args.zIndex ?? 0
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const update = (v: View, id: string, args: CircleProps) => {
|
|
35
|
+
const fillColor = processColorInput(args.fillColor, 0x80000000);
|
|
36
|
+
const strokeColor = processColorInput(args.strokeColor, 0xff000000);
|
|
37
|
+
|
|
38
|
+
Commands.updateCircle(
|
|
39
|
+
v as any,
|
|
40
|
+
id,
|
|
41
|
+
args.center.latitude,
|
|
42
|
+
args.center.longitude,
|
|
43
|
+
args.radius,
|
|
44
|
+
fillColor,
|
|
45
|
+
strokeColor,
|
|
46
|
+
args.strokeWidth ?? 0,
|
|
47
|
+
args.zIndex ?? 0
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const remove = (v: View, id: string) => {
|
|
52
|
+
Commands.removeCircle(v as any, id);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const methods = { add, update, remove };
|
|
56
|
+
|
|
57
|
+
export function Circle(props: CircleProps) {
|
|
58
|
+
const preserved = usePreservedReference(props);
|
|
59
|
+
|
|
60
|
+
useMapOverlay<object, CircleProps>({
|
|
61
|
+
registrySelector: (c) => c.markers,
|
|
62
|
+
methods,
|
|
63
|
+
props: preserved,
|
|
64
|
+
eventListeners: {},
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type View } from 'react-native';
|
|
2
|
+
import { useMapOverlay } from '../internals/useMapOverlay';
|
|
3
|
+
import { usePreservedReference } from '../internals/usePreservedReference';
|
|
4
|
+
import { Commands } from '../specs/GraniteNaverMapViewNativeComponent';
|
|
5
|
+
import type { Coord } from '../types/Coord';
|
|
6
|
+
|
|
7
|
+
export interface GroundOverlayProps {
|
|
8
|
+
bounds: {
|
|
9
|
+
northEast: Coord;
|
|
10
|
+
southWest: Coord;
|
|
11
|
+
};
|
|
12
|
+
image: string;
|
|
13
|
+
alpha?: number;
|
|
14
|
+
zIndex?: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const add = (v: View, id: string, args: GroundOverlayProps) => {
|
|
18
|
+
Commands.addGroundOverlay(
|
|
19
|
+
v as any,
|
|
20
|
+
id,
|
|
21
|
+
args.bounds.southWest.latitude,
|
|
22
|
+
args.bounds.southWest.longitude,
|
|
23
|
+
args.bounds.northEast.latitude,
|
|
24
|
+
args.bounds.northEast.longitude,
|
|
25
|
+
args.image,
|
|
26
|
+
args.alpha ?? 1,
|
|
27
|
+
args.zIndex ?? 0
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const update = (v: View, id: string, args: GroundOverlayProps) => {
|
|
32
|
+
Commands.updateGroundOverlay(
|
|
33
|
+
v as any,
|
|
34
|
+
id,
|
|
35
|
+
args.bounds.southWest.latitude,
|
|
36
|
+
args.bounds.southWest.longitude,
|
|
37
|
+
args.bounds.northEast.latitude,
|
|
38
|
+
args.bounds.northEast.longitude,
|
|
39
|
+
args.image,
|
|
40
|
+
args.alpha ?? 1,
|
|
41
|
+
args.zIndex ?? 0
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const remove = (v: View, id: string) => {
|
|
46
|
+
Commands.removeGroundOverlay(v as any, id);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const methods = { add, update, remove };
|
|
50
|
+
|
|
51
|
+
export function GroundOverlay(props: GroundOverlayProps) {
|
|
52
|
+
const preserved = usePreservedReference(props);
|
|
53
|
+
|
|
54
|
+
useMapOverlay<object, GroundOverlayProps>({
|
|
55
|
+
registrySelector: (c) => c.markers,
|
|
56
|
+
methods,
|
|
57
|
+
props: preserved,
|
|
58
|
+
eventListeners: {},
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { type View } from 'react-native';
|
|
2
|
+
import { useMapOverlay } from '../internals/useMapOverlay';
|
|
3
|
+
import { usePreservedReference } from '../internals/usePreservedReference';
|
|
4
|
+
import { Commands } from '../specs/GraniteNaverMapViewNativeComponent';
|
|
5
|
+
import type { Coord } from '../types/Coord';
|
|
6
|
+
|
|
7
|
+
export interface InfoWindowProps {
|
|
8
|
+
coordinate: Coord;
|
|
9
|
+
text: string;
|
|
10
|
+
alpha?: number;
|
|
11
|
+
zIndex?: number;
|
|
12
|
+
offsetX?: number;
|
|
13
|
+
offsetY?: number;
|
|
14
|
+
onPress?: () => void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface InfoWindowEventListeners {
|
|
18
|
+
onPress?: () => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const add = (v: View, id: string, args: InfoWindowProps) => {
|
|
22
|
+
Commands.addInfoWindow(
|
|
23
|
+
v as any,
|
|
24
|
+
id,
|
|
25
|
+
args.coordinate.latitude,
|
|
26
|
+
args.coordinate.longitude,
|
|
27
|
+
args.text,
|
|
28
|
+
args.alpha ?? 1,
|
|
29
|
+
args.zIndex ?? 0,
|
|
30
|
+
args.offsetX ?? 0,
|
|
31
|
+
args.offsetY ?? 0
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const update = (v: View, id: string, args: InfoWindowProps) => {
|
|
36
|
+
Commands.updateInfoWindow(
|
|
37
|
+
v as any,
|
|
38
|
+
id,
|
|
39
|
+
args.coordinate.latitude,
|
|
40
|
+
args.coordinate.longitude,
|
|
41
|
+
args.text,
|
|
42
|
+
args.alpha ?? 1,
|
|
43
|
+
args.zIndex ?? 0,
|
|
44
|
+
args.offsetX ?? 0,
|
|
45
|
+
args.offsetY ?? 0
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const remove = (v: View, id: string) => {
|
|
50
|
+
Commands.removeInfoWindow(v as any, id);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const methods = { add, update, remove };
|
|
54
|
+
|
|
55
|
+
export function InfoWindow(props: InfoWindowProps) {
|
|
56
|
+
const preserved = usePreservedReference(props);
|
|
57
|
+
|
|
58
|
+
useMapOverlay<InfoWindowEventListeners, InfoWindowProps>({
|
|
59
|
+
registrySelector: (c) => c.markers,
|
|
60
|
+
methods,
|
|
61
|
+
props: preserved,
|
|
62
|
+
eventListeners: {
|
|
63
|
+
onPress: props.onPress,
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { type View } from 'react-native';
|
|
2
|
+
import { processColorInput } from '../internals/colorUtils';
|
|
3
|
+
import { useMapOverlay } from '../internals/useMapOverlay';
|
|
4
|
+
import { usePreservedReference } from '../internals/usePreservedReference';
|
|
5
|
+
import { Commands } from '../specs/GraniteNaverMapViewNativeComponent';
|
|
6
|
+
import type { Coord } from '../types/Coord';
|
|
7
|
+
|
|
8
|
+
export interface MarkerProps extends MarkerEventListeners {
|
|
9
|
+
coordinate: Coord;
|
|
10
|
+
pinColor?: number | string;
|
|
11
|
+
image?: string;
|
|
12
|
+
rotation?: number;
|
|
13
|
+
flat?: boolean;
|
|
14
|
+
width?: number;
|
|
15
|
+
height?: number;
|
|
16
|
+
alpha?: number;
|
|
17
|
+
zIndex?: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface MarkerEventListeners {
|
|
21
|
+
onPress?: () => void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const add = (v: View, id: string, args: MarkerProps) => {
|
|
25
|
+
// pinColor: 0 means use default icon, otherwise process the color
|
|
26
|
+
const pinColor = args.pinColor != null ? processColorInput(args.pinColor, 0) : 0;
|
|
27
|
+
|
|
28
|
+
Commands.addMarker(
|
|
29
|
+
v as any,
|
|
30
|
+
id,
|
|
31
|
+
args.coordinate.latitude,
|
|
32
|
+
args.coordinate.longitude,
|
|
33
|
+
args.width ?? 0,
|
|
34
|
+
args.height ?? 0,
|
|
35
|
+
args.zIndex ?? 0,
|
|
36
|
+
args.rotation ?? 0,
|
|
37
|
+
args.flat ?? false,
|
|
38
|
+
args.alpha ?? 1,
|
|
39
|
+
pinColor,
|
|
40
|
+
args.image ?? ''
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const update = (v: View, id: string, args: MarkerProps) => {
|
|
45
|
+
// pinColor: 0 means use default icon, otherwise process the color
|
|
46
|
+
const pinColor = args.pinColor != null ? processColorInput(args.pinColor, 0) : 0;
|
|
47
|
+
|
|
48
|
+
Commands.updateMarker(
|
|
49
|
+
v as any,
|
|
50
|
+
id,
|
|
51
|
+
args.coordinate.latitude,
|
|
52
|
+
args.coordinate.longitude,
|
|
53
|
+
args.width ?? 0,
|
|
54
|
+
args.height ?? 0,
|
|
55
|
+
args.zIndex ?? 0,
|
|
56
|
+
args.rotation ?? 0,
|
|
57
|
+
args.flat ?? false,
|
|
58
|
+
args.alpha ?? 1,
|
|
59
|
+
pinColor,
|
|
60
|
+
args.image ?? ''
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const remove = (v: View, id: string) => {
|
|
65
|
+
Commands.removeMarker(v as any, id);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const methods = { add, update, remove };
|
|
69
|
+
|
|
70
|
+
export function Marker(props: MarkerProps) {
|
|
71
|
+
const preserved = usePreservedReference(props);
|
|
72
|
+
|
|
73
|
+
useMapOverlay<MarkerEventListeners, MarkerProps>({
|
|
74
|
+
registrySelector: (c) => c.markers,
|
|
75
|
+
methods,
|
|
76
|
+
props: preserved,
|
|
77
|
+
eventListeners: {
|
|
78
|
+
onPress: props.onPress,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { type View } from 'react-native';
|
|
2
|
+
import { processColorInput } from '../internals/colorUtils';
|
|
3
|
+
import { useMapOverlay } from '../internals/useMapOverlay';
|
|
4
|
+
import { usePreservedReference } from '../internals/usePreservedReference';
|
|
5
|
+
import { Commands } from '../specs/GraniteNaverMapViewNativeComponent';
|
|
6
|
+
import type { Coord } from '../types/Coord';
|
|
7
|
+
|
|
8
|
+
export interface PathProps {
|
|
9
|
+
coordinates: Coord[];
|
|
10
|
+
color?: number | string;
|
|
11
|
+
outlineColor?: number | string;
|
|
12
|
+
passedColor?: number | string;
|
|
13
|
+
passedOutlineColor?: number | string;
|
|
14
|
+
width?: number;
|
|
15
|
+
outlineWidth?: number;
|
|
16
|
+
patternImage?: string;
|
|
17
|
+
patternInterval?: number;
|
|
18
|
+
progress?: number;
|
|
19
|
+
zIndex?: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const add = (v: View, id: string, args: PathProps) => {
|
|
23
|
+
const color = processColorInput(args.color, 0xff000000);
|
|
24
|
+
const outlineColor = processColorInput(args.outlineColor, 0xffffffff);
|
|
25
|
+
const passedColor = processColorInput(args.passedColor, 0xff808080);
|
|
26
|
+
const passedOutlineColor = processColorInput(args.passedOutlineColor, 0xffffffff);
|
|
27
|
+
const coordsJson = JSON.stringify(args.coordinates);
|
|
28
|
+
|
|
29
|
+
Commands.addPath(
|
|
30
|
+
v as any,
|
|
31
|
+
id,
|
|
32
|
+
coordsJson,
|
|
33
|
+
args.width ?? 5,
|
|
34
|
+
args.outlineWidth ?? 1,
|
|
35
|
+
color,
|
|
36
|
+
outlineColor,
|
|
37
|
+
passedColor,
|
|
38
|
+
passedOutlineColor,
|
|
39
|
+
args.patternImage ?? '',
|
|
40
|
+
args.patternInterval ?? 0,
|
|
41
|
+
args.progress ?? 0,
|
|
42
|
+
args.zIndex ?? 0
|
|
43
|
+
);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const update = (v: View, id: string, args: PathProps) => {
|
|
47
|
+
const color = processColorInput(args.color, 0xff000000);
|
|
48
|
+
const outlineColor = processColorInput(args.outlineColor, 0xffffffff);
|
|
49
|
+
const passedColor = processColorInput(args.passedColor, 0xff808080);
|
|
50
|
+
const passedOutlineColor = processColorInput(args.passedOutlineColor, 0xffffffff);
|
|
51
|
+
const coordsJson = JSON.stringify(args.coordinates);
|
|
52
|
+
|
|
53
|
+
Commands.updatePath(
|
|
54
|
+
v as any,
|
|
55
|
+
id,
|
|
56
|
+
coordsJson,
|
|
57
|
+
args.width ?? 5,
|
|
58
|
+
args.outlineWidth ?? 1,
|
|
59
|
+
color,
|
|
60
|
+
outlineColor,
|
|
61
|
+
passedColor,
|
|
62
|
+
passedOutlineColor,
|
|
63
|
+
args.patternImage ?? '',
|
|
64
|
+
args.patternInterval ?? 0,
|
|
65
|
+
args.progress ?? 0,
|
|
66
|
+
args.zIndex ?? 0
|
|
67
|
+
);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const remove = (v: View, id: string) => {
|
|
71
|
+
Commands.removePath(v as any, id);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const methods = { add, update, remove };
|
|
75
|
+
|
|
76
|
+
export function Path(props: PathProps) {
|
|
77
|
+
const preserved = usePreservedReference(props);
|
|
78
|
+
|
|
79
|
+
useMapOverlay<object, PathProps>({
|
|
80
|
+
registrySelector: (c) => c.markers,
|
|
81
|
+
methods,
|
|
82
|
+
props: preserved,
|
|
83
|
+
eventListeners: {},
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { type View } from 'react-native';
|
|
2
|
+
import { processColorInput } from '../internals/colorUtils';
|
|
3
|
+
import { useMapOverlay } from '../internals/useMapOverlay';
|
|
4
|
+
import { usePreservedReference } from '../internals/usePreservedReference';
|
|
5
|
+
import { Commands } from '../specs/GraniteNaverMapViewNativeComponent';
|
|
6
|
+
import type { Coord } from '../types/Coord';
|
|
7
|
+
|
|
8
|
+
export interface PolygonProps {
|
|
9
|
+
coordinates: Coord[];
|
|
10
|
+
holes?: Coord[][];
|
|
11
|
+
fillColor?: number | string;
|
|
12
|
+
strokeColor?: number | string;
|
|
13
|
+
strokeWidth?: number;
|
|
14
|
+
zIndex?: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Close the ring by adding the first coordinate at the end if not already closed
|
|
18
|
+
const closeRing = (coords: Coord[]): Coord[] => {
|
|
19
|
+
if (coords.length < 3) {
|
|
20
|
+
return coords;
|
|
21
|
+
}
|
|
22
|
+
const first = coords[0]!;
|
|
23
|
+
const last = coords[coords.length - 1]!;
|
|
24
|
+
if (first.latitude === last.latitude && first.longitude === last.longitude) {
|
|
25
|
+
return coords; // Already closed
|
|
26
|
+
}
|
|
27
|
+
return [...coords, first];
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const add = (v: View, id: string, args: PolygonProps) => {
|
|
31
|
+
const fillColor = processColorInput(args.fillColor, 0x80000000);
|
|
32
|
+
const strokeColor = processColorInput(args.strokeColor, 0xff000000);
|
|
33
|
+
const coordsJson = JSON.stringify(closeRing(args.coordinates));
|
|
34
|
+
const holesJson = JSON.stringify((args.holes ?? []).map(closeRing));
|
|
35
|
+
|
|
36
|
+
Commands.addPolygon(
|
|
37
|
+
v as any,
|
|
38
|
+
id,
|
|
39
|
+
coordsJson,
|
|
40
|
+
holesJson,
|
|
41
|
+
fillColor,
|
|
42
|
+
strokeColor,
|
|
43
|
+
args.strokeWidth ?? 0,
|
|
44
|
+
args.zIndex ?? 0
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const update = (v: View, id: string, args: PolygonProps) => {
|
|
49
|
+
const fillColor = processColorInput(args.fillColor, 0x80000000);
|
|
50
|
+
const strokeColor = processColorInput(args.strokeColor, 0xff000000);
|
|
51
|
+
const coordsJson = JSON.stringify(closeRing(args.coordinates));
|
|
52
|
+
const holesJson = JSON.stringify((args.holes ?? []).map(closeRing));
|
|
53
|
+
|
|
54
|
+
Commands.updatePolygon(
|
|
55
|
+
v as any,
|
|
56
|
+
id,
|
|
57
|
+
coordsJson,
|
|
58
|
+
holesJson,
|
|
59
|
+
fillColor,
|
|
60
|
+
strokeColor,
|
|
61
|
+
args.strokeWidth ?? 0,
|
|
62
|
+
args.zIndex ?? 0
|
|
63
|
+
);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const remove = (v: View, id: string) => {
|
|
67
|
+
Commands.removePolygon(v as any, id);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const methods = { add, update, remove };
|
|
71
|
+
|
|
72
|
+
export function Polygon(props: PolygonProps) {
|
|
73
|
+
const preserved = usePreservedReference(props);
|
|
74
|
+
|
|
75
|
+
useMapOverlay<object, PolygonProps>({
|
|
76
|
+
registrySelector: (c) => c.markers,
|
|
77
|
+
methods,
|
|
78
|
+
props: preserved,
|
|
79
|
+
eventListeners: {},
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
return null;
|
|
83
|
+
}
|