MapConductor React SDK Samples

Heatmap-Ebene | MapLibre | MapConductor React SDK

Heatmap-Ebene-Beispiel des MapConductor React SDK mit MapLibre.

Dieses interaktive Beispiel zeigt Heatmap-Ebene über die MapConductor-Abstraktion auf MapLibre.

Codebeispiel

import { useMemo } from 'react';
import { createGeoPoint, createMapCameraPosition } from '@mapconductor/js-sdk-core';
import { MapLibreDesign, MapLibreMapView2D, useMapLibreViewState } from '@mapconductor/react-for-maplibre';
import { HeatmapOverlay, HeatmapPointState, HeatmapPoints } from '@mapconductor/react-heatmap';
import '@mapconductor/react-for-maplibre/style.css';


export default function App() {
  // (1) Die Karte erzeugen


  const initialCamera = createMapCameraPosition({
    position: createGeoPoint({ latitude: 35.6812, longitude: 139.7671 }),
    zoom: 12,
  });


  const mapViewState = useMapLibreViewState({
    mapDesignType: MapLibreDesign.OsmBrightJa,
    cameraPosition: initialCamera,
  });


  // (2) Daten und Interaktionszustand vorbereiten
  // Inline points work without the example app's public data files.
  const heatmapPoints = useMemo(() => Array.from({ length: 100 }, (_, index) =>
    new HeatmapPointState({
      id: `point-${index}`,
      position: createGeoPoint({
        latitude: 35.68 + Math.sin(index * 2.4) * (index % 10) * 0.001,
        longitude: 139.77 + Math.cos(index * 2.4) * (index % 10) * 0.001,
      }),
    }),
  ), []);


  // (3) Die Karte und ihre Overlays rendern


  return (
    <div style={{ height: 500, position: 'relative', display: 'flex', flexDirection: 'column' }}>
      <MapLibreMapView2D state={mapViewState}>
        <HeatmapOverlay>
          <HeatmapPoints states={heatmapPoints} />
        </HeatmapOverlay>
      </MapLibreMapView2D>
    </div>
  );
}

Wie der Code funktioniert

HeatmapOverlay zeichnet die Dichte geografischer Punkte.

useMemo erzeugt 100 HeatmapPointState-Beispielpunkte ohne externe Datei. HeatmapPoints übergibt sie gemeinsam an das Overlay.