* Fetching tile from endpoint
(data)
| 541 | * Fetching tile from endpoint |
| 542 | */ |
| 543 | async getTile(data) { |
| 544 | const options = { |
| 545 | url: data.url, |
| 546 | responseType: 'buffer', |
| 547 | // resolveWithFullResponse: true, |
| 548 | headers: this.tileRequestHeader || {}, |
| 549 | timeout: this.tileRequestTimeout, |
| 550 | }; |
| 551 | |
| 552 | try { |
| 553 | const res = await got.get(options); |
| 554 | const { body, headers } = res; |
| 555 | |
| 556 | const contentType = headers['content-type']; |
| 557 | if (!contentType.startsWith('image/')) throw new Error('Tiles server response with wrong data'); |
| 558 | // console.log(headers); |
| 559 | |
| 560 | return { |
| 561 | success: true, |
| 562 | tile: { |
| 563 | url: data.url, |
| 564 | box: data.box, |
| 565 | body, |
| 566 | }, |
| 567 | }; |
| 568 | } catch (error) { |
| 569 | return { |
| 570 | success: false, |
| 571 | error, |
| 572 | }; |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | /** |
| 577 | * Fetching tiles and limit concurrent connections |