1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| const pulsingDot = { width: size, height: size, data: new Uint8Array(size * size * 4),
onAdd() { const canvas = document.createElement('canvas'); canvas.width = this.width; canvas.height = this.height; this.context = canvas.getContext('2d'); const image = new Image(); image.src = './green.png'; this.image = image; const sprite = new Sprite({ canvas, image, numberOfFrames: 10, ticksPerFrame: 0, row: 7, column: 7, x: 0, y: 0, }); this.sprite = sprite; },
render() { const context = this.context;
context.clearRect(0, 0, this.width, this.height); this.sprite.update(); this.sprite.render(); this.data = context.getImageData(0, 0, this.width, this.height).data;
map.triggerRepaint();
return true; }, }; map.on('load', () => { map.addImage('pulsing-dot', pulsingDot, { pixelRatio: 2 });
map.addSource('points', { type: 'geojson', data: { type: 'FeatureCollection', features: [ { type: 'Feature', geometry: { type: 'Point', coordinates: mapConfig.center, }, }, ], }, }); map.addLayer({ id: 'points', type: 'symbol', source: 'points', layout: { 'icon-image': 'pulsing-dot', 'icon-rotation-alignment': 'map', }, }); });
|