@yarrow-uz/rn-map-sdk 0.2.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 +6 -0
- package/README.md +37 -3
- package/dist/index.d.ts +24 -6
- package/dist/index.js +46 -12
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
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
|
+
|
|
3
9
|
## 0.2.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -106,6 +106,10 @@ function Directions({ origin, destination }) {
|
|
|
106
106
|
("no route found" resolves to an empty result instead of rejecting; network
|
|
107
107
|
failures reject and set `error`).
|
|
108
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
|
+
|
|
109
113
|
## Search
|
|
110
114
|
|
|
111
115
|
```tsx
|
|
@@ -169,9 +173,8 @@ Pass `dataById` to skip lookups for POIs you already know
|
|
|
169
173
|
(`{ [id]: { location, icon, title } }`). Removing an id from `ids` plays the
|
|
170
174
|
exit animation, then unmounts the marker.
|
|
171
175
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
`setFilter`, so the highlight marker draws **on top of** the base icon instead.
|
|
176
|
+
The base-icon limitation below applies to this layer — see
|
|
177
|
+
[Web-parity gaps](#web-parity-gaps).
|
|
175
178
|
|
|
176
179
|
## Search results on the map
|
|
177
180
|
|
|
@@ -393,6 +396,37 @@ offline.invalidateAmbientCache(); // recommended refresh
|
|
|
393
396
|
destructive — MapLibre's JS layer only re-reads the database on app restart,
|
|
394
397
|
so prefer per-region `invalidate()`/`delete()`.
|
|
395
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
|
+
|
|
396
430
|
## Example app
|
|
397
431
|
|
|
398
432
|
`packages/example` is a private Expo app that runs the SDK on a real Android
|
package/dist/index.d.ts
CHANGED
|
@@ -539,7 +539,8 @@ type RouteLayerProps = {
|
|
|
539
539
|
routeWidth?: number;
|
|
540
540
|
/** Best-route opacity. Default `1`. */
|
|
541
541
|
routeOpacity?: number;
|
|
542
|
-
/** Alternative-route color.
|
|
542
|
+
/** Alternative-route color. Default `#aaaaaa` — every alternative shares
|
|
543
|
+
* it, matching the web SDK's `buildRoute()`. */
|
|
543
544
|
alternativeColor?: string;
|
|
544
545
|
/** Alternative-route line width. Default `2.5`. */
|
|
545
546
|
alternativeWidth?: number;
|
|
@@ -549,6 +550,13 @@ type RouteLayerProps = {
|
|
|
549
550
|
layerPrefix?: string;
|
|
550
551
|
/** Called when a rendered route line is pressed. */
|
|
551
552
|
onPressRoute?: RoutePressHandler;
|
|
553
|
+
/**
|
|
554
|
+
* Distinct-series mode — web `renderRoutes()` parity. Every route draws in
|
|
555
|
+
* its own color from the shared `ROUTE_COLORS` palette (cycled), width 4
|
|
556
|
+
* and opacity 0.8, with no best/alternative distinction; the
|
|
557
|
+
* `bestIndex`/route/alternative style props are ignored.
|
|
558
|
+
*/
|
|
559
|
+
distinct?: boolean;
|
|
552
560
|
};
|
|
553
561
|
/**
|
|
554
562
|
* Declarative route rendering: one GeoJSON source + line layer per route.
|
|
@@ -560,8 +568,12 @@ type RouteLayerProps = {
|
|
|
560
568
|
* <RouteLayer routes={routes} onPressRoute={…} />
|
|
561
569
|
* </YarrowMapView>
|
|
562
570
|
* ```
|
|
571
|
+
*
|
|
572
|
+
* Pass `distinct` to render independent series instead of best-route-plus-
|
|
573
|
+
* alternatives — the declarative counterpart of the web SDK's
|
|
574
|
+
* `renderRoutes()`.
|
|
563
575
|
*/
|
|
564
|
-
export declare const RouteLayer: import("react").MemoExoticComponent<({ routes, bestIndex, routeColor, routeWidth, routeOpacity, alternativeColor, alternativeWidth, alternativeOpacity, layerPrefix, onPressRoute }: RouteLayerProps) => import("react/jsx-runtime").JSX.Element[]>;
|
|
576
|
+
export declare const RouteLayer: import("react").MemoExoticComponent<({ routes, bestIndex, routeColor, routeWidth, routeOpacity, alternativeColor, alternativeWidth, alternativeOpacity, layerPrefix, onPressRoute, distinct }: RouteLayerProps) => import("react/jsx-runtime").JSX.Element[]>;
|
|
565
577
|
/**
|
|
566
578
|
* Full style URL for MapLibre React Native's `mapStyle` prop, built from the
|
|
567
579
|
* platform-agnostic style endpoint plus the configured API key. The key comes
|
|
@@ -1132,8 +1144,14 @@ export declare const POI_BASE_LAYER = "pois_tile_layer";
|
|
|
1132
1144
|
* Fetches a POI's coordinates and icon from the place-detail API — the
|
|
1133
1145
|
* off-screen / below-zoom fallback of the resolution chain. Returns `null`
|
|
1134
1146
|
* on any failure or missing coordinates (web parity).
|
|
1147
|
+
*
|
|
1148
|
+
* When the response carries no `icon_img`, the icon is derived from
|
|
1149
|
+
* `node_type` (falling back to `category.name`) — the web SDK resolves it
|
|
1150
|
+
* through its style `icon-image` expression; native approximates that with
|
|
1151
|
+
* an icon-registry lookup by the same name, since the detail endpoint
|
|
1152
|
+
* returns the node type rather than an icon URL.
|
|
1135
1153
|
*/
|
|
1136
|
-
export declare function fetchPlaceLocation(id: number): Promise<ResolvedPoiData | null>;
|
|
1154
|
+
export declare function fetchPlaceLocation(id: number, iconsByName?: Record<string, string>): Promise<ResolvedPoiData | null>;
|
|
1137
1155
|
/**
|
|
1138
1156
|
* Reads a POI's point geometry from the style's POI layer within the current
|
|
1139
1157
|
* viewport — the free, no-network resolution step. Native can only query
|
|
@@ -1151,9 +1169,9 @@ export declare function lookupPoiInViewport(mapRef: MapRef$1, id: number, iconsB
|
|
|
1151
1169
|
* too, not just coordinates)
|
|
1152
1170
|
*
|
|
1153
1171
|
* The web SDK additionally evaluates the style's `icon-image` expression for
|
|
1154
|
-
* the tile
|
|
1155
|
-
* `node_type`. Coordinate resolution is the hard
|
|
1156
|
-
* the highlight is rolled back by the caller.
|
|
1172
|
+
* both the tile and the place-detail steps; native approximates it with a
|
|
1173
|
+
* registry lookup by `node_type`. Coordinate resolution is the hard
|
|
1174
|
+
* requirement — if it fails, the highlight is rolled back by the caller.
|
|
1157
1175
|
*/
|
|
1158
1176
|
export declare function resolvePoiData(id: number, options: HighlightPoiData, runtime: YarrowMapRuntime): Promise<ResolvedPoiData | null>;
|
|
1159
1177
|
/** Handle for one active highlight — mirrors the web SDK's `POIHighlight`. */
|
package/dist/index.js
CHANGED
|
@@ -555,8 +555,14 @@ const PLACE_TIMEOUT_MS = 15e3;
|
|
|
555
555
|
* Fetches a POI's coordinates and icon from the place-detail API — the
|
|
556
556
|
* off-screen / below-zoom fallback of the resolution chain. Returns `null`
|
|
557
557
|
* on any failure or missing coordinates (web parity).
|
|
558
|
+
*
|
|
559
|
+
* When the response carries no `icon_img`, the icon is derived from
|
|
560
|
+
* `node_type` (falling back to `category.name`) — the web SDK resolves it
|
|
561
|
+
* through its style `icon-image` expression; native approximates that with
|
|
562
|
+
* an icon-registry lookup by the same name, since the detail endpoint
|
|
563
|
+
* returns the node type rather than an icon URL.
|
|
558
564
|
*/
|
|
559
|
-
async function fetchPlaceLocation(id) {
|
|
565
|
+
async function fetchPlaceLocation(id, iconsByName) {
|
|
560
566
|
const controller = new AbortController();
|
|
561
567
|
const timeout = setTimeout(() => controller.abort(), PLACE_TIMEOUT_MS);
|
|
562
568
|
try {
|
|
@@ -566,10 +572,12 @@ async function fetchPlaceLocation(id) {
|
|
|
566
572
|
const data = (await res.json())?.search?.data;
|
|
567
573
|
const loc = data?.address?.location;
|
|
568
574
|
if (!loc) return null;
|
|
575
|
+
const nodeType = typeof data?.node_type === "string" ? data.node_type : typeof data?.category?.name === "string" ? data.category.name : void 0;
|
|
576
|
+
const iconUrl = data?.icon_img ?? (nodeType ? resolveCategoryIcon(iconsByName, nodeType) : void 0);
|
|
569
577
|
return {
|
|
570
578
|
lng: loc.lng,
|
|
571
579
|
lat: loc.lat,
|
|
572
|
-
iconUrl
|
|
580
|
+
iconUrl,
|
|
573
581
|
title: data?.name
|
|
574
582
|
};
|
|
575
583
|
} catch (error) {
|
|
@@ -622,9 +630,9 @@ async function lookupPoiInViewport(mapRef, id, iconsByName) {
|
|
|
622
630
|
* too, not just coordinates)
|
|
623
631
|
*
|
|
624
632
|
* The web SDK additionally evaluates the style's `icon-image` expression for
|
|
625
|
-
* the tile
|
|
626
|
-
* `node_type`. Coordinate resolution is the hard
|
|
627
|
-
* the highlight is rolled back by the caller.
|
|
633
|
+
* both the tile and the place-detail steps; native approximates it with a
|
|
634
|
+
* registry lookup by `node_type`. Coordinate resolution is the hard
|
|
635
|
+
* requirement — if it fails, the highlight is rolled back by the caller.
|
|
628
636
|
*/
|
|
629
637
|
async function resolvePoiData(id, options, runtime) {
|
|
630
638
|
let lng = options.location?.lng;
|
|
@@ -644,7 +652,7 @@ async function resolvePoiData(id, options, runtime) {
|
|
|
644
652
|
}
|
|
645
653
|
}
|
|
646
654
|
if (lng === void 0 || iconUrl === void 0 || title === void 0) {
|
|
647
|
-
const remote = await fetchPlaceLocation(id);
|
|
655
|
+
const remote = await fetchPlaceLocation(id, runtime.iconsByName);
|
|
648
656
|
if (remote) {
|
|
649
657
|
if (lng === void 0) {
|
|
650
658
|
lng = remote.lng;
|
|
@@ -979,7 +987,8 @@ var YarrowMapConfig = class {
|
|
|
979
987
|
|
|
980
988
|
// src/maps/routing/types.ts
|
|
981
989
|
/** Best-route + alternatives palette — same values as the web SDK's
|
|
982
|
-
* `buildRoute()` defaults (index 0 is the best route
|
|
990
|
+
* `buildRoute()` defaults (index 0 is the best route, index 1 the shared
|
|
991
|
+
* alternative color). */
|
|
983
992
|
const ROUTE_LAYER_COLORS = [
|
|
984
993
|
"#22c55e",
|
|
985
994
|
"#aaaaaa",
|
|
@@ -987,9 +996,20 @@ const ROUTE_LAYER_COLORS = [
|
|
|
987
996
|
"#dddddd",
|
|
988
997
|
"#eeeeee"
|
|
989
998
|
];
|
|
999
|
+
/** Distinct-series palette — same values as the web SDK's `renderRoutes()`. */
|
|
1000
|
+
const ROUTE_COLORS = [
|
|
1001
|
+
"#3b82f6",
|
|
1002
|
+
"#10b981",
|
|
1003
|
+
"#f59e0b",
|
|
1004
|
+
"#ef4444",
|
|
1005
|
+
"#8b5cf6"
|
|
1006
|
+
];
|
|
990
1007
|
|
|
991
1008
|
// src/maps/routing/RouteLayer.tsx
|
|
992
1009
|
const DEFAULT_LAYER_PREFIX = "yarrow-route";
|
|
1010
|
+
/** Line styling of `renderRoutes()` — web parity for the distinct series. */
|
|
1011
|
+
const DISTINCT_ROUTE_WIDTH = 4;
|
|
1012
|
+
const DISTINCT_ROUTE_OPACITY = .8;
|
|
993
1013
|
const toFeatureCollection = (route) => ({
|
|
994
1014
|
type: "FeatureCollection",
|
|
995
1015
|
features: [route]
|
|
@@ -1004,14 +1024,28 @@ const toFeatureCollection = (route) => ({
|
|
|
1004
1024
|
* <RouteLayer routes={routes} onPressRoute={…} />
|
|
1005
1025
|
* </YarrowMapView>
|
|
1006
1026
|
* ```
|
|
1027
|
+
*
|
|
1028
|
+
* Pass `distinct` to render independent series instead of best-route-plus-
|
|
1029
|
+
* alternatives — the declarative counterpart of the web SDK's
|
|
1030
|
+
* `renderRoutes()`.
|
|
1007
1031
|
*/
|
|
1008
|
-
const RouteLayer = memo(function RouteLayer({ routes, bestIndex = 0, routeColor = ROUTE_LAYER_COLORS[0], routeWidth = 5, routeOpacity = 1, alternativeColor, alternativeWidth = 2.5, alternativeOpacity = .5, layerPrefix = DEFAULT_LAYER_PREFIX, onPressRoute }) {
|
|
1009
|
-
|
|
1032
|
+
const RouteLayer = memo(function RouteLayer({ routes, bestIndex = 0, routeColor = ROUTE_LAYER_COLORS[0], routeWidth = 5, routeOpacity = 1, alternativeColor = ROUTE_LAYER_COLORS[1], alternativeWidth = 2.5, alternativeOpacity = .5, layerPrefix = DEFAULT_LAYER_PREFIX, onPressRoute, distinct = false }) {
|
|
1033
|
+
const styleFor = (index) => {
|
|
1034
|
+
if (distinct) return {
|
|
1035
|
+
color: ROUTE_COLORS[index % ROUTE_COLORS.length],
|
|
1036
|
+
width: DISTINCT_ROUTE_WIDTH,
|
|
1037
|
+
opacity: DISTINCT_ROUTE_OPACITY
|
|
1038
|
+
};
|
|
1010
1039
|
const isBest = index === bestIndex;
|
|
1040
|
+
return {
|
|
1041
|
+
color: isBest ? routeColor : alternativeColor,
|
|
1042
|
+
width: isBest ? routeWidth : alternativeWidth,
|
|
1043
|
+
opacity: isBest ? routeOpacity : alternativeOpacity
|
|
1044
|
+
};
|
|
1045
|
+
};
|
|
1046
|
+
return routes.map((route, index) => {
|
|
1011
1047
|
const sourceId = `${layerPrefix}-${index}`;
|
|
1012
|
-
const color
|
|
1013
|
-
const width = isBest ? routeWidth : alternativeWidth;
|
|
1014
|
-
const opacity = isBest ? routeOpacity : alternativeOpacity;
|
|
1048
|
+
const { color, width, opacity } = styleFor(index);
|
|
1015
1049
|
return /* @__PURE__ */ jsx(GeoJSONSource, {
|
|
1016
1050
|
id: sourceId,
|
|
1017
1051
|
data: toFeatureCollection(route),
|
package/package.json
CHANGED