react-native-maplibre-lite 0.1.2 → 0.1.4
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/README.md +133 -45
- package/lib/module/components/MapView.js +55 -20
- package/lib/module/components/MapView.js.map +1 -1
- package/lib/module/components/webMapBuild.js +4 -0
- package/lib/module/components/webMapBuild.js.map +1 -0
- package/lib/typescript/src/components/MapView.d.ts +28 -2
- package/lib/typescript/src/components/MapView.d.ts.map +1 -1
- package/lib/typescript/src/components/types.d.ts +30 -5
- package/lib/typescript/src/components/types.d.ts.map +1 -1
- package/lib/typescript/src/components/webMapBuild.d.ts +2 -0
- package/lib/typescript/src/components/webMapBuild.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/components/MapView.tsx +72 -33
- package/src/components/types.ts +37 -6
- package/src/components/webMapBuild.ts +4 -0
- package/src/index.tsx +13 -1
- package/lib/module/components/webContent.js +0 -159
- package/lib/module/components/webContent.js.map +0 -1
- package/lib/module/components/webFunctions/addMarkerWeb.js +0 -83
- package/lib/module/components/webFunctions/addMarkerWeb.js.map +0 -1
- package/lib/module/components/webFunctions/addPolygonWeb.js +0 -62
- package/lib/module/components/webFunctions/addPolygonWeb.js.map +0 -1
- package/lib/module/components/webFunctions/addPolylineWeb.js +0 -48
- package/lib/module/components/webFunctions/addPolylineWeb.js.map +0 -1
- package/lib/module/components/webFunctions/fitBoundsWeb.js +0 -15
- package/lib/module/components/webFunctions/fitBoundsWeb.js.map +0 -1
- package/lib/module/components/webFunctions/flyToWeb.js +0 -14
- package/lib/module/components/webFunctions/flyToWeb.js.map +0 -1
- package/lib/module/components/webFunctions/initWeb.js +0 -158
- package/lib/module/components/webFunctions/initWeb.js.map +0 -1
- package/lib/module/components/webFunctions/removeMarkerWeb.js +0 -12
- package/lib/module/components/webFunctions/removeMarkerWeb.js.map +0 -1
- package/lib/module/components/webFunctions/removePolygonWeb.js +0 -22
- package/lib/module/components/webFunctions/removePolygonWeb.js.map +0 -1
- package/lib/module/components/webFunctions/removePolylineWeb.js +0 -17
- package/lib/module/components/webFunctions/removePolylineWeb.js.map +0 -1
- package/lib/module/components/webFunctions/updateWeb.js +0 -78
- package/lib/module/components/webFunctions/updateWeb.js.map +0 -1
- package/lib/typescript/src/components/webContent.d.ts +0 -3
- package/lib/typescript/src/components/webContent.d.ts.map +0 -1
- package/lib/typescript/src/components/webFunctions/addMarkerWeb.d.ts +0 -3
- package/lib/typescript/src/components/webFunctions/addMarkerWeb.d.ts.map +0 -1
- package/lib/typescript/src/components/webFunctions/addPolygonWeb.d.ts +0 -3
- package/lib/typescript/src/components/webFunctions/addPolygonWeb.d.ts.map +0 -1
- package/lib/typescript/src/components/webFunctions/addPolylineWeb.d.ts +0 -3
- package/lib/typescript/src/components/webFunctions/addPolylineWeb.d.ts.map +0 -1
- package/lib/typescript/src/components/webFunctions/fitBoundsWeb.d.ts +0 -3
- package/lib/typescript/src/components/webFunctions/fitBoundsWeb.d.ts.map +0 -1
- package/lib/typescript/src/components/webFunctions/flyToWeb.d.ts +0 -2
- package/lib/typescript/src/components/webFunctions/flyToWeb.d.ts.map +0 -1
- package/lib/typescript/src/components/webFunctions/initWeb.d.ts +0 -3
- package/lib/typescript/src/components/webFunctions/initWeb.d.ts.map +0 -1
- package/lib/typescript/src/components/webFunctions/removeMarkerWeb.d.ts +0 -3
- package/lib/typescript/src/components/webFunctions/removeMarkerWeb.d.ts.map +0 -1
- package/lib/typescript/src/components/webFunctions/removePolygonWeb.d.ts +0 -3
- package/lib/typescript/src/components/webFunctions/removePolygonWeb.d.ts.map +0 -1
- package/lib/typescript/src/components/webFunctions/removePolylineWeb.d.ts +0 -3
- package/lib/typescript/src/components/webFunctions/removePolylineWeb.d.ts.map +0 -1
- package/lib/typescript/src/components/webFunctions/updateWeb.d.ts +0 -3
- package/lib/typescript/src/components/webFunctions/updateWeb.d.ts.map +0 -1
- package/src/components/webContent.ts +0 -163
- package/src/components/webFunctions/addMarkerWeb.ts +0 -80
- package/src/components/webFunctions/addPolygonWeb.ts +0 -59
- package/src/components/webFunctions/addPolylineWeb.ts +0 -45
- package/src/components/webFunctions/fitBoundsWeb.ts +0 -12
- package/src/components/webFunctions/flyToWeb.ts +0 -11
- package/src/components/webFunctions/initWeb.ts +0 -155
- package/src/components/webFunctions/removeMarkerWeb.ts +0 -9
- package/src/components/webFunctions/removePolygonWeb.ts +0 -19
- package/src/components/webFunctions/removePolylineWeb.ts +0 -14
- package/src/components/webFunctions/updateWeb.ts +0 -75
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webMapBuild.d.ts","sourceRoot":"","sources":["../../../../src/components/webMapBuild.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,QAAQ,0+hzCAA4/4yC,CAAC"}
|
|
@@ -5,5 +5,5 @@ import { Polyline } from './components/Polyline';
|
|
|
5
5
|
export { MapView, Marker, Polygon, Polyline };
|
|
6
6
|
export default MapView;
|
|
7
7
|
export type { MapViewRef } from './components/MapView';
|
|
8
|
-
export type { MarkerProps,
|
|
8
|
+
export type { EventParams, MapLiteWebError, MarkerProps, NavigatorInstructionParams, NavigatorLang, NavigatorLngLat, NavigatorPositionMode, NavigatorPositionSetParams, NavigatorRouteSetParams, PolygonProps, PolylineProps, } from './components/types';
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AAC9C,eAAe,OAAO,CAAC;AAEvB,YAAY,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AAC9C,eAAe,OAAO,CAAC;AAEvB,YAAY,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,YAAY,EACR,WAAW,EACX,eAAe,EACf,WAAW,EACX,0BAA0B,EAC1B,aAAa,EACb,eAAe,EACf,qBAAqB,EACrB,0BAA0B,EAC1B,uBAAuB,EACvB,YAAY,EACZ,aAAa,GAChB,MAAM,oBAAoB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-maplibre-lite",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Lightweight MapLibre GL JS wrapper using WebView",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
@@ -98,7 +98,8 @@
|
|
|
98
98
|
"preset": "react-native",
|
|
99
99
|
"modulePathIgnorePatterns": [
|
|
100
100
|
"<rootDir>/example/node_modules",
|
|
101
|
-
"<rootDir>/lib/"
|
|
101
|
+
"<rootDir>/lib/",
|
|
102
|
+
"<rootDir>/webProject/"
|
|
102
103
|
]
|
|
103
104
|
},
|
|
104
105
|
"commitlint": {
|
|
@@ -20,23 +20,17 @@ import MapPlaceholder from './MapPlaceholder';
|
|
|
20
20
|
import MapSelectPoint, { type MapSelectPointType } from './MapSelectPoint';
|
|
21
21
|
import {
|
|
22
22
|
type EventParams,
|
|
23
|
+
type MapLiteWebError,
|
|
23
24
|
type MarkerProps,
|
|
25
|
+
type NavigatorInstructionParams,
|
|
26
|
+
type NavigatorLang,
|
|
27
|
+
type NavigatorPositionSetParams,
|
|
28
|
+
type NavigatorRouteSetParams,
|
|
24
29
|
type PolygonProps,
|
|
25
30
|
type PolylineProps,
|
|
26
|
-
type SourcesProps,
|
|
27
31
|
} from './types';
|
|
28
32
|
import { loadResources } from './utils';
|
|
29
|
-
import {
|
|
30
|
-
import addMarkerWeb from './webFunctions/addMarkerWeb';
|
|
31
|
-
import addPolygonWeb from './webFunctions/addPolygonWeb';
|
|
32
|
-
import addPolylineWeb from './webFunctions/addPolylineWeb';
|
|
33
|
-
import fitBoundsWeb from './webFunctions/fitBoundsWeb';
|
|
34
|
-
import { flyToWeb } from './webFunctions/flyToWeb';
|
|
35
|
-
import initWeb from './webFunctions/initWeb';
|
|
36
|
-
import removeMarkerWeb from './webFunctions/removeMarkerWeb';
|
|
37
|
-
import removePolygonWeb from './webFunctions/removePolygonWeb';
|
|
38
|
-
import removePolylineWeb from './webFunctions/removePolylineWeb';
|
|
39
|
-
import updateWeb from './webFunctions/updateWeb';
|
|
33
|
+
import { MAP_HTML } from './webMapBuild';
|
|
40
34
|
|
|
41
35
|
interface UpdateProps {
|
|
42
36
|
center?: [number, number];
|
|
@@ -81,12 +75,38 @@ interface MapViewProps {
|
|
|
81
75
|
pixelRatio?: number;
|
|
82
76
|
turboWhileMoving?: boolean;
|
|
83
77
|
|
|
84
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Включает режим навигатора в WebView (стрелка, маршрут GraphHopper, HUD).
|
|
80
|
+
* Должен совпадать с билдом `webMapBuild` / `MapLiteController`.
|
|
81
|
+
*/
|
|
82
|
+
navigator?: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Базовый URL GraphHopper для маршрутов навигатора (без обязательного `/route`).
|
|
85
|
+
* Нужен для `setNavigatorPoint` и пересчёта маршрута.
|
|
86
|
+
*/
|
|
87
|
+
graphhopperUrl?: string;
|
|
88
|
+
/** Язык HUD и инструкций навигатора. По умолчанию веб-часть использует `ru`. */
|
|
89
|
+
navigatorLang?: NavigatorLang;
|
|
90
|
+
onNavigatorRouteSet?: (params: NavigatorRouteSetParams) => void;
|
|
91
|
+
onNavigatorInstruction?: (params: NavigatorInstructionParams) => void;
|
|
92
|
+
onNavigatorPositionSet?: (params: NavigatorPositionSetParams) => void;
|
|
93
|
+
/** Ошибки команд WebView (`type: 'error'` из карты). */
|
|
94
|
+
onMapLiteError?: (err: MapLiteWebError) => void;
|
|
85
95
|
}
|
|
86
96
|
|
|
87
97
|
export type MapViewRef = {
|
|
88
98
|
fitBounds: () => void;
|
|
89
99
|
flyTo: (center: [number, number], zoom: number) => void;
|
|
100
|
+
/** Построить маршрут до точки (нужен `navigator: true` в MapView). */
|
|
101
|
+
setNavigatorPoint: (latitude: number, longitude: number) => void;
|
|
102
|
+
/** Следующая пошаговая инструкция (для отладки / ручного шага). */
|
|
103
|
+
advanceNavigatorInstruction: () => void;
|
|
104
|
+
/**
|
|
105
|
+
* Обновить «текущую позицию» (GPS): snap / reroute / прибытие — на стороне WebView.
|
|
106
|
+
*/
|
|
107
|
+
setNavigatorPosition: (latitude: number, longitude: number) => void;
|
|
108
|
+
/** Режим «клик по карте = новая позиция» (удобно в dev). */
|
|
109
|
+
pickNavigatorPosition: () => void;
|
|
90
110
|
};
|
|
91
111
|
|
|
92
112
|
type MapViewRegistry = {
|
|
@@ -106,19 +126,6 @@ export const useMapViewContext = () => {
|
|
|
106
126
|
return ctx;
|
|
107
127
|
};
|
|
108
128
|
|
|
109
|
-
const webFunctionsString = [
|
|
110
|
-
initWeb,
|
|
111
|
-
addMarkerWeb,
|
|
112
|
-
removeMarkerWeb,
|
|
113
|
-
addPolylineWeb,
|
|
114
|
-
removePolylineWeb,
|
|
115
|
-
addPolygonWeb,
|
|
116
|
-
removePolygonWeb,
|
|
117
|
-
fitBoundsWeb,
|
|
118
|
-
flyToWeb,
|
|
119
|
-
updateWeb
|
|
120
|
-
].join('\n');
|
|
121
|
-
|
|
122
129
|
const getBoundsFromCoords = (
|
|
123
130
|
coords: [number, number][]
|
|
124
131
|
): [[number, number], [number, number]] => {
|
|
@@ -147,7 +154,6 @@ const getBoundsFromCoords = (
|
|
|
147
154
|
export const MapView = forwardRef<MapViewRef, MapViewProps>((props, ref) => {
|
|
148
155
|
const webViewRef = useRef<WebView | null>(null);
|
|
149
156
|
const [inited, setInited] = useState(false);
|
|
150
|
-
const [html, setHtml] = useState('');
|
|
151
157
|
|
|
152
158
|
const coordsInMapRef = useRef<Record<string, [number, number][]>>({});
|
|
153
159
|
const markersClickHandlers = useRef<Record<string, () => void>>({});
|
|
@@ -193,6 +199,10 @@ export const MapView = forwardRef<MapViewRef, MapViewProps>((props, ref) => {
|
|
|
193
199
|
maxPitch: performanceMode === 'performance' ? 0 : 45,
|
|
194
200
|
renderWorldCopies: performanceMode === 'quality',
|
|
195
201
|
turboWhileMoving: props.turboWhileMoving ?? (performanceMode === 'performance'),
|
|
202
|
+
debugMode: props.debugMode ?? false,
|
|
203
|
+
navigator: props.navigator === true,
|
|
204
|
+
graphhopperUrl: props.graphhopperUrl,
|
|
205
|
+
navigatorLang: props.navigatorLang,
|
|
196
206
|
},
|
|
197
207
|
});
|
|
198
208
|
};
|
|
@@ -279,9 +289,29 @@ export const MapView = forwardRef<MapViewRef, MapViewProps>((props, ref) => {
|
|
|
279
289
|
sendToWebView({ function: 'flyTo', params: { center, zoom, duration: props.flyToDuration ?? 500 } });
|
|
280
290
|
};
|
|
281
291
|
|
|
292
|
+
const setNavigatorPoint = (latitude: number, longitude: number) => {
|
|
293
|
+
sendToWebView({ function: 'setNavigatorPoint', params: { latitude, longitude } });
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
const advanceNavigatorInstruction = () => {
|
|
297
|
+
sendToWebView({ function: 'advanceNavigatorInstruction', params: {} });
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
const setNavigatorPosition = (latitude: number, longitude: number) => {
|
|
301
|
+
sendToWebView({ function: 'setNavigatorPosition', params: { latitude, longitude } });
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
const pickNavigatorPosition = () => {
|
|
305
|
+
sendToWebView({ function: 'pickNavigatorPosition', params: {} });
|
|
306
|
+
};
|
|
307
|
+
|
|
282
308
|
useImperativeHandle(ref, () => ({
|
|
283
309
|
fitBounds,
|
|
284
310
|
flyTo,
|
|
311
|
+
setNavigatorPoint,
|
|
312
|
+
advanceNavigatorInstruction,
|
|
313
|
+
setNavigatorPosition,
|
|
314
|
+
pickNavigatorPosition,
|
|
285
315
|
}), [fitBounds]);
|
|
286
316
|
|
|
287
317
|
|
|
@@ -319,11 +349,6 @@ export const MapView = forwardRef<MapViewRef, MapViewProps>((props, ref) => {
|
|
|
319
349
|
}, [props.minZoom, props.maxZoom, props.zoomEnabled, props.scrollEnabled, props.mapStyle]);
|
|
320
350
|
|
|
321
351
|
|
|
322
|
-
useEffect(() => {
|
|
323
|
-
if (html) return;
|
|
324
|
-
maplibreHtmlMap(webFunctionsString, props.sources, props.debugMode ?? false).then(setHtml);
|
|
325
|
-
}, []);
|
|
326
|
-
|
|
327
352
|
const onReceiveMessageFromWebView = (data: string) => {
|
|
328
353
|
try {
|
|
329
354
|
const msg = JSON.parse(data);
|
|
@@ -351,10 +376,24 @@ export const MapView = forwardRef<MapViewRef, MapViewProps>((props, ref) => {
|
|
|
351
376
|
case 'idle':
|
|
352
377
|
props.onIdle?.(msg.params);
|
|
353
378
|
break;
|
|
379
|
+
case 'navigatorRouteSet':
|
|
380
|
+
props.onNavigatorRouteSet?.(msg.params as NavigatorRouteSetParams);
|
|
381
|
+
break;
|
|
382
|
+
case 'navigatorInstruction':
|
|
383
|
+
props.onNavigatorInstruction?.(msg.params as NavigatorInstructionParams);
|
|
384
|
+
break;
|
|
385
|
+
case 'navigatorPositionSet':
|
|
386
|
+
props.onNavigatorPositionSet?.(msg.params as NavigatorPositionSetParams);
|
|
387
|
+
break;
|
|
354
388
|
}
|
|
355
389
|
return;
|
|
356
390
|
}
|
|
357
391
|
|
|
392
|
+
if (msg.type === 'error' && msg.data) {
|
|
393
|
+
props.onMapLiteError?.(msg.data as MapLiteWebError);
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
|
|
358
397
|
if (msg.type === 'inited') {
|
|
359
398
|
props.onReady?.();
|
|
360
399
|
setInited(true);
|
|
@@ -398,7 +437,7 @@ export const MapView = forwardRef<MapViewRef, MapViewProps>((props, ref) => {
|
|
|
398
437
|
ref={webViewRef}
|
|
399
438
|
style={{ flex: 1, backgroundColor: 'transparent' }}
|
|
400
439
|
originWhitelist={['*']}
|
|
401
|
-
source={{ html }}
|
|
440
|
+
source={{ html: MAP_HTML }}
|
|
402
441
|
onMessage={event => {
|
|
403
442
|
onReceiveMessageFromWebView(event.nativeEvent.data);
|
|
404
443
|
}}
|
package/src/components/types.ts
CHANGED
|
@@ -14,12 +14,6 @@ export type MarkerProps = {
|
|
|
14
14
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export type SourcesProps = {
|
|
18
|
-
maplibreJS: string;
|
|
19
|
-
maplibreCSS: string;
|
|
20
|
-
pmtilesJS: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
17
|
export type PolygonProps = {
|
|
24
18
|
ignoreFitBounds?: boolean,
|
|
25
19
|
uniqueId: string,
|
|
@@ -47,4 +41,41 @@ export type EventParams = {
|
|
|
47
41
|
lat: number
|
|
48
42
|
},
|
|
49
43
|
zoom?: number
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export type NavigatorLang = 'ru' | 'en'
|
|
47
|
+
|
|
48
|
+
/** [longitude, latitude] — как в GeoJSON / GraphHopper. */
|
|
49
|
+
export type NavigatorLngLat = {
|
|
50
|
+
lng: number,
|
|
51
|
+
lat: number,
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type NavigatorRouteSetParams = {
|
|
55
|
+
destination: NavigatorLngLat,
|
|
56
|
+
distanceMeters?: number,
|
|
57
|
+
timeMs?: number,
|
|
58
|
+
pointsCount: number,
|
|
59
|
+
instructionsCount: number,
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export type NavigatorInstructionParams = {
|
|
63
|
+
text: string,
|
|
64
|
+
streetName?: string,
|
|
65
|
+
sign: number,
|
|
66
|
+
distance: number,
|
|
67
|
+
time: number,
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export type NavigatorPositionMode = 'noRoute' | 'arrived' | 'snapped' | 'rerouted'
|
|
71
|
+
|
|
72
|
+
export type NavigatorPositionSetParams = {
|
|
73
|
+
point: NavigatorLngLat,
|
|
74
|
+
mode: NavigatorPositionMode,
|
|
75
|
+
distanceFromRouteMeters: number,
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export type MapLiteWebError = {
|
|
79
|
+
target: string,
|
|
80
|
+
message: string,
|
|
50
81
|
}
|