Skip to content

Commit c953144

Browse files
authored
Merge pull request #122 from Siergiej29/feature/mapbox-marker-image-source
feat: Add imageSource support for marker rendering
2 parents 06d0853 + 8492598 commit c953144

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

src/ui-mapbox/common.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ export interface MapboxMarker extends LatLng {
147147
* Example: "~/assets/markers/green_pin_marker.png"
148148
*/
149149
iconPath?: string;
150+
/**
151+
* Runtime-generated image used directly as a marker icon.
152+
* Useful when the app composes an icon in memory instead of loading it from a resource, file path, or URL.
153+
*/
154+
imageSource?: ImageSource;
150155
/**
151156
* A callback function to invoke when the marker is tapped.
152157
*/

src/ui-mapbox/index.android.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,11 +1376,13 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
13761376
console.warn(`No icon found for this device density for icon ' ${marker.icon}'. Falling back to the default icon.`);
13771377
}
13781378
} else if (marker.icon.startsWith('http')) {
1379-
if (marker.downloadedIcon !== null) {
1379+
if (marker.downloadedIcon) {
13801380
icon = marker.downloadedIcon;
13811381

13821382
// markerOptions.setIcon(iconFactory.fromBitmap(marker.iconDownloaded));
13831383
}
1384+
} else if (marker.imageSource) {
1385+
icon = marker.imageSource;
13841386
} else {
13851387
if (Trace.isEnabled()) {
13861388
CLog(CLogTypes.info, 'Please use res://resourcename, http(s)://imageurl or iconPath to use a local path');
@@ -3566,14 +3568,17 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
35663568
return marker;
35673569
} catch (error) {
35683570
console.error(error);
3571+
return marker;
35693572
}
35703573
}
35713574

35723575
async _downloadMarkerImages(markers: MapboxMarker[]) {
35733576
const result: MapboxMarker[] = [];
35743577
for (let i = 0; i < markers.length; i++) {
35753578
const marker = markers[i];
3576-
if (marker.icon && marker.icon.startsWith('http')) {
3579+
if (marker.imageSource || marker.downloadedIcon) {
3580+
result.push(marker);
3581+
} else if (marker.icon && marker.icon.startsWith('http')) {
35773582
const mark = await this._downloadImage(marker);
35783583
result.push(mark);
35793584
} else {

src/ui-mapbox/index.ios.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,11 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
626626

627627
const updated = await Promise.all(
628628
markers.map(async (m) => {
629-
if (m.icon && typeof m.icon === 'string' && m.icon.startsWith('http')) {
629+
if (m.imageSource) {
630+
(m as any).iconDownloaded = m.imageSource.ios;
631+
} else if (m.downloadedIcon) {
632+
(m as any).iconDownloaded = m.downloadedIcon.ios;
633+
} else if (m.icon && typeof m.icon === 'string' && m.icon.startsWith('http')) {
630634
(m as any).iconDownloaded = await fetchImageIOS(m.icon);
631635
}
632636
return m;

0 commit comments

Comments
 (0)