react-native-maplibre-lite 0.1.3 → 0.1.5

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.
Files changed (73) hide show
  1. package/README.md +133 -45
  2. package/lib/module/components/MapView.js +58 -21
  3. package/lib/module/components/MapView.js.map +1 -1
  4. package/lib/module/components/webMapBuild.js +4 -0
  5. package/lib/module/components/webMapBuild.js.map +1 -0
  6. package/lib/typescript/src/components/MapView.d.ts +29 -2
  7. package/lib/typescript/src/components/MapView.d.ts.map +1 -1
  8. package/lib/typescript/src/components/types.d.ts +30 -5
  9. package/lib/typescript/src/components/types.d.ts.map +1 -1
  10. package/lib/typescript/src/components/webMapBuild.d.ts +2 -0
  11. package/lib/typescript/src/components/webMapBuild.d.ts.map +1 -0
  12. package/lib/typescript/src/index.d.ts +1 -1
  13. package/lib/typescript/src/index.d.ts.map +1 -1
  14. package/package.json +3 -2
  15. package/src/components/MapView.tsx +90 -48
  16. package/src/components/types.ts +37 -6
  17. package/src/components/webMapBuild.ts +4 -0
  18. package/src/index.tsx +13 -1
  19. package/lib/module/components/webContent.js +0 -159
  20. package/lib/module/components/webContent.js.map +0 -1
  21. package/lib/module/components/webFunctions/addMarkerWeb.js +0 -83
  22. package/lib/module/components/webFunctions/addMarkerWeb.js.map +0 -1
  23. package/lib/module/components/webFunctions/addPolygonWeb.js +0 -62
  24. package/lib/module/components/webFunctions/addPolygonWeb.js.map +0 -1
  25. package/lib/module/components/webFunctions/addPolylineWeb.js +0 -48
  26. package/lib/module/components/webFunctions/addPolylineWeb.js.map +0 -1
  27. package/lib/module/components/webFunctions/fitBoundsWeb.js +0 -15
  28. package/lib/module/components/webFunctions/fitBoundsWeb.js.map +0 -1
  29. package/lib/module/components/webFunctions/flyToWeb.js +0 -14
  30. package/lib/module/components/webFunctions/flyToWeb.js.map +0 -1
  31. package/lib/module/components/webFunctions/initWeb.js +0 -188
  32. package/lib/module/components/webFunctions/initWeb.js.map +0 -1
  33. package/lib/module/components/webFunctions/removeMarkerWeb.js +0 -12
  34. package/lib/module/components/webFunctions/removeMarkerWeb.js.map +0 -1
  35. package/lib/module/components/webFunctions/removePolygonWeb.js +0 -22
  36. package/lib/module/components/webFunctions/removePolygonWeb.js.map +0 -1
  37. package/lib/module/components/webFunctions/removePolylineWeb.js +0 -17
  38. package/lib/module/components/webFunctions/removePolylineWeb.js.map +0 -1
  39. package/lib/module/components/webFunctions/updateWeb.js +0 -78
  40. package/lib/module/components/webFunctions/updateWeb.js.map +0 -1
  41. package/lib/typescript/src/components/webContent.d.ts +0 -3
  42. package/lib/typescript/src/components/webContent.d.ts.map +0 -1
  43. package/lib/typescript/src/components/webFunctions/addMarkerWeb.d.ts +0 -3
  44. package/lib/typescript/src/components/webFunctions/addMarkerWeb.d.ts.map +0 -1
  45. package/lib/typescript/src/components/webFunctions/addPolygonWeb.d.ts +0 -3
  46. package/lib/typescript/src/components/webFunctions/addPolygonWeb.d.ts.map +0 -1
  47. package/lib/typescript/src/components/webFunctions/addPolylineWeb.d.ts +0 -3
  48. package/lib/typescript/src/components/webFunctions/addPolylineWeb.d.ts.map +0 -1
  49. package/lib/typescript/src/components/webFunctions/fitBoundsWeb.d.ts +0 -3
  50. package/lib/typescript/src/components/webFunctions/fitBoundsWeb.d.ts.map +0 -1
  51. package/lib/typescript/src/components/webFunctions/flyToWeb.d.ts +0 -2
  52. package/lib/typescript/src/components/webFunctions/flyToWeb.d.ts.map +0 -1
  53. package/lib/typescript/src/components/webFunctions/initWeb.d.ts +0 -3
  54. package/lib/typescript/src/components/webFunctions/initWeb.d.ts.map +0 -1
  55. package/lib/typescript/src/components/webFunctions/removeMarkerWeb.d.ts +0 -3
  56. package/lib/typescript/src/components/webFunctions/removeMarkerWeb.d.ts.map +0 -1
  57. package/lib/typescript/src/components/webFunctions/removePolygonWeb.d.ts +0 -3
  58. package/lib/typescript/src/components/webFunctions/removePolygonWeb.d.ts.map +0 -1
  59. package/lib/typescript/src/components/webFunctions/removePolylineWeb.d.ts +0 -3
  60. package/lib/typescript/src/components/webFunctions/removePolylineWeb.d.ts.map +0 -1
  61. package/lib/typescript/src/components/webFunctions/updateWeb.d.ts +0 -3
  62. package/lib/typescript/src/components/webFunctions/updateWeb.d.ts.map +0 -1
  63. package/src/components/webContent.ts +0 -163
  64. package/src/components/webFunctions/addMarkerWeb.ts +0 -80
  65. package/src/components/webFunctions/addPolygonWeb.ts +0 -59
  66. package/src/components/webFunctions/addPolylineWeb.ts +0 -45
  67. package/src/components/webFunctions/fitBoundsWeb.ts +0 -12
  68. package/src/components/webFunctions/flyToWeb.ts +0 -11
  69. package/src/components/webFunctions/initWeb.ts +0 -185
  70. package/src/components/webFunctions/removeMarkerWeb.ts +0 -9
  71. package/src/components/webFunctions/removePolygonWeb.ts +0 -19
  72. package/src/components/webFunctions/removePolylineWeb.ts +0 -14
  73. 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, PolygonProps, PolylineProps, EventParams, SourcesProps } from './components/types';
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,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
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",
3
+ "version": "0.1.5",
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": {
@@ -1,42 +1,36 @@
1
1
  import {
2
- createContext,
3
- forwardRef,
4
- useContext,
5
- useEffect,
6
- useImperativeHandle,
7
- useRef,
8
- useState,
2
+ createContext,
3
+ forwardRef,
4
+ useContext,
5
+ useEffect,
6
+ useImperativeHandle,
7
+ useRef,
8
+ useState,
9
9
  } from 'react';
