-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add styleimagemissing
event for on-demand images
#7987
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks great. Just a couple nits on language.
I don't have a strong preference on the name of the event. styleimageneeded
and styleimagemissing
both work for me. If you want to include a warning as well, that's probably not a bad idea, but otherwise 👍
src/ui/events.js
Outdated
@@ -778,6 +778,20 @@ export type MapEvent = | |||
*/ | |||
| 'sourcedataloading' | |||
|
|||
/** | |||
* Fired when an icon or pattern needed by the style is missing. The missing image can | |||
* be added with {@link Map#addImage} within this callback to prevent the image from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe better to be explicit here -> within the event listener callback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, good idea!
@@ -0,0 +1,11 @@ | |||
/*--- | |||
title: Generate and add a missing icon to the map | |||
description: Add a missing icon to the map that was generated at runtime. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: in the map that was generated at runtime
, "that" appears to reference "map". Maybe something like Dynamically generate a missing icon at runtime and add it to the map
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, that's better. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example in this PR is 💯!
I think the styleimage
prefix is good for distinguishing from source images (for image or raster sources). I like missing
vs needed
because it describes the event better. styleimagenotfound
is one more for the naming 🎩.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 No strong preference but styleimagemissing
sounds good to me.
The event gets fired when a layer needs an image that the map doesn't have. The developer has a chance to listen for this event and add an image within the callback in order to have it included. This event can be used to dynamically generate icons based on feature properties. fix #7587
Thanks for the suggestions and feedback. I'll merge this as |
styleimageneeded
event for on-demand imagesstyleimagemissing
event for on-demand images
#6231 for me renders this feature unusable (though I love the idea of it). Currently that bug still exists for me in my use-case - the icons never properly render at the initial zoom level when I add them via the |
@joewoodhouse can you submit a new bug report with a minimal reproducible test case for this (e.g. using JSFiddle)? |
* reproducible issues were observed where marker icons don't display at initial zoom, but visible at other zoom levels * reproducible on Android browsers * also in Firefox desktop with connection throttling set to "Regular 3G" * caused by marker image not loaded in time * in theory we can use ['styleimagemissing'](mapbox/mapbox-gl-js#7987) to handle this, but this does not work with image files loaded via callback, only for inline generated images
This is the first of several dynamic icon prs.
The event gets fired when a layer needs an image that the map doesn't have. The developer has a chance to listen for this event and add an image within the callback in order to have it included.
This event can be used to dynamically generate icons based on feature properties.
fix #7587
See the committed
add-image-missing-generated
example for a full version.Naming
I'm pretty ok with
styleimageneeded
. Other alternatives were:styleimagemissing
imageneeded
imagemissing
Do you prefer any of these?
Launch Checklist