JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5
  • Score
    100M100P100Q53542F
  • License MIT

A React library integrating Three.js and MapLibre for 3D map visualization

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@trapar-waves/react-three-maplibre) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    @trapar-waves/react-three-maplibre

    npm version npm dm License GitHub last commit GitHub Actions Workflow Status Renovate


    中文 | 日本語 | Русский язык

    A React-based library integrating Three.js, MapLibre, and AntV for advanced geospatial 3D visualizations.

    ✨ Features

    • Geospatial Visualization: Combines @antv/l7 and maplibre-gl for powerful geospatial data rendering with custom map layers.
    • 3D Rendering with React: Leverages @react-three/fiber and @react-three/drei to integrate Three.js into a React-based workflow for declarative 3D scene management.
    • Customizable UI Integration: Offers seamless integration with React (react, react-dom) for building interactive geospatial applications.
    • Utility-First Styling: Employs tailwindcss for flexible and rapid styling of components and layouts.
    • Type Safety: Uses TypeScript to ensure type safety and improve developer experience during development.
    • Fast Development Workflow: Utilizes rsbuild for optimized builds and efficient development server performance.
    • Rich Component Library: Integrates with three-stdlib and @react-three/drei for reusable Three.js utilities and components.
    • Map Interactivity: Implements react-map-gl for interactive map controls and client-side navigation in geospatial contexts.
    • AntV Enhancements: Incorporates @antv/l7-maps for additional map layering capabilities and visualization tools.

    💻 Tech Stack

    • Framework/Library: React
    • UI Toolkit/Styling: Tailwind CSS
    • 3D Rendering: Three.js (@react-three/fiber, @react-three/drei)
    • Geospatial Libraries: MapLibre GL, AntV L7
    • Build Tool: Rsbuild
    • Language: TypeScript

    See the package.json for a full list of dependencies.

    🚀 Getting Started

    Follow these instructions to get the project running locally.

    Prerequisites

    Ensure you have the following installed:

    • Node.js (>= 18.x recommended)
    • Package manager (npm, yarn, or pnpm)
    node -v
    npm -v

    Installation

    1. Create a new project using the template:
    pnpm create trapar-waves
    1. Navigate to your project directory and install dependencies:
    cd your-project-name
    pnpm install
    # or
    npm install
    # or
    yarn install

    Development

    Start the development server with hot reloading:

    pnpm dev
    # or
    npm run dev
    # or
    yarn dev

    The application will be available at http://localhost:3000 by default.

    Building for Production

    To create a production build:

    pnpm build
    # or
    npm run build
    # or
    yarn build

    Preview the production build locally:

    pnpm preview
    # or
    npm run preview
    # or
    yarn preview

    📦 Usage

    This library is designed to be used as a template for creating geospatial 3D visualization applications. It provides a foundational setup with React, Three.js, MapLibre GL, and AntV L7.

    Basic Example

    Here's a simple example of how to use the components provided by this template:

    // App.tsx
    import type { ReactNode } from "react";
    import type { MapRef } from "react-map-gl/maplibre";
    import { PointLayer, Scene } from "@antv/l7";
    import { MapLibre } from "@antv/l7-maps";
    import { Box, Stats } from "@react-three/drei";
    import { extend } from "@react-three/fiber";
    import { useRef } from "react";
    import Map from "react-map-gl/maplibre";
    import { Canvas } from "react-three-map/maplibre";
    import { LineMaterial, LineSegments2, LineSegmentsGeometry } from "three-stdlib";
    
    extend({ LineSegmentsGeometry, LineMaterial, LineSegments2 });
    
    declare module "@react-three/fiber" {
      interface ThreeElements {
        lineSegmentsGeometry: ThreeElements["bufferGeometry"];
        lineMaterial: ThreeElements["material"] & Partial<LineMaterial>;
        lineSegments2: ThreeElements["object3D"] & { children?: ReactNode };
      }
    }
    
    const latLon = {
      latitude: 31.215175,
      longitude: 121.417463,
    };
    const MAPTILER_KEY = import.meta.env.PUBLIC_MAPTILER_KEY;
    
    function App() {
      const ref = useRef<HTMLDivElement>(null!);
      const mapRef = useRef<MapRef>(null!);
      function initL7() {
        if (mapRef.current) {
          const scene = new Scene({
            id: "map",
            map: new MapLibre({
              mapInstance: mapRef.current.getMap(),
            }),
          });
          scene.on("loaded", () => {
            fetch("/BElVQFEFvpAKzddxFZxJ.txt")
              .then(res => res.text())
              .then((data) => {
                const pointLayer = new PointLayer({
                  blend: "additive",
                })
                  .source(data, {
                    parser: {
                      type: "csv",
                      y: "lat",
                      x: "lng",
                    },
                  })
                  .size(0.5)
                  .color("#080298");
    
                scene.addLayer(pointLayer);
              });
          });
        }
      }
      return (
        <div className="h-screen w-screen relative overflow-hidden" ref={ref}>
          <Map
            id="map"
            ref={mapRef}
            initialViewState={{
              ...latLon,
              zoom: 11,
              pitch: 64.88,
            }}
            mapStyle={`https://api.maptiler.com/maps/streets/style.json?key=${MAPTILER_KEY}`}
            onLoad={initL7}
          >
            <Stats className="stats" parent={ref} />
    
            <Canvas {...latLon}>
              <hemisphereLight
                args={["#ffffff", "#60666C"]}
                position={[1, 4.5, 3]}
              />
              <object3D scale={500}>
                <Box position={[-1.2, 1, 0]} />
                <Box position={[1.2, 1, 0]} />
              </object3D>
            </Canvas>
          </Map>
        </div>
      );
    }
    
    export default App;

    This example demonstrates:

    • Creating a MapLibre GL map with react-map-gl
    • Integrating AntV L7 for geospatial data visualization
    • Using React Three Fiber and Drei for 3D rendering
    • Positioning 3D objects relative to the map using react-three-map

    Environment Variables

    To use map services like MapTiler, you'll need to set up environment variables. Create a .env file in your project root:

    PUBLIC_MAPTILER_KEY=your_maptiler_api_key_here

    Make sure to add .env to your .gitignore to keep your keys secure.

    🤝 Contributing

    Contributions are welcome and greatly appreciated! Please follow these steps to contribute:

    1. Fork the repository
    2. Create your feature branch (git checkout -b feature/amazing-feature)
    3. Commit your changes (git commit -m 'Add some amazing feature')
    4. Push to the branch (git push origin feature/amazing-feature)
    5. Open a Pull Request

    Please ensure your code follows the existing style and passes all tests.

    👤 Author