@yarrow-uz/rn-map-sdk 0.1.0 → 0.3.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 +12 -0
- package/README.md +226 -5
- package/dist/index.d.ts +748 -173
- package/dist/index.js +1586 -253
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @yarrow-uz/rn-map-sdk
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 1844859: RouteLayer: alternative routes now default to the web `buildRoute()` shared gray (`#aaaaaa`) instead of a per-index palette, and a new `distinct` prop renders the web `renderRoutes()` series (own `ROUTE_COLORS` color per route, width 4, opacity 0.8). The POI place-detail fallback now derives the icon from `node_type`/`category.name` through the icon registry when the response has no `icon_img` (web parity — previously those POIs fell back to the blue dot). The README consolidates the web-parity gaps (category visibility, hover, brand badge/controls, feature state, viewport-only tile lookup, camera caps) in one section.
|
|
8
|
+
|
|
9
|
+
## 0.2.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 202314b: Bring the React Native SDK to feature parity with the web SDK's interactive surface, as declarative components and hooks. rn-sdk gains: `<YarrowMarker>` (addMarker parity), `<PoiHighlightLayer>` + `useYarrowPoiHighlight` (highlightPOI parity — animated icon+label markers with the caller-data → tiles → place-detail resolution chain (the API also fills icon/title when only coordinates are known, matching web), panTo, press info, exit animations), `<SearchResultsLayer>` + `useYarrowMapSearch` (highlightSearchResults parity — on-map result markers with icon fallbacks, fit-once-per-session with a `fitKey` prop so a new query re-fits like the web's per-call sessions, re-query on ≥ 500 m camera moves), clustering (`clustering` prop on both layers — count badges, zoom-to-expand, web defaults), `useYarrowCamera` (zoomTo/fitBounds web semantics + the 0.003° degenerate-bounds expansion), `onMoveEnd` on `YarrowMapView`, `useYarrowLayerPress` (onIconClick/onLayerClick parity for POIs, buildings and admin labels — targets resolve to the canonical Yarrow style layer ids, verified against the served `/styles/` document — with the highlight-aware `selected` flag), and the icon pipeline (`YarrowMapView` fetches `/icons-image` and feeds the native style via `<Images>` with a missing-icon retry — the web addImage/resolver parity, tunable with `icons={false}`). Core (bundled into both SDKs, its changes ride this release) gains the shared `getBoundingBox`/`BoundingBox` helpers moved from the web SDK and the `ICONS_ENDPOINT` constant; the web SDK patch republishes the rebuilt bundle with that core, behavior unchanged. Known native limitation, documented in the README: the web's base-layer hide filter behind highlight markers has no runtime `setFilter` on native, so highlight markers draw on top of the base POI icon instead.
|
|
14
|
+
|
|
3
15
|
## 0.1.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -7,7 +7,11 @@ routing for iOS and Android.
|
|
|
7
7
|
|
|
8
8
|
- Native MapLibre maps (via [`@maplibre/maplibre-react-native`](https://github.com/maplibre/maplibre-react-native)) with Yarrow light/dark, satellite and hybrid styles
|
|
9
9
|
- Route planning, rendering and turn-by-turn directions
|
|
10
|
-
- Debounced, abortable search hooks
|
|
10
|
+
- Debounced, abortable search hooks, plus on-map search-result markers
|
|
11
|
+
- Animated POI highlight markers (icon + label) with cheapest-first resolution
|
|
12
|
+
- Marker clustering with count badges and zoom-to-expand
|
|
13
|
+
- Web-parity camera helpers (`zoomTo` / `fitBounds` / `getBoundingBox`)
|
|
14
|
+
- Base-style layer press events (POIs, buildings, admin labels)
|
|
11
15
|
- Offline region downloads (pause/resume/invalidate) plus ambient-cache control
|
|
12
16
|
- Anonymous user-token tracking with an AsyncStorage adapter
|
|
13
17
|
- DAU reporting (`sdk_type: "react-native"`)
|
|
@@ -102,6 +106,10 @@ function Directions({ origin, destination }) {
|
|
|
102
106
|
("no route found" resolves to an empty result instead of rejecting; network
|
|
103
107
|
failures reject and set `error`).
|
|
104
108
|
|
|
109
|
+
`<RouteLayer>` renders best-route-plus-alternatives (web `buildRoute()`
|
|
110
|
+
styling). Pass `distinct` to render independent series in their own palette
|
|
111
|
+
colors instead — the counterpart of the web SDK's `renderRoutes()`.
|
|
112
|
+
|
|
105
113
|
## Search
|
|
106
114
|
|
|
107
115
|
```tsx
|
|
@@ -112,8 +120,191 @@ const { results, isLoading, error } = useYarrowSearch(query, {
|
|
|
112
120
|
});
|
|
113
121
|
```
|
|
114
122
|
|
|
115
|
-
Results are plain `SearchResult` objects — render them with
|
|
116
|
-
(e.g. `Marker` or `ViewAnnotation` from
|
|
123
|
+
Results are plain `SearchResult` objects — render them with `SearchResultsLayer`
|
|
124
|
+
(below) or your own markers (e.g. `Marker` or `ViewAnnotation` from
|
|
125
|
+
`@maplibre/maplibre-react-native`).
|
|
126
|
+
|
|
127
|
+
## Markers
|
|
128
|
+
|
|
129
|
+
`<YarrowMarker>` is the declarative counterpart of the web SDK's
|
|
130
|
+
`addMarker()`/`removeMarker()` — mount to place, unmount to remove:
|
|
131
|
+
|
|
132
|
+
```tsx
|
|
133
|
+
import { YarrowMapView, YarrowMarker } from '@yarrow-uz/rn-map-sdk';
|
|
134
|
+
|
|
135
|
+
<YarrowMapView apiKey="YOUR_API_KEY" center={[69.2401, 41.2995]}>
|
|
136
|
+
<YarrowMarker lngLat={[69.2401, 41.2995]} onPress={() => console.log('pin')}>
|
|
137
|
+
<PinView />
|
|
138
|
+
</YarrowMarker>
|
|
139
|
+
</YarrowMapView>
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Props: `lngLat` (`[lng, lat]`), `anchor` (default `'bottom'`, matching the web
|
|
143
|
+
SDK), `offset`, `onPress`, and a single child view.
|
|
144
|
+
|
|
145
|
+
## POI highlight
|
|
146
|
+
|
|
147
|
+
`<PoiHighlightLayer>` renders the web SDK's animated highlight markers for POI
|
|
148
|
+
ids. Each id resolves cheapest-first: caller-provided data → rendered map
|
|
149
|
+
tiles → the place-detail API, and an animated icon+label marker (or blue-dot
|
|
150
|
+
fallback) stands in for the POI:
|
|
151
|
+
|
|
152
|
+
```tsx
|
|
153
|
+
import { YarrowMapView, PoiHighlightLayer, useYarrowPoiHighlight } from '@yarrow-uz/rn-map-sdk';
|
|
154
|
+
|
|
155
|
+
function PoiScreen({ poiId }) {
|
|
156
|
+
const { highlightedIds, highlight, reset } = useYarrowPoiHighlight();
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<YarrowMapView apiKey="YOUR_API_KEY" center={[69.2401, 41.2995]}>
|
|
160
|
+
<PoiHighlightLayer
|
|
161
|
+
ids={highlightedIds}
|
|
162
|
+
panTo // fly to the POI once resolved
|
|
163
|
+
iconSize={56}
|
|
164
|
+
onHighlightPress={(info) => console.log(info.id, info.lat, info.lng)}
|
|
165
|
+
onResolveError={(id) => console.warn('could not resolve', id)}
|
|
166
|
+
/>
|
|
167
|
+
</YarrowMapView>
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Pass `dataById` to skip lookups for POIs you already know
|
|
173
|
+
(`{ [id]: { location, icon, title } }`). Removing an id from `ids` plays the
|
|
174
|
+
exit animation, then unmounts the marker.
|
|
175
|
+
|
|
176
|
+
The base-icon limitation below applies to this layer — see
|
|
177
|
+
[Web-parity gaps](#web-parity-gaps).
|
|
178
|
+
|
|
179
|
+
## Search results on the map
|
|
180
|
+
|
|
181
|
+
`<SearchResultsLayer>` renders search results on the map — the declarative
|
|
182
|
+
counterpart of the web SDK's `highlightSearchResults()`:
|
|
183
|
+
|
|
184
|
+
```tsx
|
|
185
|
+
import { YarrowMapView, SearchResultsLayer, useYarrowMapSearch } from '@yarrow-uz/rn-map-sdk';
|
|
186
|
+
|
|
187
|
+
function SearchScreen() {
|
|
188
|
+
const { results, isLoading, center } = useYarrowMapSearch(query, {
|
|
189
|
+
lat: 41.2995,
|
|
190
|
+
lon: 69.2401,
|
|
191
|
+
refetchOnMove: true, // re-query when the camera moves ≥ 500 m (web parity)
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
return (
|
|
195
|
+
<YarrowMapView apiKey="YOUR_API_KEY">
|
|
196
|
+
<SearchResultsLayer
|
|
197
|
+
results={results}
|
|
198
|
+
fitKey={query} // re-fit the camera when the query changes
|
|
199
|
+
zoomToResults // fitBounds on the first non-empty page (default)
|
|
200
|
+
onResultPress={(lat, lng, result) => console.log(result.name)}
|
|
201
|
+
/>
|
|
202
|
+
</YarrowMapView>
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Icon precedence per result: `icon_img` → registry icon by `category.name` →
|
|
208
|
+
blue dot. `zoomToResults` fits the camera once per session — pass `fitKey`
|
|
209
|
+
(e.g. the query) to start a new session and re-fit when it changes, matching
|
|
210
|
+
the web's per-call `highlightSearchResults()` semantics. Combine with
|
|
211
|
+
`useYarrowSearch` (headless) instead if you render
|
|
212
|
+
results in your own list.
|
|
213
|
+
|
|
214
|
+
## Clustering
|
|
215
|
+
|
|
216
|
+
Both `<PoiHighlightLayer>` and `<SearchResultsLayer>` accept a `clustering`
|
|
217
|
+
prop (`true` or a config object). Nearby markers collapse into a count badge;
|
|
218
|
+
pressing a badge zooms to expand (or calls your handler):
|
|
219
|
+
|
|
220
|
+
```tsx
|
|
221
|
+
<SearchResultsLayer
|
|
222
|
+
results={results}
|
|
223
|
+
clustering={{
|
|
224
|
+
radius: 60, // merge distance in points (default 60)
|
|
225
|
+
maxZoom: 16, // never cluster above this zoom (default 16)
|
|
226
|
+
minPoints: 2, // minimum markers per cluster (default 2)
|
|
227
|
+
onClusterClick: (children) => {
|
|
228
|
+
// return false to suppress the default zoom-to-expand
|
|
229
|
+
},
|
|
230
|
+
}}
|
|
231
|
+
/>
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
Defaults match the web SDK's `setClustering()`. Implementation note: native
|
|
235
|
+
MapLibre clusters GeoJSON sources, not marker views, so the RN SDK groups the
|
|
236
|
+
markers by screen distance on every map move (the web SDK's own approach) —
|
|
237
|
+
aimed at dozens of markers, not thousands.
|
|
238
|
+
|
|
239
|
+
## Camera helpers
|
|
240
|
+
|
|
241
|
+
`useYarrowCamera` wraps the native `CameraRef` with the web SDK's camera
|
|
242
|
+
semantics (fitBounds defaults, degenerate-bounds expansion):
|
|
243
|
+
|
|
244
|
+
```tsx
|
|
245
|
+
import { useYarrowCamera, type CameraRef } from '@yarrow-uz/rn-map-sdk';
|
|
246
|
+
|
|
247
|
+
const cameraRef = useRef<CameraRef>(null);
|
|
248
|
+
<YarrowMapView apiKey="KEY" cameraRef={cameraRef}>…</YarrowMapView>
|
|
249
|
+
|
|
250
|
+
const camera = useYarrowCamera(cameraRef); // or no arg inside <YarrowMapView>
|
|
251
|
+
camera.zoomTo(41.2995, 69.2401, 14, { duration: 800 });
|
|
252
|
+
camera.fitBounds(routeFeatureCollection); // padding 50, duration 1000
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
Web's `speed`/`maxZoom` camera options have no native equivalents.
|
|
256
|
+
|
|
257
|
+
## Events
|
|
258
|
+
|
|
259
|
+
```tsx
|
|
260
|
+
<YarrowMapView
|
|
261
|
+
apiKey="KEY"
|
|
262
|
+
onMoveEnd={(lat, lng, zoom) => console.log(lat, lng, zoom)} // web onMoveEnd
|
|
263
|
+
onPress={(event) => console.log(event.nativeEvent.lngLat)} // map taps
|
|
264
|
+
>
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
`useYarrowLayerPress` handles presses on the base style's own layers — the
|
|
268
|
+
native counterpart of the web SDK's `onIconClick('pois' | 'buildings')` and
|
|
269
|
+
`onLayerClick(<admin labels>)`. It reads the map runtime from context, so it
|
|
270
|
+
must run in a component rendered **inside** `<YarrowMapView>`:
|
|
271
|
+
|
|
272
|
+
```tsx
|
|
273
|
+
import { useYarrowLayerPress, YarrowMapView } from '@yarrow-uz/rn-map-sdk';
|
|
274
|
+
|
|
275
|
+
function PoiPressReporter() {
|
|
276
|
+
useYarrowLayerPress('pois', ({ lat, lng, properties, selected }) => {
|
|
277
|
+
console.log('POI', properties.id, 'selected:', selected);
|
|
278
|
+
});
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export function MapScreen() {
|
|
283
|
+
return (
|
|
284
|
+
<YarrowMapView apiKey="KEY" center={tashkent}>
|
|
285
|
+
<PoiPressReporter />
|
|
286
|
+
</YarrowMapView>
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
Targets: `'pois' | 'buildings' | 'mahalla' | 'district' | 'region' | 'country'`.
|
|
292
|
+
Native cannot enumerate style layers, so targets resolve to the canonical
|
|
293
|
+
Yarrow style layer ids — verified against the served `/styles/` document
|
|
294
|
+
(identical in light and dark): `pois_tile_layer`, `buildings_tile_layer`,
|
|
295
|
+
`mahallah_label_tile_layer`, `districts_label_tile_layer`,
|
|
296
|
+
`regions_label_tile_layer`, `countries_label_tile_layer`. Pass
|
|
297
|
+
`{ layerIds: { … } }` to override. `selected` is `true` when the pressed POI
|
|
298
|
+
is currently highlighted by a `PoiHighlightLayer` in the same map.
|
|
299
|
+
|
|
300
|
+
## Icons
|
|
301
|
+
|
|
302
|
+
`YarrowMapView` fetches the Yarrow icon registry (`/icons-image`) on mount and
|
|
303
|
+
adds it to the style, so POI symbols render and search results can fall back
|
|
304
|
+
to category icons — the web icon pipeline, natively. Disable it with
|
|
305
|
+
`icons={false}` if your style doesn't need the Yarrow icons. The registry is
|
|
306
|
+
available to your own code via `fetchYarrowIcons()` and, inside the map,
|
|
307
|
+
`useYarrowMapRuntime().iconsByName`.
|
|
117
308
|
|
|
118
309
|
## Anonymous user token
|
|
119
310
|
|
|
@@ -164,8 +355,7 @@ const region = await offline.downloadRegion({
|
|
|
164
355
|
await region.done; // resolves with final progress, rejects on download failure
|
|
165
356
|
```
|
|
166
357
|
|
|
167
|
-
|
|
168
|
-
```
|
|
358
|
+
The region handle is `{ id, name, done, refreshStatus(), pause(), resume(), invalidate(), delete() }`.
|
|
169
359
|
|
|
170
360
|
Downloads default to zooms **8–15** (higher zooms multiply the tile count
|
|
171
361
|
fast — always estimate first) and are idempotent by `name`: re-downloading a
|
|
@@ -206,6 +396,37 @@ offline.invalidateAmbientCache(); // recommended refresh
|
|
|
206
396
|
destructive — MapLibre's JS layer only re-reads the database on app restart,
|
|
207
397
|
so prefer per-region `invalidate()`/`delete()`.
|
|
208
398
|
|
|
399
|
+
## Web-parity gaps
|
|
400
|
+
|
|
401
|
+
The RN SDK mirrors the web SDK's interactive surface — search, routing, POI
|
|
402
|
+
highlight, clustering, camera helpers and base-layer press events all behave
|
|
403
|
+
like their web counterparts. Some web features have no native equivalent:
|
|
404
|
+
|
|
405
|
+
- **Highlight base-icon overlap** — the web SDK hides a highlighted POI's own
|
|
406
|
+
icon in the base style via a layer filter. Native has no runtime
|
|
407
|
+
`setFilter`, so `<PoiHighlightLayer>` markers draw **on top of** the base
|
|
408
|
+
icon instead of replacing it.
|
|
409
|
+
- **POI category visibility** — the web's `setPoiCategoryEnabled()` /
|
|
410
|
+
`setPoiCategoriesEnabled()` / `getPoiCategories()` / `enablePoiLayer()` /
|
|
411
|
+
`disablePoiLayer()` / `excludePoiLayer` config are unavailable (same
|
|
412
|
+
runtime-`setFilter` limitation): category visibility cannot be changed
|
|
413
|
+
after the style loads.
|
|
414
|
+
- **Hover effects** — the web `hover` config and `setHoverEnabled()` are
|
|
415
|
+
web-only; there is no hover on touch surfaces.
|
|
416
|
+
- **Brand badge & Yarrow controls** — the web SDK's Yarrow brand badge and
|
|
417
|
+
zoom/compass controls are DOM overlays. RN maps use MapLibre's native
|
|
418
|
+
ornaments instead (`attribution`, `logo`, `compass` props of
|
|
419
|
+
`<YarrowMapView>`).
|
|
420
|
+
- **Feature state & background color** — MapLibre React Native's `MapRef`
|
|
421
|
+
exposes no `setFeatureState`, and there is no `changeBackgroundColor()`
|
|
422
|
+
equivalent (add your own background `<Layer>` if needed).
|
|
423
|
+
- **Tile-step POI lookup is viewport-only** — the web resolves highlight
|
|
424
|
+
coordinates from all loaded tiles (`querySourceFeatures`); native can only
|
|
425
|
+
query *rendered* features, so off-screen POIs fall through to the
|
|
426
|
+
place-detail API.
|
|
427
|
+
- **Camera option caps** — `zoomTo(speed)` and `fitBounds(maxZoom)` have no
|
|
428
|
+
native equivalents; `duration` and `padding` are supported.
|
|
429
|
+
|
|
209
430
|
## Example app
|
|
210
431
|
|
|
211
432
|
`packages/example` is a private Expo app that runs the SDK on a real Android
|