);
};
export default BarikoiAutocompleteComponent;
```
--------------------------------
### useMap Hook
Source: https://context7.com/barikoi/barikoi-map-widget/llms.txt
Provides access to map-related state managed by BarikoiMapProvider. Exposes zoom level, center point coordinates, and marker data with their setter functions for programmatic map control.
```APIDOC
## useMap Hook
### Description
The `useMap` hook provides access to the map-related state managed by `BarikoiMapProvider`. It exposes the current zoom level, center point coordinates, and marker data along with their setter functions for programmatic map control.
### Usage
```tsx
import { useEffect } from 'react';
import { useAutocomplete, useMap } from 'barikoi-map-widget';
const MapController = () => {
const { selectedPlace } = useAutocomplete();
const {
zoomLevel,
setZoomLevel,
centerPoint,
setCenterPoint,
markerData,
setMarkerData
} = useMap();
// Sync map center with selected place from autocomplete
useEffect(() => {
if (selectedPlace?.latitude && selectedPlace?.longitude) {
setCenterPoint({
lat: parseFloat(selectedPlace.latitude),
lng: parseFloat(selectedPlace.longitude)
});
}
}, [selectedPlace, setCenterPoint]);
const handleGoToDhaka = () => {
setCenterPoint({ lat: 23.8103, lng: 90.4125 });
};
return (
Current Center: {centerPoint.lat}, {centerPoint.lng}
Zoom Level: {zoomLevel}
);
};
export default MapController;
```
### State Variables Exposed
- **zoomLevel** (number): Current zoom level.
- **setZoomLevel** (function): Function to set zoom level.
- **centerPoint** ({ lat: number, lng: number }): Current center coordinates.
- **setCenterPoint** (function): Function to set center point.
- **markerData** (array): Array of marker data.
- **setMarkerData** (function): Function to set marker data.
```
--------------------------------
### useAutocomplete Hook
Source: https://context7.com/barikoi/barikoi-map-widget/llms.txt
Provides access to autocomplete-related state managed by BarikoiMapProvider. Exposes search text, selected place, suggestions, and loading state with their setter functions.
```APIDOC
## useAutocomplete Hook
### Description
The `useAutocomplete` hook provides access to the autocomplete-related state managed by `BarikoiMapProvider`. It exposes the current search text, selected place, suggestions list, and loading state along with their setter functions for custom implementations.
### Usage
```tsx
import { useAutocomplete } from 'barikoi-map-widget';
const CustomAutocompleteDisplay = () => {
const {
searchedPlace,
setSearchedPlace,
selectedPlace,
setSelectedPlace,
suggestions,
setSuggestions,
isAutocompleteLoading,
setIsAutocompleteLoading
} = useAutocomplete();
return (
);
};
export default CustomAutocompleteDisplay;
```
### State Variables Exposed
- **searchedPlace** (string): Current search input value.
- **setSearchedPlace** (function): Function to update search input.
- **selectedPlace** (object): Currently selected place object.
- **setSelectedPlace** (function): Function to set selected place.
- **suggestions** (array): Array of autocomplete suggestions.
- **setSuggestions** (function): Function to update suggestions.
- **isAutocompleteLoading** (boolean): Boolean indicating loading state.
- **setIsAutocompleteLoading** (function): Function to set loading state.
```
--------------------------------
### BarikoiAutocomplete Component
Source: https://github.com/barikoi/barikoi-map-widget/blob/main/README.md
The BarikoiAutocomplete component provides a customizable search input with autocomplete suggestions.
```APIDOC
## BarikoiAutoComplete
The **BarikoiAutoComplete** component is a customizable search input field with real-time autocomplete suggestions fetched from the **Barikoi API**. It supports **debounced search**, **smooth dropdown animations**, and allows **custom styling** via `className` props.
### Basic Example
```tsx
import { BarikoiAutocomplete } from 'barikoi-map-widget';
const BarikoiAutocompleteComponent = () => {
return (
Search
);
};
export default BarikoiAutocompleteComponent;
```
### Props
| **Prop Name** | **Type** | **Required** | **Description** |
| ------------- | -------- | ------------ | --------------------------------------------------------------- |
| `apiKey` | `string` | ✅ Yes | Your **Barikoi API key** for fetching autocomplete suggestions. |
| `className` | `object` | ❌ No | Object to override default styles using CSS class names. |
### Class Name Object Structure
| **Key** | **Type** | **Description** |
| ----------------- | -------- | ------------------------------------- |
| `container` | `string` | Class for the main container. |
| `input` | `string` | Class for the input field. |
| `dropdown` | `string` | Class for the dropdown container. |
| `dropdownVisible` | `string` | Class for the dropdown visibility. |
| `dropdownItem` | `string` | Class for each dropdown item. |
| `noResult` | `string` | Class for "No Results Found" message. |
| `clearButton` | `string` | Class for clear button. |
### Styling
The component uses **default inline styles** but allows **className** overrides. Below is an example of CSS customizations:
```css
/* customStyles.css */
.custom-container {
border: 2px solid blue;
border-radius: 6px;
}
.custom-input {
font-size: 16px;
border: 1px solid #aaa;
}
.custom-dropdown {
border: 1px solid green;
background-color: #f9fafb;
}
.custom-dropdown-item {
padding: 12px;
font-weight: bold;
}
.custom-no-result {
color: red;
font-style: italic;
}
```
### State Management
The BarikoiAutoComplete component uses the following state variables to manage its internal state:
- `searchedPlace`: Tracks the current search input value.
- `setSearchedPlace`: A function to update the searchedPlace state.
- `selectedPlace`: Stores the place that the user has selected from the autocomplete suggestions.
- `setSelectedPlace`: A function to update the selectedPlace state.
- `suggestions`: Contains the list of autocomplete suggestions fetched from the API.
- `setSuggestions`: A function to update the suggestions state.
- `isAutocompleteLoading`: A boolean that indicates whether the autocomplete data is being fetched.
- `setIsAutocompleteLoading`: A function to update the isAutocompleteLoading state.
```
--------------------------------
### Integrate Barikoi Map and Autocomplete in React
Source: https://context7.com/barikoi/barikoi-map-widget/llms.txt
Connects the autocomplete search component with the map view using the BarikoiMapProvider and custom hooks. Requires a valid Barikoi API key and React 18+.
```tsx
import { useEffect } from 'react';
import {
BarikoiMapProvider,
BarikoiAutocomplete,
BarikoiMap,
useAutocomplete,
useMap
} from 'barikoi-map-widget';
// Component that connects autocomplete and map
const BarikoiMapWidget = () => {
const { selectedPlace } = useAutocomplete();
const { setCenterPoint } = useMap();
const BARIKOI_API_KEY = 'YOUR_BARIKOI_API_KEY';
const initialViewState = {
longitude: 90.36402,
latitude: 23.823731,
minZoom: 4,
maxZoom: 30,
zoom: 16
};
// Update map center when a place is selected
useEffect(() => {
if (selectedPlace?.latitude && selectedPlace?.longitude) {
setCenterPoint({
lat: parseFloat(selectedPlace.latitude),
lng: parseFloat(selectedPlace.longitude)
});
}
}, [selectedPlace, setCenterPoint]);
return (
);
};
// Main App with Provider wrapper
const App = () => {
return (
);
};
export default App;
// CSS required
// .map-container { width: 100%; height: 100%; min-height: 500px; }
```
--------------------------------
### Basic Barikoi Map Widget Usage
Source: https://github.com/barikoi/barikoi-map-widget/blob/main/README.md
Integrate the BarikoiMap component into your React application. Ensure you replace 'YOUR_BARIKOI_API_KEY' with your actual API key and adjust the initial view state and map style as needed.
```tsx
import { BarikoiMap } from 'barikoi-map-widget';
const BarikoiMapComponent = () => {
const BARIKOI_API_KEY = 'YOUR_BARIKOI_API_KEY'; // Replace with your actual API key
const initialViewState = {
longitude: 90.36402,
latitude: 23.823731,
minZoom: 4,
maxZoom: 30,
zoom: 16,
};
return (
);
};
export default BarikoiMapComponent;
```
--------------------------------
### BarikoiMap Component
Source: https://github.com/barikoi/barikoi-map-widget/blob/main/README.md
The BarikoiMap component is the primary interface for rendering the map. It requires an API key and allows for extensive customization of controls and styles.
```APIDOC
## BarikoiMap Component
### Description
The BarikoiMap component renders an interactive map using the Barikoi service. It supports various controls such as geolocating, fullscreen toggles, and custom markers.
### Props
- **apiKey** (string) - Required - Your Barikoi API key.
- **initialViewState** (object) - Optional - Initial map view state (longitude, latitude, zoom, minZoom, maxZoom).
- **controls** (object) - Optional - Configuration for map controls (geolocate, fullscreen, navigation, scale, marker).
- **mapStyle** (string) - Optional - The visual style of the map (e.g., 'osm-liberty', 'barikoi-dark').
- **className** (string) - Required - CSS class name for the container.
### Request Example
```
--------------------------------
### BarikoiMap Component
Source: https://github.com/barikoi/barikoi-map-widget/blob/main/README.md
The BarikoiMap component renders a map with customizable controls and view settings.
```APIDOC
## BarikoiMap
The **BarikoiMap** component is a customizable React component designed to render a map using the Barikoi Maps service. It provides several map controls, such as geolocation, fullscreen mode, and scale controls, and allows for dynamic positioning of a marker. The map’s initial view state and style are customizable, and the component provides an API key to integrate with Barikoi’s map services.
```
--------------------------------
### Use Autocomplete Hook for Custom Display
Source: https://context7.com/barikoi/barikoi-map-widget/llms.txt
Use the useAutocomplete hook to access and manage autocomplete state, including search text, selected place, suggestions, and loading status. This is useful for building custom UI components that display search results or interact with selected locations.
```tsx
import { useAutocomplete } from 'barikoi-map-widget';
const CustomAutocompleteDisplay = () => {
const {
searchedPlace,
setSearchedPlace,
selectedPlace,
setSelectedPlace,
suggestions,
setSuggestions,
isAutocompleteLoading,
setIsAutocompleteLoading
} = useAutocomplete();
return (
);
};
export default CustomAutocompleteDisplay;
```
--------------------------------
### CSS for Map Container
Source: https://github.com/barikoi/barikoi-map-widget/blob/main/README.md
Apply this CSS to style the map container. Adjust width and height to fit your layout requirements.
```css
.map-container {
width: 100%;
height: 100vh;
}
```
--------------------------------
### Use Map Hook for Programmatic Map Control
Source: https://context7.com/barikoi/barikoi-map-widget/llms.txt
The useMap hook provides access to map state like zoom level and center coordinates, along with functions to update them. It also exposes marker data and its setter. This hook is essential for controlling map behavior programmatically, such as centering the map on a selected place or adjusting zoom.
```tsx
import { useEffect } from 'react';
import { useAutocomplete, useMap } from 'barikoi-map-widget';
const MapController = () => {
const { selectedPlace } = useAutocomplete();
const {
zoomLevel,
setZoomLevel,
centerPoint,
setCenterPoint,
markerData,
setMarkerData
} = useMap();
// Sync map center with selected place from autocomplete
useEffect(() => {
if (selectedPlace?.latitude && selectedPlace?.longitude) {
setCenterPoint({
lat: parseFloat(selectedPlace.latitude),
lng: parseFloat(selectedPlace.longitude)
});
}
}, [selectedPlace, setCenterPoint]);
const handleGoToDhaka = () => {
setCenterPoint({ lat: 23.8103, lng: 90.4125 });
};
return (
Current Center: {centerPoint.lat}, {centerPoint.lng}
Zoom Level: {zoomLevel}
);
};
export default MapController;
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.