react-native-maplibre-lite 0.1.9 → 0.2.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.
@@ -1 +1 @@
1
- {"version":3,"file":"webMapBuild.d.ts","sourceRoot":"","sources":["../../../../src/components/webMapBuild.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,QAAQ,yxtzCAA68jzC,CAAC"}
1
+ {"version":3,"file":"webMapBuild.d.ts","sourceRoot":"","sources":["../../../../src/components/webMapBuild.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,QAAQ,y/6zCAA6qxzC,CAAC"}
@@ -5,6 +5,6 @@ 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 { EventParams, MapLiteWebError, MarkerProps, NavigatorChromeParams, NavigatorInstructionParams, NavigatorLang, NavigatorLngLat, NavigatorProfile, NavigatorPositionMode, NavigatorPositionSetParams, NavigatorRouteSetParams, PolygonProps, PolylineProps, } from './components/types';
8
+ export type { EventParams, MapLiteFitBoundsParams, MapLiteFlyToParams, MapLiteInitParams, MapLiteMapErrorEventParams, MapLiteMapEventName, MapLiteSetNavigatorPointParams, MapLiteSetNavigatorPositionParams, MapLiteStyleSpecification, MapLiteUpdateParams, MapLiteWebError, MarkerProps, NativeToWebCommand, NavigatorChromeParams, NavigatorInstructionParams, NavigatorLang, NavigatorLngLat, NavigatorProfile, NavigatorPositionMode, NavigatorPositionSetParams, NavigatorRouteSetParams, PolygonProps, PolylineProps, WebToNativeMessage, } from './components/types';
9
9
  export { NAVIGATOR_PROFILE_IDS } from './components/types';
10
10
  //# 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,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,qBAAqB,EACrB,0BAA0B,EAC1B,uBAAuB,EACvB,YAAY,EACZ,aAAa,EACb,kBAAkB,GACrB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-maplibre-lite",
3
- "version": "0.1.9",
3
+ "version": "0.2.0",
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",
@@ -23,8 +23,12 @@ import MapPlaceholder from './MapPlaceholder';
23
23
  import MapSelectPoint, { type MapSelectPointType } from './MapSelectPoint';
24
24
  import {
25
25
  type EventParams,
26
+ type MapLiteInitParams,
27
+ type MapLiteSetNavigatorPositionParams,
28
+ type MapLiteUpdateParams,
26
29
  type MapLiteWebError,
27
30
  type MarkerProps,
31
+ type NativeToWebCommand,
28
32
  type NavigatorChromeParams,
29
33
  type NavigatorInstructionParams,
30
34
  type NavigatorLang,
@@ -33,19 +37,11 @@ import {
33
37
  type NavigatorRouteSetParams,
34
38
  type PolygonProps,
35
39
  type PolylineProps,
40
+ type WebToNativeMessage,
36
41
  } from './types';
37
42
  import { loadResources } from './utils';
38
43
  import { MAP_HTML } from './webMapBuild';
39
44
 
40
- interface UpdateProps {
41
- center?: [number, number];
42
- zoom?: number;
43
- minZoom?: number;
44
- maxZoom?: number;
45
- zoomEnabled?: boolean;
46
- scrollEnabled?: boolean;
47
- mapStyle?: string;
48
- }
49
45
 
50
46
  interface MapViewProps {
51
47
  children?: React.ReactNode;
@@ -122,7 +118,7 @@ export type MapViewRef = {
122
118
  /**
123
119
  * Обновить «текущую позицию» (GPS): snap / reroute / прибытие — на стороне WebView.
124
120
  */
125
- setNavigatorPosition: (latitude: number, longitude: number) => void;
121
+ setNavigatorPosition: (latitude: number, longitude: number, accuracy?: number) => void;
126
122
  /** Режим «клик по карте = новая позиция» (удобно в dev). */
127
123
  pickNavigatorPosition: () => void;
128
124
  };
@@ -190,7 +186,7 @@ export const MapView = forwardRef<MapViewRef, MapViewProps>((props, ref) => {
190
186
  ? 0.85
191
187
  : (performanceMode === 'balanced' && Platform.OS === 'android' ? 1 : undefined);
192
188
 
193
- const sendToWebView = (message: { function: string; params: any }) => {
189
+ const sendToWebView = (message: NativeToWebCommand) => {
194
190
  if (__DEV__) {
195
191
  console.log('MapView: sendToWebView', message);
196
192
  }
@@ -209,33 +205,31 @@ export const MapView = forwardRef<MapViewRef, MapViewProps>((props, ref) => {
209
205
  const mapStyleText = await loadResources(props.mapStyle);
210
206
  const mapStyle = JSON.parse(mapStyleText);
211
207
 
212
- sendToWebView({
213
- function: 'init',
214
- params: {
215
- mapStyle: mapStyle,
216
- zoomEnabled: props.zoomEnabled ?? false,
217
- scrollEnabled: props.scrollEnabled ?? false,
218
- center: props.center,
219
- zoom: props.zoom,
220
- minZoom: props.minZoom,
221
- maxZoom: props.maxZoom,
222
- antialias: false,
223
- crossSourceCollisions: performanceMode !== 'performance',
224
- fadeDuration: performanceMode === 'performance' ? 0 : 120,
225
- pixelRatio: props.pixelRatio ?? fallbackPixelRatio,
226
- simplifyStyle: performanceMode !== 'quality',
227
- aggressiveSimplifyStyle: performanceMode === 'performance',
228
- maxPitch: performanceMode === 'performance' ? 0 : 45,
229
- renderWorldCopies: performanceMode === 'quality',
230
- turboWhileMoving: props.turboWhileMoving ?? (performanceMode === 'performance'),
231
- debugMode: props.debugMode ?? false,
232
- navigator: props.navigator === true,
233
- graphhopperUrl: props.graphhopperUrl,
234
- navigatorLang: props.navigatorLang,
235
- navigatorProfile: props.navigatorProfile,
236
- navigatorChrome: props.navigatorChrome,
237
- },
238
- });
208
+ const initParams: MapLiteInitParams = {
209
+ mapStyle: mapStyle,
210
+ zoomEnabled: props.zoomEnabled ?? false,
211
+ scrollEnabled: props.scrollEnabled ?? false,
212
+ center: props.center,
213
+ zoom: props.zoom,
214
+ minZoom: props.minZoom,
215
+ maxZoom: props.maxZoom,
216
+ antialias: false,
217
+ crossSourceCollisions: performanceMode !== 'performance',
218
+ fadeDuration: performanceMode === 'performance' ? 0 : 120,
219
+ pixelRatio: props.pixelRatio ?? fallbackPixelRatio,
220
+ simplifyStyle: performanceMode !== 'quality',
221
+ aggressiveSimplifyStyle: performanceMode === 'performance',
222
+ maxPitch: performanceMode === 'performance' ? 0 : 45,
223
+ renderWorldCopies: performanceMode === 'quality',
224
+ turboWhileMoving: props.turboWhileMoving ?? (performanceMode === 'performance'),
225
+ debugMode: props.debugMode ?? false,
226
+ navigator: props.navigator === true,
227
+ graphhopperUrl: props.graphhopperUrl,
228
+ navigatorLang: props.navigatorLang,
229
+ navigatorProfile: props.navigatorProfile,
230
+ navigatorChrome: props.navigatorChrome,
231
+ };
232
+ sendToWebView({ function: 'init', params: initParams });
239
233
  };
240
234
 
241
235
  const updateMarkerClickHandler = (propsMarker: MarkerProps) => {
@@ -328,8 +322,12 @@ export const MapView = forwardRef<MapViewRef, MapViewProps>((props, ref) => {
328
322
  sendToWebView({ function: 'advanceNavigatorInstruction', params: {} });
329
323
  };
330
324
 
331
- const setNavigatorPosition = (latitude: number, longitude: number) => {
332
- sendToWebView({ function: 'setNavigatorPosition', params: { latitude, longitude } });
325
+ const setNavigatorPosition = (latitude: number, longitude: number, accuracy?: number) => {
326
+ const params: MapLiteSetNavigatorPositionParams = { latitude, longitude };
327
+ if (typeof accuracy === 'number' && Number.isFinite(accuracy) && accuracy >= 0) {
328
+ params.accuracy = accuracy;
329
+ }
330
+ sendToWebView({ function: 'setNavigatorPosition', params });
333
331
  };
334
332
 
335
333
  const pickNavigatorPosition = () => {
@@ -350,7 +348,7 @@ export const MapView = forwardRef<MapViewRef, MapViewProps>((props, ref) => {
350
348
  const lastPropsRef = useRef<MapViewProps>(props);
351
349
 
352
350
  useEffect(() => {
353
- const updateProps: UpdateProps = {};
351
+ const updateProps: MapLiteUpdateParams = {};
354
352
 
355
353
  if (lastPropsRef.current.minZoom !== props.minZoom) {
356
354
  updateProps.minZoom = props.minZoom;
@@ -369,7 +367,9 @@ export const MapView = forwardRef<MapViewRef, MapViewProps>((props, ref) => {
369
367
  }
370
368
 
371
369
  if (lastPropsRef.current.mapStyle !== props.mapStyle) {
372
- updateProps.mapStyle = props.mapStyle;
370
+ void loadResources(props.mapStyle).then((mapStyleText) => {
371
+ sendToWebView({ function: 'update', params: { mapStyle: JSON.parse(mapStyleText) } });
372
+ });
373
373
  }
374
374
 
375
375
  lastPropsRef.current = props;
@@ -382,7 +382,7 @@ export const MapView = forwardRef<MapViewRef, MapViewProps>((props, ref) => {
382
382
 
383
383
  const onReceiveMessageFromWebView = (data: string) => {
384
384
  try {
385
- const msg = JSON.parse(data);
385
+ const msg = JSON.parse(data) as WebToNativeMessage;
386
386
 
387
387
  if (__DEV__) {
388
388
  console.log('MapView: event', msg);
@@ -392,20 +392,20 @@ export const MapView = forwardRef<MapViewRef, MapViewProps>((props, ref) => {
392
392
  switch (msg.event) {
393
393
  case 'movestart':
394
394
  mapSelectPointRef.current?.up();
395
- props.onMoveStart?.(msg.params);
395
+ props.onMoveStart?.(msg.params as EventParams);
396
396
  break;
397
397
  case 'moveend':
398
- props.onMoveEnd?.(msg.params);
398
+ props.onMoveEnd?.(msg.params as EventParams);
399
399
  mapSelectPointRef.current?.down();
400
400
  break;
401
401
  case 'zoomstart':
402
- props.onZoomStart?.(msg.params);
402
+ props.onZoomStart?.(msg.params as EventParams);
403
403
  break;
404
404
  case 'zoomend':
405
- props.onZoomEnd?.(msg.params);
405
+ props.onZoomEnd?.(msg.params as EventParams);
406
406
  break;
407
407
  case 'idle':
408
- props.onIdle?.(msg.params);
408
+ props.onIdle?.(msg.params as EventParams);
409
409
  break;
410
410
  case 'navigatorRouteSet':
411
411
  props.onNavigatorRouteSet?.(msg.params as NavigatorRouteSetParams);
@@ -421,7 +421,7 @@ export const MapView = forwardRef<MapViewRef, MapViewProps>((props, ref) => {
421
421
  }
422
422
 
423
423
  if (msg.type === 'error' && msg.data) {
424
- props.onMapLiteError?.(msg.data as MapLiteWebError);
424
+ props.onMapLiteError?.(msg.data);
425
425
  return;
426
426
  }
427
427
 
@@ -465,6 +465,7 @@ export const MapView = forwardRef<MapViewRef, MapViewProps>((props, ref) => {
465
465
 
466
466
  const lat = position.coords.latitude;
467
467
  const lng = position.coords.longitude;
468
+ const accuracy = position.coords.accuracy;
468
469
  if (!Number.isFinite(lat) || !Number.isFinite(lng)) {
469
470
  return;
470
471
  }
@@ -475,9 +476,13 @@ export const MapView = forwardRef<MapViewRef, MapViewProps>((props, ref) => {
475
476
  }
476
477
  lastForwardedAt = now;
477
478
 
479
+ const params: MapLiteSetNavigatorPositionParams = { latitude: lat, longitude: lng };
480
+ if (typeof accuracy === 'number' && Number.isFinite(accuracy) && accuracy >= 0) {
481
+ params.accuracy = accuracy;
482
+ }
478
483
  sendToWebViewRef.current({
479
484
  function: 'setNavigatorPosition',
480
- params: { latitude: lat, longitude: lng },
485
+ params,
481
486
  });
482
487
  },
483
488
  (error) => {
@@ -35,12 +35,13 @@ export type PolylineProps = {
35
35
 
36
36
  }
37
37
 
38
+ /** Web → RN: `postToNative` payload (`webProject/src/map/types.ts`). */
38
39
  export type EventParams = {
39
40
  center?: {
40
41
  lng: number,
41
- lat: number
42
- },
43
- zoom?: number
42
+ lat: number,
43
+ } | null,
44
+ zoom?: number | null,
44
45
  }
45
46
 
46
47
  export type NavigatorLang = 'ru' | 'en'
@@ -116,4 +117,116 @@ export type NavigatorPositionSetParams = {
116
117
  export type MapLiteWebError = {
117
118
  target: string,
118
119
  message: string,
119
- }
120
+ }
121
+
122
+ /** Parsed MapLibre style JSON — `InitParams.mapStyle` / `UpdateParams.mapStyle` в WebView. */
123
+ export type MapLiteStyleSpecification = Record<string, unknown>
124
+
125
+ /** RN → Web: `init` (`MapLiteController.InitParams`). */
126
+ export type MapLiteInitParams = {
127
+ mapStyle: MapLiteStyleSpecification,
128
+ center: [number, number],
129
+ zoom: number,
130
+ minZoom?: number,
131
+ maxZoom?: number,
132
+ zoomEnabled?: boolean,
133
+ scrollEnabled?: boolean,
134
+ antialias?: boolean,
135
+ crossSourceCollisions?: boolean,
136
+ fadeDuration?: number,
137
+ pixelRatio?: number,
138
+ simplifyStyle?: boolean,
139
+ aggressiveSimplifyStyle?: boolean,
140
+ maxPitch?: number,
141
+ renderWorldCopies?: boolean,
142
+ turboWhileMoving?: boolean,
143
+ debugMode?: boolean,
144
+ navigator?: boolean,
145
+ graphhopperUrl?: string,
146
+ navigatorLang?: NavigatorLang,
147
+ navigatorProfile?: NavigatorProfile | string,
148
+ navigatorChrome?: NavigatorChromeParams,
149
+ }
150
+
151
+ /** RN → Web: `update` (`MapLiteController.UpdateParams`). */
152
+ export type MapLiteUpdateParams = {
153
+ minZoom?: number,
154
+ maxZoom?: number,
155
+ zoomEnabled?: boolean,
156
+ scrollEnabled?: boolean,
157
+ mapStyle?: MapLiteStyleSpecification,
158
+ }
159
+
160
+ /** RN → Web: `fitBounds`. */
161
+ export type MapLiteFitBoundsParams = {
162
+ bounds: [[number, number], [number, number]],
163
+ padding?: number,
164
+ duration?: number,
165
+ }
166
+
167
+ /** RN → Web: `flyTo`. */
168
+ export type MapLiteFlyToParams = {
169
+ center: [number, number],
170
+ zoom: number,
171
+ duration?: number,
172
+ }
173
+
174
+ /** RN → Web: `setNavigatorPoint`. */
175
+ export type MapLiteSetNavigatorPointParams = {
176
+ latitude: number,
177
+ longitude: number,
178
+ }
179
+
180
+ /**
181
+ * RN → Web: `setNavigatorPosition`.
182
+ * `accuracy` (м) включает прод-режим off-route на стороне WebView.
183
+ */
184
+ export type MapLiteSetNavigatorPositionParams = {
185
+ latitude: number,
186
+ longitude: number,
187
+ accuracy?: number,
188
+ }
189
+
190
+ /** RN → Web: JSON в `WebView.postMessage` (`webProject/src/map/MapLiteController.receive`). */
191
+ export type NativeToWebCommand =
192
+ | { function: 'init', params: MapLiteInitParams }
193
+ | { function: 'update', params: MapLiteUpdateParams }
194
+ | { function: 'addMarker', params: MarkerProps }
195
+ | { function: 'removeMarker', params: MarkerProps }
196
+ | { function: 'addPolyline', params: PolylineProps }
197
+ | { function: 'removePolyline', params: PolylineProps }
198
+ | { function: 'addPolygon', params: PolygonProps }
199
+ | { function: 'removePolygon', params: PolygonProps }
200
+ | { function: 'fitBounds', params: MapLiteFitBoundsParams }
201
+ | { function: 'flyTo', params: MapLiteFlyToParams }
202
+ | { function: 'setNavigatorPoint', params: MapLiteSetNavigatorPointParams }
203
+ | { function: 'advanceNavigatorInstruction', params: Record<string, never> }
204
+ | { function: 'setNavigatorPosition', params: MapLiteSetNavigatorPositionParams }
205
+ | { function: 'pickNavigatorPosition', params: Record<string, never> }
206
+
207
+ /** Web → RN: `postToNative` (`webProject/src/map/types.ts`). */
208
+ export type WebToNativeMessage =
209
+ | { type: 'scriptReady' }
210
+ | { type: 'inited' }
211
+ | { type: 'event', event: string, params: unknown }
212
+ | { type: 'markerClick', uniqueId: string }
213
+ | {
214
+ type: 'error',
215
+ data: MapLiteWebError,
216
+ }
217
+
218
+ /** Имена `event` в `{ type: 'event', event, params }` из WebView. */
219
+ export type MapLiteMapEventName =
220
+ | 'movestart'
221
+ | 'moveend'
222
+ | 'zoomstart'
223
+ | 'zoomend'
224
+ | 'idle'
225
+ | 'error'
226
+ | 'navigatorRouteSet'
227
+ | 'navigatorInstruction'
228
+ | 'navigatorPositionSet'
229
+
230
+ export type MapLiteMapErrorEventParams = {
231
+ message: string,
232
+ }