Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,8 @@ user's Local Network permission on iOS.

A rejected URL logs `Rejected remote marker image URI` — under the `NitroMaps` logcat tag on
Android, and under the `NitroMaps` category of the `com.nitromaps` subsystem in the unified log
on iOS. The marker itself falls back to the default pin on both Google providers. On Apple Maps
it draws with no image at all, the same as any marker image that fails to load.
on iOS. The marker itself stays invisible on every provider, the same as any marker image that
fails to load.

`require()`d assets are exempt, including the packager URL Metro resolves them to in a
development build.
Expand All @@ -656,10 +656,14 @@ Additional props:
Platform notes:

- Recommended icon size: up to **128×128 dp**; larger bitmaps are downscaled when `width`/`height` are provided.
- Retina assets: pass `require()` and let Metro resolve `@2x`/`@3x`; optional explicit `width`/`height`/`scale` on `MarkerImage`.
- Display size: an explicit `width` and `height` (in dp) win. Without them, `scale` maps the bitmap's pixels to dp, so a 50×82 px remote image with `scale: 2` draws at 25×41 dp on every device. Without either, a remote image keeps its pixel size.
- Retina assets: pass `require()` and let Metro resolve `@2x`/`@3x`; it fills in `width`/`height` for you.
- Until its image is ready, or after the load failed, a marker with `image` is invisible rather than the default pin. Changing `image` keeps the current image until the new one is ready, and a cached image is swapped in place. Failed loads log one warning per image (tag/category `NitroMaps`).
- Remote URLs use a basic in-memory cache only (no disk persistence).
- Custom React Native marker views (`<Marker><View /></Marker>`) are not supported.

> **Behavior change after 1.2.1:** `MarkerImage.scale` used to be ignored, so an image with `scale` but no `width`/`height` drew at its pixel size on iOS and at a density-dependent size on Android. It now draws at pixels ÷ `scale` dp on both. If you passed `scale` and sized your bitmaps around the old result, drop `scale` or set `width`/`height`.

### react-native-maps migration (markers)

| react-native-maps | react-native-better-maps |
Expand Down
6 changes: 6 additions & 0 deletions example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,9 @@ export default function App() {
const [dockExpanded, setDockExpanded] = useState(false);
const [customMarkerRotation, setCustomMarkerRotation] = useState(45);
const [customMarkerFlat, setCustomMarkerFlat] = useState(true);
const [selectedCustomMarkerId, setSelectedCustomMarkerId] = useState<
string | null
>(null);
const [applePoiDetailPresentation, setApplePoiDetailPresentation] =
useState<ApplePoiDetailPresentation>(
APPLE_POI_DETAILS_DEFAULT_PRESENTATION,
Expand All @@ -772,6 +775,7 @@ export default function App() {
return createCustomMarkerImagesScenario({
rotation: customMarkerRotation,
flat: customMarkerFlat,
selectedMarkerId: selectedCustomMarkerId,
});
case APPLE_POI_DETAILS_SCENARIO_ID:
return createApplePoiDetailsScenario(applePoiDetailPresentation);
Expand All @@ -782,6 +786,7 @@ export default function App() {
baseScenario,
customMarkerRotation,
customMarkerFlat,
selectedCustomMarkerId,
applePoiDetailPresentation,
]);
const provider = SUPPORTED_MAP_PROVIDERS[providerIndex] ?? 'google';
Expand Down Expand Up @@ -896,6 +901,7 @@ export default function App() {

const handleMarkerPress = useCallback((id: string) => {
setStatus(`Marker · ${id}`);
setSelectedCustomMarkerId((current) => (current === id ? null : id));
}, []);

const handleMarkerDragEnd = useCallback(
Expand Down
27 changes: 25 additions & 2 deletions example/examples/customMarkerImages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ const PIN_ANCHOR = { x: 0.5, y: 1 } as const;
export interface CustomMarkerImagesOptions {
rotation: number;
flat: boolean;
/** The last pressed marker; the selectable pin grows while it is selected. */
selectedMarkerId: string | null;
}

const SELECTABLE_MARKER_ID = 'selectable-pin';

const BASE = {
latitude: 52.2297,
longitude: 21.0122,
Expand Down Expand Up @@ -81,10 +85,10 @@ export function createCustomMarkerImagesScenario(
longitude: longitude + lngStep * 1.5,
},
title: 'Remote URL',
subtitle: 'Leaflet gold pin · async fetch',
subtitle: 'Leaflet gold pin · scale 2 only · 25×41 dp',
image: {
uri: `${LEAFLET_BASE}/marker-icon-2x-gold.png`,
...LEAFLET_MARKER,
scale: LEAFLET_MARKER.scale,
},
anchor: PIN_ANCHOR,
},
Expand Down Expand Up @@ -207,13 +211,32 @@ export function createCustomMarkerImagesScenario(
},
anchor: PIN_ANCHOR,
},
{
id: SELECTABLE_MARKER_ID,
coordinate: {
latitude: latitude - latStep * 3.9,
longitude,
},
title: 'Image swap',
subtitle: 'Press to toggle 25×41 / 37×61 dp · swaps in place',
// A remote URL: a `require()`d asset cannot set its own size, and its `uri` passed as a
// plain object counts as user-supplied, so Android rejects the Metro host in development.
image: {
uri: `${LEAFLET_BASE}/marker-icon-2x-violet.png`,
width: options.selectedMarkerId === SELECTABLE_MARKER_ID ? 37 : 25,
height: options.selectedMarkerId === SELECTABLE_MARKER_ID ? 61 : 41,
scale: LEAFLET_MARKER.scale,
},
anchor: PIN_ANCHOR,
},
],
};
}

export const customMarkerImagesScenario = createCustomMarkerImagesScenario({
rotation: 45,
flat: true,
selectedMarkerId: null,
});

export const CUSTOM_MARKER_IMAGES_SCENARIO_ID = customMarkerImagesScenario.id;
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ fun MarkerDescriptor.toMarkerOptions(): MarkerOptions =
.title(title)
.snippet(subtitle)
.draggable(draggable == true)
.apply {
// Without an icon the marker is the default pin until `MarkerIconFactory` sets its image.
if (image != null) {
icon(placeholderMarkerIcon)
}
}

internal fun MarkerDescriptor.effectiveGoogleMapsAnchor(
widthPx: Float,
Expand Down
Loading
Loading