Custom Icons
Creating Custom Stop Icons
The RouteStopIconProvider Interface
Implementing a Custom RouteStopIconProvider
/**
* Custom route stop icon provider.
*/
class CustomRouteStopIconProvider {
/**
* Gets the icon for the specified stop number.
*
* @param {number} [stopNumber] - The stop number.
* @returns {Promise<HTMLImageElement>} - The icon image.
*/
async getImage(stopNumber) {
return new Promise((resolve) => {
// This example creates a simple circle icon with a number
const width = 64;
const height = width;
const canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
const context = canvas.getContext('2d');
context.beginPath();
context.arc(width / 2, height / 2, width / 2 - 2, 0, 2 * Math.PI);
context.strokeStyle = '#fff'; // Set your desired stroke color here
context.lineWidth = 4;
context.fillStyle = '#00f'; // Set your desired fill color here
context.fill();
context.stroke();
if (Number.isInteger(stopNumber)) {
context.fillStyle = '#fff';
context.font = 'bold 28px sans-serif';
context.textAlign = 'center';
context.textBaseline = 'middle';
context.fillText(stopNumber, width / 2, height / 2);
}
const img = new Image(canvas.width, canvas.height);
img.onload = () => resolve(img);
img.src = canvas.toDataURL();
});
}
}Using the CustomRouteStopIconProvider

Last updated
Was this helpful?