gistda-sphere-react

Heatmaps, clusters and 3D

GPU-rendered heatmaps and clustering, 3D buildings from 3D Tiles, and glTF models

Sphere draws with MapLibre and deck.gl, so <Layer> can show far more than map tiles:

Data: MapLibre (earthquakes), Cesium (3D Tiles), Khronos (glTF).

Heatmap

Pass a MapLibre style with a GeoJSON source and a heatmap layer:

import { Layer, SphereMap } from "gistda-sphere-react";

const HEATMAP = {
  sources: {
    quakes: { type: "geojson", data: "https://maplibre.org/maplibre-gl-js/docs/assets/earthquakes.geojson" },
  },
  layers: [
    {
      id: "quakes-heat",
      type: "heatmap",
      source: "quakes",
      paint: {
        "heatmap-weight": ["interpolate", ["linear"], ["get", "mag"], 0, 0, 6, 1],
        "heatmap-radius": ["interpolate", ["linear"], ["zoom"], 0, 2, 9, 20],
      },
    },
  ],
};

<SphereMap zoom={3}>
  <Layer style={HEATMAP} />
</SphereMap>

Clustering

GeoJSON sources group nearby points with cluster: true. Style clusters by their point_count:

import { Layer } from "gistda-sphere-react";

const CLUSTERS = {
  sources: {
    stores: { type: "geojson", data: storesGeoJson, cluster: true, clusterRadius: 50 },
  },
  layers: [
    {
      id: "store-clusters",
      type: "circle",
      source: "stores",
      filter: ["has", "point_count"],
      paint: {
        "circle-color": ["step", ["get", "point_count"], "#51bbd6", 100, "#f1f075", 750, "#f28cb1"],
        "circle-radius": ["step", ["get", "point_count"], 14, 100, 22, 750, 32],
      },
    },
    {
      id: "store-points",
      type: "circle",
      source: "stores",
      filter: ["!", ["has", "point_count"]],
      paint: { "circle-color": "#11b4da", "circle-radius": 5 },
    },
  ],
};

<Layer style={CLUSTERS} />

Give each style's sources and layers unique IDs, so two <Layer>s never clash.

3D buildings (3D Tiles)

import { Layer, useMapControls } from "gistda-sphere-react";

const { goTo } = useMapControls();

<Layer
  name="buildings"
  type="Tiles3D"
  url="https://raw.githubusercontent.com/CesiumGS/3d-tiles-samples/main/1.0/TilesetWithRequestVolume/tileset.json"
  onTilesetLoad={(tileset) => {
    const [lon, lat] = tileset.cartographicCenter ?? [];
    goTo({ center: { lon, lat }, zoom: (tileset.zoom ?? 13) + 3, pitch: 60 });
  }}
/>

type="Tiles3D" takes a tileset.json URL of OGC 3D Tiles, including photogrammetry meshes and point clouds (pointSize). Large tilesets take a few seconds before onTilesetLoad fires. Sphere can't draw I3S layers at the moment. See the Layer page.

glTF models

deck.gl's ScenegraphLayer places 3D models. Create it once, wrapped in deck.MapboxLayer:

import { Layer } from "gistda-sphere-react";
import { useMemo } from "react";

function Model() {
  const layer = useMemo(() => {
    const { deck } = window;
    if (!deck) {
      return null;
    }
    return new deck.MapboxLayer({
      id: "box",
      type: deck.ScenegraphLayer,
      data: [{ position: [100.5018, 13.7563, 0] }],
      getPosition: (item: { position: number[] }) => item.position,
      getScale: [100, 100, 100],
      scenegraph: "https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/Box/glTF-Binary/Box.glb",
    });
  }, []);
  return layer ? <Layer layer={layer} /> : null;
}

Tilt the map (pitch) to see 3D content from the side. options={{ maxPitch: 85 }} on SphereMap allows steeper views.

On this page