Skip to content
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

Merged
merged 4 commits into from
Dec 1, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/style/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,10 @@ class Style extends Evented {
this.fire('data', {dataType: 'style'});
}

getImage(id: string): ?StyleImage {
return this.imageManager.getImage(id);
}

removeImage(id: string) {
if (!this.imageManager.getImage(id)) {
Copy link
Contributor

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.

return this.fire('error', {error: new Error('No image with this name exists.')});
Expand Down
16 changes: 16 additions & 0 deletions src/ui/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,22 @@ class Map extends Camera {
this.style.addImage(id, { data: ((data: any): RGBAImage), pixelRatio, sdf });
}

/**
* Get an image from the style (such as one used by `icon-image` or `background-pattern`).
*
* @param id The ID of the image.
*/
getImage(id: string): ?StyleImage {
Copy link
Contributor

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

if (!id) {
this.fire('error', {
error: new Error('Missing required image id')
});
return;
}

return this.style.getImage(id);
}

/**
* Remove an image from the style (such as one used by `icon-image` or `background-pattern`).
*
Expand Down