-
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
feature request: a way to conditionally provide icon images #7587
Labels
Comments
ansis
changed the title
feature request: a way of conditionally providing icon images
feature request: a way to conditionally provide icon images
Nov 13, 2018
Any update on this? I have just written almost verbatim your code in example B) under the assumption it would "just work" and then found this issue. I'm using a vector tile source. |
Some previous discussion along these lines: mapbox/mapbox-gl-style-spec#485, #5261. |
ansis
added a commit
that referenced
this issue
Mar 4, 2019
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
ansis
added a commit
that referenced
this issue
Mar 4, 2019
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
ansis
added a commit
that referenced
this issue
Mar 4, 2019
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
4 tasks
ansis
added a commit
that referenced
this issue
Mar 6, 2019
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
ansis
added a commit
that referenced
this issue
Mar 6, 2019
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
ansis
added a commit
that referenced
this issue
Mar 6, 2019
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
4 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Motivation
There are currently two ways to provide images for icons and patterns: the sprite and
addImage
. These work well when you have a limited number of images or when you know ahead of time which images you need. These approaches do not work when there are many possible images and you don't know which you need, for example user icons.We have a way to push images. We need a way to pull images.
Example:
You have a vector tile source that contains user locations. You want to set a unique icon image for each user depending on a userid data property. This is currently not possible there are too many icons to add in the sprite and because you can't use
addImage
because you don't know which icons are needed.A solution to this problem could be also useful for rendering custom icons based on feature properties.
Design Alternatives
A) Do nothing
Force users to load the data separately as geojson and have them manually iterate through features and add the correct icons before setting the data.
Cons:
B) Support loading images from urls
The
transformRequest
map option could be used by users to transform custom uri schemes to regular urls. For example,my-scheme://images/123
tohttp://example.com/images/
.Cons:
C) event for missing images
An event that gets fired after noticing we need an icon but before actually trying to use it. This lets the user add an image within the callback.
We would need some way of cleaning up images after they aren't needed anymore. One possible way is to add a third
addImage
parameter that lets the map drop it when it isn't used anymore:addImage(name, img, dropWhenUnused)
.We would also need support for async images.
Cons:
D) add image rendering callback with structured data
Cons:
E) user-implemented expressions
D) allows for user code to be called by expressions indirectly. We could take this further and allow users to register their own expressions.
Cons:
Design
I think we should implement C) event for missing images. It does what we need with the least amount of changes. It seems like something similar could be added on iOS (cc @1ec5) with a delegate and on Android with listener. There is already precedent for this on iOS with
-mapView:imageForAnnotation:
.Options D and E feel over designed. B works only in some cases and the possible performance trap it would introduce worries me.
Concepts
C) also has the least amount of new concepts introduced. We would teach this design by adding an example that fetches a custom image based on data and an example that renders an image locally. No new terminology would need to be introduced.
Implementation
ImageManager#getImages would fire the event when images are missing. ImageManager would also check if the image has loaded, and if not, delay until it has. The implementation in -native should be very similar.
@ChrisLoer does
C)
sound good?The text was updated successfully, but these errors were encountered: