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

Method _updateBuildingData

modules/core/Map3dSystem.js:435–491  ·  view source on GitHub ↗

* _updateBuildingData

(entities)

Source from the content-addressed store, hash-verified

433 * _updateBuildingData
434 */
435 _updateBuildingData(entities) {
436 const context = this.context;
437 const editor = context.systems.editor;
438 const graph = editor.staging.graph;
439 const selectedIDs = context.selectedIDs();
440
441 let buildingFeatures = [];
442 for (const entity of entities) {
443 const gj = entity.asGeoJSON(graph);
444 if (gj.type !== 'Polygon' && gj.type !== 'MultiPolygon') continue;
445
446 // If the building isn't a 'part', check its nodes.
447 // If any of THEM have a 'building part' as a way, and if that part is
448 // wholly contained in the footprint of this building, then we need to
449 // hide this building.
450 // Only perform this step if there are relatively few buildings to show,
451 // as this is a very expensive algorithm to run
452 if (!entity.tags['building:part'] && entities.length < 250) {
453 let touchesBuildingPart = false;
454
455 for (let node of entity.nodes) {
456 const parents = graph.parentWays(graph.hasEntity(node));
457 for (let way of parents) {
458 if (way.tags['building:part'] && geomPolygonContainsPolygon(entity.nodes.map(n => graph.hasEntity(n).loc), way.nodes.map(n => graph.hasEntity(n).loc))) {
459 touchesBuildingPart = true;
460 break;
461 }
462 }
463 }
464
465 if (touchesBuildingPart) {
466 continue;
467 }
468 }
469
470 const newFeature = {
471 type: 'Feature',
472 properties: {
473 extrude: true,
474 selected: selectedIDs.includes(entity.id).toString(),
475 min_height: entity.tags.min_height ? parseFloat(entity.tags.min_height) : 0,
476 height: parseFloat(entity.tags.height || entity.tags['building:levels'] * 3 || 0)
477 },
478 geometry: gj
479 };
480
481 buildingFeatures.push(newFeature);
482 }
483
484 const buildingSource = this.maplibre.getSource('osmbuildings');
485 if (buildingSource) {
486 buildingSource.setData({
487 type: 'FeatureCollection',
488 features: buildingFeatures
489 });
490 }
491 }
492

Callers 1

updateDataMethod · 0.95

Calls 4

parentWaysMethod · 0.80
hasEntityMethod · 0.80
setDataMethod · 0.80
selectedIDsMethod · 0.45

Tested by

no test coverage detected