@yarrow-uz/rn-map-sdk 0.1.0 → 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.
- package/CHANGELOG.md +6 -0
- package/README.md +192 -5
- package/dist/index.d.ts +730 -173
- package/dist/index.js +1552 -253
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @yarrow-uz/rn-map-sdk
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 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.
|
|
8
|
+
|
|
3
9
|
## 0.1.0
|
|
4
10
|
|
|
5
11
|
### 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"`)
|
|
@@ -112,8 +116,192 @@ const { results, isLoading, error } = useYarrowSearch(query, {
|
|
|
112
116
|
});
|
|
113
117
|
```
|
|
114
118
|
|
|
115
|
-
Results are plain `SearchResult` objects — render them with
|
|
116
|
-
(e.g. `Marker` or `ViewAnnotation` from
|
|
119
|
+
Results are plain `SearchResult` objects — render them with `SearchResultsLayer`
|
|
120
|
+
(below) or your own markers (e.g. `Marker` or `ViewAnnotation` from
|
|
121
|
+
`@maplibre/maplibre-react-native`).
|
|
122
|
+
|
|
123
|
+
## Markers
|
|
124
|
+
|
|
125
|
+
`<YarrowMarker>` is the declarative counterpart of the web SDK's
|
|
126
|
+
`addMarker()`/`removeMarker()` — mount to place, unmount to remove:
|
|
127
|
+
|
|
128
|
+
```tsx
|
|
129
|
+
import { YarrowMapView, YarrowMarker } from '@yarrow-uz/rn-map-sdk';
|
|
130
|
+
|
|
131
|
+
<YarrowMapView apiKey="YOUR_API_KEY" center={[69.2401, 41.2995]}>
|
|
132
|
+
<YarrowMarker lngLat={[69.2401, 41.2995]} onPress={() => console.log('pin')}>
|
|
133
|
+
<PinView />
|
|
134
|
+
</YarrowMarker>
|
|
135
|
+
</YarrowMapView>
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Props: `lngLat` (`[lng, lat]`), `anchor` (default `'bottom'`, matching the web
|
|
139
|
+
SDK), `offset`, `onPress`, and a single child view.
|
|
140
|
+
|
|
141
|
+
## POI highlight
|
|
142
|
+
|
|
143
|
+
`<PoiHighlightLayer>` renders the web SDK's animated highlight markers for POI
|
|
144
|
+
ids. Each id resolves cheapest-first: caller-provided data → rendered map
|
|
145
|
+
tiles → the place-detail API, and an animated icon+label marker (or blue-dot
|
|
146
|
+
fallback) stands in for the POI:
|
|
147
|
+
|
|
148
|
+
```tsx
|
|
149
|
+
import { YarrowMapView, PoiHighlightLayer, useYarrowPoiHighlight } from '@yarrow-uz/rn-map-sdk';
|
|
150
|
+
|
|
151
|
+
function PoiScreen({ poiId }) {
|
|
152
|
+
const { highlightedIds, highlight, reset } = useYarrowPoiHighlight();
|
|
153
|
+
|
|
154
|
+
return (
|
|
155
|
+
<YarrowMapView apiKey="YOUR_API_KEY" center={[69.2401, 41.2995]}>
|
|
156
|
+
<PoiHighlightLayer
|
|
157
|
+
ids={highlightedIds}
|
|
158
|
+
panTo // fly to the POI once resolved
|
|
159
|
+
iconSize={56}
|
|
160
|
+
onHighlightPress={(info) => console.log(info.id, info.lat, info.lng)}
|
|
161
|
+
onResolveError={(id) => console.warn('could not resolve', id)}
|
|
162
|
+
/>
|
|
163
|
+
</YarrowMapView>
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Pass `dataById` to skip lookups for POIs you already know
|
|
169
|
+
(`{ [id]: { location, icon, title } }`). Removing an id from `ids` plays the
|
|
170
|
+
exit animation, then unmounts the marker.
|
|
171
|
+
|
|
172
|
+
Native limitation (web parity gap): the web SDK hides the highlighted POI's
|
|
173
|
+
own icon in the base style via a layer filter. Native has no runtime
|
|
174
|
+
`setFilter`, so the highlight marker draws **on top of** the base icon instead.
|
|
175
|
+
|
|
176
|
+
## Search results on the map
|
|
177
|
+
|
|
178
|
+
`<SearchResultsLayer>` renders search results on the map — the declarative
|
|
179
|
+
counterpart of the web SDK's `highlightSearchResults()`:
|
|
180
|
+
|
|
181
|
+
```tsx
|
|
182
|
+
import { YarrowMapView, SearchResultsLayer, useYarrowMapSearch } from '@yarrow-uz/rn-map-sdk';
|
|
183
|
+
|
|
184
|
+
function SearchScreen() {
|
|
185
|
+
const { results, isLoading, center } = useYarrowMapSearch(query, {
|
|
186
|
+
lat: 41.2995,
|
|
187
|
+
lon: 69.2401,
|
|
188
|
+
refetchOnMove: true, // re-query when the camera moves ≥ 500 m (web parity)
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
return (
|
|
192
|
+
<YarrowMapView apiKey="YOUR_API_KEY">
|
|
193
|
+
<SearchResultsLayer
|
|
194
|
+
results={results}
|
|
195
|
+
fitKey={query} // re-fit the camera when the query changes
|
|
196
|
+
zoomToResults // fitBounds on the first non-empty page (default)
|
|
197
|
+
onResultPress={(lat, lng, result) => console.log(result.name)}
|
|
198
|
+
/>
|
|
199
|
+
</YarrowMapView>
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Icon precedence per result: `icon_img` → registry icon by `category.name` →
|
|
205
|
+
blue dot. `zoomToResults` fits the camera once per session — pass `fitKey`
|
|
206
|
+
(e.g. the query) to start a new session and re-fit when it changes, matching
|
|
207
|
+
the web's per-call `highlightSearchResults()` semantics. Combine with
|
|
208
|
+
`useYarrowSearch` (headless) instead if you render
|
|
209
|
+
results in your own list.
|
|
210
|
+
|
|
211
|
+
## Clustering
|
|
212
|
+
|
|
213
|
+
Both `<PoiHighlightLayer>` and `<SearchResultsLayer>` accept a `clustering`
|
|
214
|
+
prop (`true` or a config object). Nearby markers collapse into a count badge;
|
|
215
|
+
pressing a badge zooms to expand (or calls your handler):
|
|
216
|
+
|
|
217
|
+
```tsx
|
|
218
|
+
<SearchResultsLayer
|
|
219
|
+
results={results}
|
|
220
|
+
clustering={{
|
|
221
|
+
radius: 60, // merge distance in points (default 60)
|
|
222
|
+
maxZoom: 16, // never cluster above this zoom (default 16)
|
|
223
|
+
minPoints: 2, // minimum markers per cluster (default 2)
|
|
224
|
+
onClusterClick: (children) => {
|
|
225
|
+
// return false to suppress the default zoom-to-expand
|
|
226
|
+
},
|
|
227
|
+
}}
|
|
228
|
+
/>
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Defaults match the web SDK's `setClustering()`. Implementation note: native
|
|
232
|
+
MapLibre clusters GeoJSON sources, not marker views, so the RN SDK groups the
|
|
233
|
+
markers by screen distance on every map move (the web SDK's own approach) —
|
|
234
|
+
aimed at dozens of markers, not thousands.
|
|
235
|
+
|
|
236
|
+
## Camera helpers
|
|
237
|
+
|
|
238
|
+
`useYarrowCamera` wraps the native `CameraRef` with the web SDK's camera
|
|
239
|
+
semantics (fitBounds defaults, degenerate-bounds expansion):
|
|
240
|
+
|
|
241
|
+
```tsx
|
|
242
|
+
import { useYarrowCamera, type CameraRef } from '@yarrow-uz/rn-map-sdk';
|
|
243
|
+
|
|
244
|
+
const cameraRef = useRef<CameraRef>(null);
|
|
245
|
+
<YarrowMapView apiKey="KEY" cameraRef={cameraRef}>…</YarrowMapView>
|
|
246
|
+
|
|
247
|
+
const camera = useYarrowCamera(cameraRef); // or no arg inside <YarrowMapView>
|
|
248
|
+
camera.zoomTo(41.2995, 69.2401, 14, { duration: 800 });
|
|
249
|
+
camera.fitBounds(routeFeatureCollection); // padding 50, duration 1000
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
Web's `speed`/`maxZoom` camera options have no native equivalents.
|
|
253
|
+
|
|
254
|
+
## Events
|
|
255
|
+
|
|
256
|
+
```tsx
|
|
257
|
+
<YarrowMapView
|
|
258
|
+
apiKey="KEY"
|
|
259
|
+
onMoveEnd={(lat, lng, zoom) => console.log(lat, lng, zoom)} // web onMoveEnd
|
|
260
|
+
onPress={(event) => console.log(event.nativeEvent.lngLat)} // map taps
|
|
261
|
+
>
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
`useYarrowLayerPress` handles presses on the base style's own layers — the
|
|
265
|
+
native counterpart of the web SDK's `onIconClick('pois' | 'buildings')` and
|
|
266
|
+
`onLayerClick(<admin labels>)`. It reads the map runtime from context, so it
|
|
267
|
+
must run in a component rendered **inside** `<YarrowMapView>`:
|
|
268
|
+
|
|
269
|
+
```tsx
|
|
270
|
+
import { useYarrowLayerPress, YarrowMapView } from '@yarrow-uz/rn-map-sdk';
|
|
271
|
+
|
|
272
|
+
function PoiPressReporter() {
|
|
273
|
+
useYarrowLayerPress('pois', ({ lat, lng, properties, selected }) => {
|
|
274
|
+
console.log('POI', properties.id, 'selected:', selected);
|
|
275
|
+
});
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export function MapScreen() {
|
|
280
|
+
return (
|
|
281
|
+
<YarrowMapView apiKey="KEY" center={tashkent}>
|
|
282
|
+
<PoiPressReporter />
|
|
283
|
+
</YarrowMapView>
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
Targets: `'pois' | 'buildings' | 'mahalla' | 'district' | 'region' | 'country'`.
|
|
289
|
+
Native cannot enumerate style layers, so targets resolve to the canonical
|
|
290
|
+
Yarrow style layer ids — verified against the served `/styles/` document
|
|
291
|
+
(identical in light and dark): `pois_tile_layer`, `buildings_tile_layer`,
|
|
292
|
+
`mahallah_label_tile_layer`, `districts_label_tile_layer`,
|
|
293
|
+
`regions_label_tile_layer`, `countries_label_tile_layer`. Pass
|
|
294
|
+
`{ layerIds: { … } }` to override. `selected` is `true` when the pressed POI
|
|
295
|
+
is currently highlighted by a `PoiHighlightLayer` in the same map.
|
|
296
|
+
|
|
297
|
+
## Icons
|
|
298
|
+
|
|
299
|
+
`YarrowMapView` fetches the Yarrow icon registry (`/icons-image`) on mount and
|
|
300
|
+
adds it to the style, so POI symbols render and search results can fall back
|
|
301
|
+
to category icons — the web icon pipeline, natively. Disable it with
|
|
302
|
+
`icons={false}` if your style doesn't need the Yarrow icons. The registry is
|
|
303
|
+
available to your own code via `fetchYarrowIcons()` and, inside the map,
|
|
304
|
+
`useYarrowMapRuntime().iconsByName`.
|
|
117
305
|
|
|
118
306
|
## Anonymous user token
|
|
119
307
|
|
|
@@ -164,8 +352,7 @@ const region = await offline.downloadRegion({
|
|
|
164
352
|
await region.done; // resolves with final progress, rejects on download failure
|
|
165
353
|
```
|
|
166
354
|
|
|
167
|
-
|
|
168
|
-
```
|
|
355
|
+
The region handle is `{ id, name, done, refreshStatus(), pause(), resume(), invalidate(), delete() }`.
|
|
169
356
|
|
|
170
357
|
Downloads default to zooms **8–15** (higher zooms multiply the tile count
|
|
171
358
|
fast — always estimate first) and are idempotent by `name`: re-downloading a
|