Skip to main content
The Globe component is a highly customizable 3D interactive globe visualization built with Three.js and React Three Fiber. It supports various features like country polygons, arcs, points, labels, and atmospheric effects.

Features

  • Interactive 3D globe with smooth rotation and zoom controls
  • Customizable appearance (colors, lighting, atmosphere)
  • Support for GeoJSON data overlays
  • Animated arcs between points on the globe
  • Points of interest with labels
  • Atmospheric glow effects
  • Performance optimizations for large datasets

Installation

Basic Usage

Props

GlobeConfig

Examples

Basic Globe with Custom Colors

Interactive Globe with Click Events

Performance Considerations

  • For large datasets, consider using maxPolygonFeatures to limit the number of rendered polygons
  • Adjust hexPolygonResolution to balance quality and performance
  • Use maxDPR to control rendering quality on high-DPI displays
  • Disable unnecessary features (arcs, rings, labels) when not needed

Dependencies

  • three
  • @react-three/fiber
  • @react-three/drei
  • three-globe

Centroid Worker

The Globe component uses a Web Worker (centroid.worker.ts) to efficiently calculate centroids for GeoJSON features in a background thread, ensuring smooth performance even with complex geographical data.

Purpose

The centroid worker is responsible for:
  • Processing GeoJSON features (Polygon and MultiPolygon) in parallel
  • Calculating the centroid (geometric center) for each feature
  • Extracting relevant properties for labeling
  • Maintaining performance by offloading CPU-intensive calculations from the main thread

How It Works

  1. Input: The worker receives GeoJSON features with the following structure:
  2. Processing:
    • For each feature, it extracts the name from various possible property fields (name, ADMIN, iso_a2)
    • Calculates the centroid by averaging all coordinate points of the polygon’s exterior ring
    • Handles both Polygon and MultiPolygon geometry types
    • Preserves the count property if present for data visualization
  3. Output: Returns an array of label objects:

Performance Considerations

  • Web Worker: Runs in a separate thread, preventing UI freezes during calculations
  • Efficient Calculation: Uses simple averaging for centroids, which is fast and sufficient for most visualization purposes
  • Error Handling: Includes try-catch blocks to handle malformed GeoJSON gracefully
  • Debugging: Contains debug logging that can be enabled for troubleshooting

Integration with Globe Component

The Globe component uses this worker to position labels and interactive elements on the globe. The centroids help in:
  • Placing country/region labels at appropriate positions
  • Positioning interactive markers for regions
  • Enabling hover and click interactions with geographical features

Customization

You can extend the worker to:
  1. Add more sophisticated centroid calculation methods
  2. Include additional properties in the output
  3. Implement custom filtering or transformation of features
  4. Add support for additional GeoJSON geometry types

HubSpot GeoJSON Integration

The Globe component can visualize GeoJSON data from HubSpot’s API to create interactive heatmaps. Here’s how to integrate it:

Fetching and Using HubSpot GeoJSON

  1. First, fetch the GeoJSON data from the HubSpot API:

Customizing the Heatmap

You can customize how the GeoJSON data appears on the globe using these approaches:
  1. Color Scaling: Modify the getColorForCount function to adjust the color thresholds based on your data distribution.
  2. Tooltips: The example includes a basic tooltip showing the region name and incident count. You can enhance this with more details as needed.
  3. Interactive Features: Add click handlers to regions to show detailed information or navigate to related views.
  4. Animation: Add transitions when data updates to create smooth visualizations.

Performance Considerations

  • For large datasets, consider aggregating data at a higher geographic level (e.g., country instead of state).
  • Use maxPolygonFeatures to limit the number of features rendered at once.
  • Implement data caching to avoid unnecessary API calls.
The component includes several utility functions in the functions directory:
  • cartesianToLatLng: Convert 3D coordinates to latitude/longitude
  • computeCentroidsSync: Calculate centroids for GeoJSON features
  • coordHashForFeature: Generate a hash for feature coordinates
  • darkenColor: Darken a hex or RGB color
  • genRandomNumbers: Generate random numbers within a range
  • getFeatureId: Get a unique ID for a GeoJSON feature
  • haversineKm: Calculate distance between two points using Haversine formula
  • hexToRgb: Convert hex color to RGB
  • latLngToCartesian: Convert latitude/longitude to 3D coordinates
  • pointInPolygonFeature: Check if a point is inside a polygon feature
  • pointInRing: Check if a point is inside a ring

Browser Support

The Globe component uses WebGL for rendering and requires a modern browser with WebGL support.