10
10
 
11
11
  import {
12
- type StyleProp,
13
- Platform,
14
- View,
15
- type ViewStyle,
12
+ Platform,
13
+ type StyleProp,
14
+ View,
15
+ type ViewStyle,
16
16
  } from 'react-native';
17
17
  import { WebView } from 'react-native-webview';
18
18
 
19
19
  import MapPlaceholder from './MapPlaceholder';
20
20
  import MapSelectPoint, { type MapSelectPointType } from './MapSelectPoint';
21
21
  import {
22
- type EventParams,
23
- type MarkerProps,
24
- type PolygonProps,
25
- type PolylineProps,
26
- type SourcesProps,
22
+ type EventParams,
23
+ type MapLiteWebError,
24
+ type MarkerProps,
25
+ type NavigatorInstructionParams,
26
+ type NavigatorLang,
27
+ type NavigatorPositionSetParams,
28
+ type NavigatorRouteSetParams,
29
+ type PolygonProps,
30
+ type PolylineProps,
27
31
  } from './types';
28
32
  import { loadResources } from './utils';
29
- import { maplibreHtmlMap } from './webContent';
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,41 @@ interface MapViewProps {
81
75
  pixelRatio?: number;
82
76
  turboWhileMoving?: boolean;
83
77
 
84
- sources: SourcesProps;
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;
95
+
96
+
97
+ developerLocalhostBundleUrl?: string;
85
98
  }
86
99
 
87
100
  export type MapViewRef = {
88
101
  fitBounds: () => void;
89
102
  flyTo: (center: [number, number], zoom: number) => void;
103
+ /** Построить маршрут до точки (нужен `navigator: true` в MapView). */
104
+ setNavigatorPoint: (latitude: number, longitude: number) => void;
105
+ /** Следующая пошаговая инструкция (для отладки / ручного шага). */
106
+ advanceNavigatorInstruction: () => void;
107
+ /**
108
+ * Обновить «текущую позицию» (GPS): snap / reroute / прибытие — на стороне WebView.
109
+ */
110
+ setNavigatorPosition: (latitude: number, longitude: number) => void;
111
+ /** Режим «клик по карте = новая позиция» (удобно в dev). */
112
+ pickNavigatorPosition: () => void;
90
113
  };
91
114
 
