MapConductor React SDK Samples

हีटमैप लेयर | MapLibre | MapConductor React SDK

MapLibre पर MapConductor React SDK का हีटमैप लेयर सैंपल।

यह इंटरैक्टिव उदाहरण MapLibre पर MapConductor की एब्स्ट्रैक्शन के ज़रिए हีटमैप लेयर दिखाता है।

कोड उदाहरण

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) मैप बनाएँ


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


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


  // (2) डेटा और इंटरैक्शन स्टेट तैयार करें
  // 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) मैप और उसके ओवरले रेंडर करें


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

कोड कैसे काम करता है

HeatmapOverlay भौगोलिक बिंदुओं का घनत्व दिखाता है।

useMemo बाहरी फ़ाइल के बिना 100 उदाहरण HeatmapPointState बनाता है। HeatmapPoints उन्हें एक साथ ओवरले को देता है।