MCPcopy Create free account
hub / github.com/cartesiancs/map3d / Space

Function Space

src/three/Space.tsx:442–508  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

440}
441
442export function Space() {
443 const areas = useAreaStore((state) => state.areas);
444 const [realCenter, setRealCenter] = useState<any>();
445 const center = useAreaStore((state) => state.center);
446 const refLat = (center[1].lat + center[0].lat) / 2;
447 const refLng = (center[1].lng + center[0].lng) / 2;
448
449 function project(lat: number, lng: number) {
450 const x = (lng - refLng) * scale * Math.cos((refLat * Math.PI) / 180);
451 const y = (lat - refLat) * scale;
452 return new THREE.Vector2(x, y);
453 }
454
455 const areaData = () => {
456 const result: Array<{
457 shape: THREE.Shape;
458 extrudeSettings: any;
459 tags: any;
460 }> = [];
461 areas.forEach((bld: any) => {
462 if (!bld.geometry || bld.geometry.length < 3) return;
463 const shapePoints = bld.geometry.map((pt: any) => project(pt.lat, pt.lng));
464 if (!shapePoints[0].equals(shapePoints[shapePoints.length - 1]))
465 shapePoints.push(shapePoints[0]);
466 const shape = new THREE.Shape(shapePoints);
467 let heightValue = parseFloat(bld.tags.height || "");
468 const heightLevels = parseFloat(bld.tags["building:levels"] || "");
469 if (isNaN(heightValue)) heightValue = 10;
470 if (!isNaN(heightLevels)) heightValue = heightLevels * 2.2;
471 const extrudeSettings = {
472 steps: 1,
473 depth: heightValue,
474 bevelEnabled: false,
475 };
476 result.push({ shape, extrudeSettings, tags: bld.tags });
477 });
478 return result;
479 };
480
481 useEffect(() => {
482 setRealCenter(center);
483 }, [areas]);
484
485 const buildingsData = areaData();
486
487 return (
488 <Canvas camera={{ fov: 90, near: 0.1, far: 7000 }}>
489 <ambientLight intensity={Math.PI / 2} />
490 <spotLight position={[10, 10, 10]} angle={0.15} penumbra={1} decay={0} intensity={Math.PI} />
491 {buildingsData.map((item, index) => (
492 <Building
493 key={index}
494 shape={item.shape}
495 extrudeSettings={item.extrudeSettings}
496 tags={item.tags}
497 />
498 ))}
499

Callers

nothing calls this directly

Calls 1

areaDataFunction · 0.85

Tested by

no test coverage detected