Add a canvas source
Add a CanvasSource
to the map.
<!DOCTYPE html><html><head><meta charset="utf-8" /><title>Add a canvas source</title><meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" /><script src="https://unpkg.com/trackasia-gl@1.0.5/dist/trackasia-gl.js"></script><link href="https://unpkg.com/trackasia-gl@1.0.5/dist/trackasia-gl.css" rel="stylesheet" /><style> body { margin: 0; padding: 0; } #map { position: absolute; top: 0; bottom: 0; width: 100%; }</style></head><body><canvas id="canvasID" width="400" height="400">Canvas not supported</canvas><div id="map"></div><script>//Animation from https://javascript.tutorials24x7.com/blog/how-to-draw-animated-circles-in-html5-canvasvar canvas = document.getElementById('canvasID');var ctx = canvas.getContext('2d');var circles = [];var radius = 20; function Circle(x, y, dx, dy, radius, color) {this.x = x;this.y = y;this.dx = dx;this.dy = dy; this.radius = radius; this.draw = function () {ctx.beginPath();ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2, false);ctx.strokeStyle = color;ctx.stroke();}; this.update = function () {if (this.x + this.radius > 400 || this.x - this.radius < 0) {this.dx = -this.dx;} if (this.y + this.radius > 400 || this.y - this.radius < 0) {this.dy = -this.dy;} this.x += this.dx;this.y += this.dy; this.draw();};} for (var i = 0; i < 5; i++) {var color ='#' +(0x1000000 + Math.random() * 0xffffff).toString(16).substr(1, 6);var x = Math.random() * (400 - radius * 2) + radius;var y = Math.random() * (400 - radius * 2) + radius; var dx = (Math.random() - 0.5) * 2;var dy = (Math.random() - 0.5) * 2; circles.push(new Circle(x, y, dx, dy, radius, color));} function animate() {requestAnimationFrame(animate);ctx.clearRect(0, 0, 400, 400); for (var r = 0; r < 5; r++) {circles[r].update();}} animate(); var map = new trackasiagl.Map({container: 'map',zoom: 5,minZoom: 4,center: {"lat":10.762622,"lng":106.660172},style: 'https://maps.track-asia.com/styles/v1/streets.json?key=public_key'}); map.on('load', function () {map.addSource('canvas-source', {type: 'canvas',canvas: 'canvasID',coordinates: [[110.4461,6.5006],[100.3541,6.5006],[100.3541,15.9706],[110.4461,15.9706]],// Set to true if the canvas source is animated. If the canvas is static, animate should be set to false to improve performance.animate: true}); map.addLayer({id: 'canvas-layer',type: 'raster',source: 'canvas-source'});});</script> </body></html>