* loadTiles * Schedule any data requests needed to cover the current map view * @param {string} template - template to load tiles for
(template)
| 149 | * @param {string} template - template to load tiles for |
| 150 | */ |
| 151 | loadTiles(template) { |
| 152 | this._getSourceAsync(template) |
| 153 | .then(source => { |
| 154 | const header = source.header; |
| 155 | if (header) { // pmtiles - set up allowable zoom range |
| 156 | this._tiler.zoomRange(header.minZoom, header.maxZoom); |
| 157 | if (header.tileType !== 1) { |
| 158 | throw new Error(`Unsupported tileType ${header.tileType}. Only Type 1 (MVT) is supported`); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | const viewport = this.context.viewport; |
| 163 | if (source.lastv === viewport.v) return; // exit early if the view is unchanged |
| 164 | source.lastv = viewport.v; |
| 165 | |
| 166 | // Determine the tiles needed to cover the view.. |
| 167 | const tiles = this._tiler.getTiles(viewport).tiles; |
| 168 | |
| 169 | // Abort inflight requests that are no longer needed.. |
| 170 | for (const [tileID, controller] of source.inflight) { |
| 171 | const needed = tiles.find(tile => tile.id === tileID); |
| 172 | if (!needed) { |
| 173 | controller.abort(); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | // Issue new requests.. |
| 178 | const fetches = tiles.map(tile => this._loadTileAsync(source, tile)); |
| 179 | return Promise.all(fetches) |
| 180 | .then(() => this._processMergeQueue(source)); |
| 181 | }); |
| 182 | } |
| 183 | |
| 184 | |
| 185 | /** |
nothing calls this directly
no test coverage detected