* Draw markers to the basemap
()
| 419 | * Draw markers to the basemap |
| 420 | */ |
| 421 | drawMarkers() { |
| 422 | const queue = []; |
| 423 | this.markers.forEach((marker) => { |
| 424 | queue.push(async () => { |
| 425 | const top = Math.round(marker.position[1]); |
| 426 | const left = Math.round(marker.position[0]); |
| 427 | |
| 428 | if ( |
| 429 | top < 0 |
| 430 | || left < 0 |
| 431 | || top > this.height |
| 432 | || left > this.width |
| 433 | ) return; |
| 434 | |
| 435 | const markerInstance = await sharp(marker.imgData); |
| 436 | |
| 437 | if (marker.width === null || marker.height === null) { |
| 438 | const metadata = await markerInstance.metadata(); |
| 439 | |
| 440 | if (Number.isFinite(metadata.width) && Number.isFinite(metadata.height)) { |
| 441 | marker.setSize(metadata.width, metadata.height); |
| 442 | } else { |
| 443 | throw new Error(`Cannot detectimage size of marker ${marker.img}. Please define manually!`); |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | // Check if resize marker image is needed |
| 448 | if ( |
| 449 | marker.drawWidth !== marker.width |
| 450 | || marker.drawHeight !== marker.height |
| 451 | ) { |
| 452 | const resizeData = { |
| 453 | fit: marker.resizeMode, |
| 454 | }; |
| 455 | |
| 456 | if (marker.drawWidth !== marker.width) { |
| 457 | resizeData.width = marker.drawWidth; |
| 458 | } |
| 459 | |
| 460 | if (marker.drawHeight !== marker.height) { |
| 461 | resizeData.height = marker.drawHeight; |
| 462 | } |
| 463 | |
| 464 | await markerInstance |
| 465 | .resize(resizeData); |
| 466 | } |
| 467 | |
| 468 | this.image.image = await sharp(this.image.image) |
| 469 | .composite([{ |
| 470 | input: await markerInstance.toBuffer(), |
| 471 | top, |
| 472 | left, |
| 473 | }]) |
| 474 | .toBuffer(); |
| 475 | }); |
| 476 | }); |
| 477 | return asyncQueue(queue); |
| 478 | } |