MapConductor React SDK Samples

Visible Region | MapLibre | MapConductor React SDK

MapConductor React SDK Visible Region sample using MapLibre.

This interactive example demonstrates the Visible Region feature through the MapConductor abstraction on MapLibre.

Code example

import { useState } from 'react';
import { createGeoPoint, createMapCameraPosition, type VisibleRegion } from '@mapconductor/js-sdk-core';
import { MapLibreDesign, MapLibreMapView2D, useMapLibreViewState } from '@mapconductor/react-for-maplibre';


// (1) Create the map


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


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


// (2) Prepare the data and interaction state
const [region, setRegion] = useState<VisibleRegion | null>(null);


// (3) Render the map and its overlays


<MapLibreMapView2D
  state={mapViewState}
  onCameraMove={camera => setRegion(camera.visibleRegion)}
/>


<VisibleRegionValues region={region} />

How the code works

Read the provider-independent visible region from camera events, including its bounds and four corner coordinates.

Each onCameraMove event carries a camera whose visibleRegion is saved into React state as a VisibleRegion value.

VisibleRegionValues then prints that region’s bounds and its four corners, normalized so the same numbers appear on any provider.