vasturiano / react-globe.gl

React component for Globe Data Visualization using ThreeJS/WebGL
https://vasturiano.github.io/react-globe.gl/example/world-population/
MIT License
818 stars 150 forks source link

How To: Dotted lands #145

Open vicky1103 opened 9 months ago

vicky1103 commented 9 months ago

I'm attempting to render a transparent globe composed of lands represented by points. Currently, I'm using the following React component:

import { useEffect, useState, useRef } from 'react';
import Globe from 'react-globe.gl';
import * as THREE from 'three';
import * as topojson from 'topojson-client';

function GlobeGL() {

    const polygonsMaterial = new THREE.MeshLambertMaterial({ color: 'red', side: THREE.DoubleSide });

    const globeEl = useRef()
    const [landPolygons, setLandPolygons] = useState([]);

    useEffect(() => {
        fetch('//unpkg.com/world-atlas/land-110m.json').then(res => res.json())
            .then(landTopo => {
                setLandPolygons(topojson.feature(landTopo, landTopo.objects.land).features);
            });

        globeEl.current.controls().autoRotate = true;
        globeEl.current.controls().autoRotateSpeed = 1;
        globeEl.current.controls().enableZoom = false;
        globeEl.current.controls().enabled = false;

    }, []);

    return <Globe
        ref={globeEl}
        backgroundColor="rgba(0,0,0,.1)"
        showGlobe={false}
        showAtmosphere={false}
        polygonsData={landPolygons}
        polygonCapMaterial={polygonsMaterial}
        polygonSideColor={() => 'rgba(0, 0, 0, 0)'}
        animateIn={false}
    />;

}

export default GlobeGL;

And I get this: image

I would like to modify the component to render a series of equidistant points on the globe, replacing the current red land representation. Is there a straightforward way to achieve this?

BangNguyen1992 commented 9 months ago

Hello @vicky1103, currently, the lib doesnt support the dots layer out of the box. However, you can use the hexed polygon layer and set the hexPolygonMargin 0.7 That might help the hexagon look more rounded.

We had a small discussion over here