Skip to main content

Example: Controls

FullscreenControl

The FullscreenControl is the component provided by the react-bkoi-gl package that allows users to toggle fullscreen mode for the map. This can enhance the user experience by providing a more immersive view of the map.

The NavigationControl component in the react-bkoi-gl package provides users with convenient map navigation tools, including zoom in/out controls and a reset-to-north feature. These controls improve user interaction by offering an easy way to adjust the map view, allowing users to zoom in for detailed exploration or zoom out for a broader perspective. Additionally, the reset-to-north functionality helps reorient the map to its default position, ensuring a more seamless and intuitive mapping experience.

GeolocateControl

The GeolocateControl component in the react-bkoi-gl package allows users to center the map on their current location. By leveraging the device's GPS capabilities, it provides a seamless way for users to quickly view their position on the map. This feature is particularly useful for location-based services, navigation, and enhancing user experience in applications where finding one's location is crucial. The control ensures users can easily orient themselves within the map, improving engagement and interactivity.

ScaleControl

The ScaleControl component in the react-bkoi-gl package displays a scale bar on the map, helping users understand distances between points on the map. This visual guide dynamically adjusts as users zoom in or out, offering a clear representation of scale relative to the map’s current zoom level. It enhances map usability by providing a quick reference for measuring distances, making it especially useful in mapping, navigation, and geographic analysis applications. The ScaleControl ensures users can easily gauge real-world distances, improving the overall user experience.

Example

"use client";
import { useRef } from 'react';
import { Map, FullscreenControl, NavigationControl, GeolocateControl, ScaleControl } from 'react-bkoi-gl'; // Import the Barikoi React GL package
import "react-bkoi-gl/styles"; // Import CSS for proper map styling

const App = () => {
const BARIKOI_API_KEY = 'YOUR_BARIKOI_API_KEY_HERE'
const mapStyle = `https://map.barikoi.com/styles/osm-liberty/style.json?key=${BARIKOI_API_KEY}`
const mapContainer = useRef(null);
const mapRef = useRef(null);
const initialViewState = {
longitude: 90.36402,
latitude: 23.823731,
minZoom: 4,
maxZoom: 30,
zoom: 13,
bearing: 0,
pitch: 0,
antialias: true
}

return (
<div
ref={mapContainer} style={containerStyles}
>
<Map
ref={mapRef}
mapStyle={mapStyle}
style={{ width: "100%", height: "100%" }}
initialViewState={initialViewState}
doubleClickZoom={false}
dragRotate={false}
attributionControl={false}
>
<FullscreenControl position="top-right" />
<NavigationControl position="top-right" />
<GeolocateControl position="top-right" />
<ScaleControl position="bottom-right" />
</Map>
</div>
)
}

// JSX Styles
const containerStyles = {
width: "100%",
height: "100vh",
minHeight: "400px",
overflow: "hidden",
}

export default App