* _parseTileBuffer * @param source * @param tile * @param buffer
(source, tile, buffer)
| 314 | * @param buffer |
| 315 | */ |
| 316 | _parseTileBuffer(source, tile, buffer) { |
| 317 | if (!buffer) return; // 'no data' is ok |
| 318 | |
| 319 | // Get some info about this tile and its neighbors |
| 320 | const [x, y, z] = tile.xyz; |
| 321 | const tileID = tile.id; |
| 322 | const tileExtent = tile.wgs84Extent; |
| 323 | |
| 324 | // -y |
| 325 | // +----+ |
| 326 | // -x | | +x |
| 327 | // +----+ |
| 328 | // +y |
| 329 | |
| 330 | // Define tile edges (lower x,y,z - higher x,y,z) |
| 331 | const leftEdge = `${x-1},${y},${z}-${tileID}`; |
| 332 | const rightEdge = `${tileID}-${x+1},${y},${z}`; |
| 333 | const topEdge = `${x},${y-1},${z}-${tileID}`; |
| 334 | const bottomEdge = `${tileID}-${x},${y+1},${z}`; |
| 335 | |
| 336 | const vt = new VectorTile(new Protobuf(buffer)); |
| 337 | const cache = this._getZoomCache(source, z); |
| 338 | |
| 339 | const newFeatures = []; |
| 340 | for (const [layerID, vtLayer] of Object.entries(vt.layers)) { |
| 341 | if (!vtLayer) continue; |
| 342 | |
| 343 | // Determine extent of tile coordinates |
| 344 | const min = 0; |
| 345 | const max = vtLayer.extent; // default 4096 |
| 346 | |
| 347 | // For each feature on the vector tile... |
| 348 | for (let i = 0; i < vtLayer.length; i++) { |
| 349 | const vtFeature = vtLayer.feature(i); |
| 350 | const [left, top, right, bottom] = vtFeature.bbox(); |
| 351 | |
| 352 | // This feature is wholly on a neighbor tile - it just spills onto this tile in the buffer.. |
| 353 | if (left > max || top > max || right < min || bottom < min) continue; |
| 354 | |
| 355 | // Force all properties to strings |
| 356 | for (const [k, v] of Object.entries(vtFeature.properties)) { |
| 357 | vtFeature.properties[k] = v.toString(); |
| 358 | } |
| 359 | |
| 360 | // When features have the same properties, we'll consider them mergeable. |
| 361 | const prophash = utilHashcode(stringify(vtFeature.properties)).toString(); |
| 362 | |
| 363 | // If the feature doesn't have an id, use the prophash as the id |
| 364 | if (!vtFeature.id) { |
| 365 | vtFeature.id = prophash; |
| 366 | } |
| 367 | |
| 368 | // Convert to GeoJSON |
| 369 | const orig = vtFeature.toGeoJSON(x, y, z); |
| 370 | |
| 371 | // It's common for a vector tile to return 'Multi' GeoJSON features.. |
| 372 | // e.g. All the roads together in one `MultiLineString`. |
| 373 | // For our purposes, we really want to work with them as single features.. |
no test coverage detected