-
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
Expose getImage to public API #5775
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.
thanks for the contribution! I noticed one missing return
statement but I also think it would be a good idea to guard/return an error when no id is passed or when the id is not a string.
src/ui/map.js
Outdated
* @param id The ID of the image. | ||
*/ | ||
getImage(id: string) { | ||
this.style.getImage(id); |
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.
you need a return statement here
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.
my bad 👍
What's the return type of |
Thanks, I addressed all the comments and squashed my commits |
Good point @jfirebaugh – @alex3165 would returning a boolean and renaming the method |
src/style/style.js
Outdated
getImage(id: string): ?StyleImage { | ||
return this.imageManager.getImage(id); | ||
} | ||
|
||
removeImage(id: string) { | ||
if (!this.imageManager.getImage(id)) { |
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.
you can use the new Style#getImage
method here.
src/ui/map.js
Outdated
* | ||
* @param id The ID of the image. | ||
*/ | ||
getImage(id: string): ?StyleImage { |
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 build is failing because the type StyleImage
was not imported so flow is erroring. I think we should rename the method hasImage
and change the return type to boolean
Yes |
Thanks @alex3165 ! |
Hey, @mollymerp when do you plan to release this? |
This will go out with the v0.43.0 release – i'd estimate sometime in the next 3-5 weeks |
@mollymerp Is there an equivalent method that could be exposed for controls? If so, I can create a new ticket. The use case is switching map styles. Since there is no "change base layer" ability like in Leaflet, we store references to all active layers in our app state and then re-add those sources/layers in GL. It appears that controls are not actually removed during this process so when we re-add them we get duplicate copies of the control. |
Great!! |
@areichman – no we don't expose a method for Controls. For DOM elements added to the map (see #5821 (comment)), we generally don't keep copies in the |
@mollymerp That's what I ended up doing. I am storing the control reference for other reasons and can just check for the presence of |
I'm not sure what this internal |
I'm not sure what your use case is @alpha-beta-soup but there is a listImages method that returns the names of all images in the style's sprite sheet. |
That's a handy method actually. My use case is to create automated legends from a layer. I do this with circle, symbol and polygon layers at the moment using my own (brittle) method that works because I have tightly-defined, known inputs (and graceful failure). But point I don't know if what I want to do is at all possible, but I just think it would be useful to get the actual image used in the spritesheet (or some kind of remote reference) to include in a legend, without having that separation between the symbols in Mapbox and those in the application. Then someone can add symbols to the spritesheet via Mapbox Studio without rebuilding the application. I'll include a gif. The legend for the area layer is determined dynamically, entirely based on the content of the style loaded when the application starts. Ideally I'd achieve the same for symbol layers too. In this example, all layers are pre-included into the style, and the UI simply toggles layer |
This PR expose
getImage
method from image manager to the public API. It should address #5735.Launch Checklist