MCPcopy Create free account
hub / github.com/StephanGeorg/staticmaps / getTiles

Method getTiles

src/staticmaps.js:579–608  ·  view source on GitHub ↗

* Fetching tiles and limit concurrent connections

(baseLayers)

Source from the content-addressed store, hash-verified

577 * Fetching tiles and limit concurrent connections
578 */
579 async getTiles(baseLayers) {
580 const limit = this.tileRequestLimit;
581
582 // Limit concurrent connections to tiles server
583 // https://operations.osmfoundation.org/policies/tiles/#technical-usage-requirements
584 if (Number(limit)) {
585 const aQueue = [];
586 const tiles = [];
587 for (let i = 0, j = baseLayers.length; i < j; i += limit) {
588 const chunks = baseLayers.slice(i, i + limit);
589 const sQueue = [];
590 aQueue.push(async () => {
591 chunks.forEach((r) => {
592 sQueue.push((async () => {
593 const tile = await this.getTile(r);
594 tiles.push(tile);
595 })());
596 });
597 await Promise.all(sQueue);
598 });
599 }
600 await asyncQueue(aQueue);
601 return tiles;
602 }
603
604 // Do not limit concurrent connections at all
605 const tilePromises = [];
606 baseLayers.forEach((r) => { tilePromises.push(this.getTile(r)); });
607 return Promise.all(tilePromises);
608 }
609}
610
611export default StaticMaps;

Callers 1

drawLayerMethod · 0.95

Calls 1

getTileMethod · 0.95

Tested by

no test coverage detected