MCPcopy Create free account
hub / github.com/facebook/Rapid / _parseTileBuffer

Method _parseTileBuffer

modules/services/VectorTileService.js:316–437  ·  view source on GitHub ↗

* _parseTileBuffer * @param source * @param tile * @param buffer

(source, tile, buffer)

Source from the content-addressed store, hash-verified

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..

Callers 1

_loadTileAsyncMethod · 0.95

Calls 10

_getZoomCacheMethod · 0.95
_toSingleFeaturesMethod · 0.95
_calcExtentMethod · 0.95
getNextIDMethod · 0.95
_queueMergeMethod · 0.95
_cacheFeaturesMethod · 0.95
stringifyFunction · 0.85
featureMethod · 0.80
deferredRedrawMethod · 0.45

Tested by

no test coverage detected