[Feat] Add onStyleImageMissing callback for Map

Author: joshkautzCreated Dec 16, 2022Updated Mar 2, 2026
Labelsfeature

Target Use Case

Mapbox throws a warning when you try to load an image that hasn't been added.

Image [...] could not be loaded. Please make sure you have added the image with map.addImage() or a "sprite" property in your style. You can provide missing images by listening for the "styleimagemissing" map event.

They have a new map event, styleimagemissing, that I think should be exposed by this React Wrapper. Unless this is already an event type that's supported with another callback handler that I've been overlooking.

Proposal

The usage might look something like this. I'm happy to help contribute in this feature if it's something that folks think would be good to add. I'll wait to hear back from a maintainer first though

<Map
   {...initialViewState}
   mapboxAccessToken={MAPBOX_TOKEN}
   projection={'globe'}
   style={{ position: 'absolute', top: '0', bottom: '0', left: '0', right: '0' }}

   onStyleImageMissing={evt => {
      evt.target.loadImage(
         "./icons/mapbox-marker-icon-20px-red.png",
         (error, image) => {
            if (error)
               throw error;
            evt.target.addImage(mapImages.Default, image);
         }
      );
   }}
/>