getImage(ratio)
Returns an image for the specified scale.
Declaration
getImage?(ratio: number): Promise<string | ImageSource | undefined>;Mentioned in
Discussion
Implement this method to return a Promise that resolves to a URL string, an ImageSource, or undefined if no image is available. MapKit JS calls this method with a pixel ratio value that your function uses to provide an appropriately scaled image.
When both getImage(ratio) and getImageUrl(ratio, callback) are present, the framework uses getImage(ratio).
const imageDelegate = {
async getImage(scale) {
const response = await fetch(`https://example.com/images/marker?scale=${scale}`, {
headers: { "Authorization": "Bearer " + token }
});
if (!response.ok) return undefined;
const blob = await response.blob();
return createImageBitmap(blob);
}
};
const annotation = new mapkit.ImageAnnotation(
new mapkit.Coordinate(10, 10),
{ image: imageDelegate }
);