Contents

ImageDelegate

An object you use to provide images for annotations.

Declaration

interface ImageDelegate

Mentioned in

Overview

In addition to using a dictionary object that defines image URLs for ImageAnnotation or MarkerAnnotation, you can specify an image delegate that allows you to return an image dynamically or asynchronously.

Implement getImage(ratio) to return a Promise that resolves to a URL string, an ImageSource, or undefined:

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.MarkerAnnotation(
    new mapkit.Coordinate(10, 10),
    {
        glyphImage: imageDelegate
    }
);

Topics

Returning an image

See Also

Setting images