92
115
  type MapViewRegistry = {
@@ -106,19 +129,6 @@ export const useMapViewContext = () => {
106
129
  return ctx;
107
130
  };
108
131
 
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
132
  const getBoundsFromCoords = (
123
133
  coords: [number, number][]
124
134
  ): [[number, number], [number, number]] => {
@@ -147,7 +157,6 @@ const getBoundsFromCoords = (
147
157
  export const MapView = forwardRef<MapViewRef, MapViewProps>((props, ref) => {
148
158
  const webViewRef = useRef<WebView | null>(null);
149
159
  const [inited, setInited] = useState(false);
150
- const [html, setHtml] = useState('');
151
160
 
152
161
  const coordsInMapRef = useRef<Record<string, [number, number][]>>({});
153
162
  const markersClickHandlers = useRef<Record<string, () => void>>({});
@@ -193,6 +202,10 @@ export const MapView = forwardRef<MapViewRef, MapViewProps>((props, ref) => {
193
202
  maxPitch: performanceMode === 'performance' ? 0 : 45,
194
203
  renderWorldCopies: performanceMode === 'quality',
195
204
  turboWhileMoving: props.turboWhileMoving ?? (performanceMode === 'performance'),
205
+ debugMode: props.debugMode ?? false,
206
+ navigator: props.navigator === true,
207
+ graphhopperUrl: props.graphhopperUrl,
208
+ navigatorLang: props.navigatorLang,
196
209
  },
197
210
  });
198
211
  };
@@ -279,9 +292,29 @@ export const MapView = forwardRef<MapViewRef, MapViewProps>((props, ref) => {
279
292
  sendToWebView({ function: 'flyTo', params: { center, zoom, duration: props.flyToDuration ?? 500 } });
280
293
  };
281
294
 
295
+ const setNavigatorPoint = (latitude: number, longitude: number) => {
296
+ sendToWebView({ function: 'setNavigatorPoint', params: { latitude, longitude } });
297
+ };
298
+
299
+ const advanceNavigatorInstruction = () => {
300
+ sendToWebView({ function: 'advanceNavigatorInstruction', params: {} });
301
+ };
302
+
303
+ const setNavigatorPosition = (latitude: number, longitude: number) => {
304
+ sendToWebView({ function: 'setNavigatorPosition', params: { latitude, longitude } });
305
+ };
306
+
307
+ const pickNavigatorPosition = () => {
308
+ sendToWebView({ function: 'pickNavigatorPosition', params: {} });
309
+ };
310
+
282
311
  useImperativeHandle(ref, () => ({
283
312
  fitBounds,
284
313
  flyTo,
314
+ setNavigatorPoint,
315
+ advanceNavigatorInstruction,
316
+ setNavigatorPosition,
317
+ pickNavigatorPosition,
285
318
  }), [fitBounds]);
286
319
 
287
320
 
@@ -319,11 +352,6 @@ export const MapView = forwardRef<MapViewRef, MapViewProps>((props, ref) => {
319
352
  }, [props.minZoom, props.maxZoom, props.zoomEnabled, props.scrollEnabled, props.mapStyle]);
320
353
 
321
354
 
322
- useEffect(() => {
323
- if (html) return;
324
- maplibreHtmlMap(webFunctionsString, props.sources, props.debugMode ?? false).then(setHtml);
325
- }, []);
326
-
327
355
  const onReceiveMessageFromWebView = (data: string) => {
328
356
  try {
329
357
  const msg = JSON.parse(data);
@@ -351,10 +379,24 @@ export const MapView = forwardRef<MapViewRef, MapViewProps>((props, ref) => {
351
379
  case 'idle':
352
380
  props.onIdle?.(msg.params);
353
381
  break;
382
+ case 'navigatorRouteSet':
383
+ props.onNavigatorRouteSet?.(msg.params as NavigatorRouteSetParams);
384
+ break;
385
+ case 'navigatorInstruction':
386
+ props.onNavigatorInstruction?.(msg.params as NavigatorInstructionParams);
387
+ break;
388
+ case 'navigatorPositionSet':
389
+ props.onNavigatorPositionSet?.(msg.params as NavigatorPositionSetParams);
390
+ break;
354
391
  }
355
392
  return;
356
393
  }
357
394
 
395
+ if (msg.type === 'error' && msg.data) {
396
+ props.onMapLiteError?.(msg.data as MapLiteWebError);
397
+ return;
398
+ }
399
+
358
400
  if (msg.type === 'inited') {
359
401
  props.onReady?.();
360
402
  setInited(true);
@@ -398,7 +440,7 @@ export const MapView = forwardRef<MapViewRef, MapViewProps>((props, ref) => {
398
440
  ref={webViewRef}
399
441
  style={{ flex: 1, backgroundColor: 'transparent' }}
400
442
  originWhitelist={['*']}
401
- source={{ html }}
443
+ source={!!props.developerLocalhostBundleUrl ? { uri: props.developerLocalhostBundleUrl } : { html: MAP_HTML }}
402
444
  onMessage={event => {
403
445
  onReceiveMessageFromWebView(event.nativeEvent.data);
404
446
  }}
@@ -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
  }