import React, { useEffect, useRef } from 'react'; import maplibregl from 'maplibre-gl'; import { createAmplifyGeocoder } from 'maplibre-gl-js-amplify'; import { useControl, useMap } from 'react-map-gl'; import type { IControl } from 'react-map-gl'; import { LocationSearchProps } from '../types/maplibre-gl-geocoder'; const LOCATION_SEARCH_OPTIONS = { maplibregl, marker: { color: '#3FB1CE' }, popup: true, showResultMarkers: { color: '#3FB1CE' }, showResultsWhileTyping: true, }; const LOCATION_SEARCH_CONTAINER = 'geocoder-container'; type AmplifyLocationSearch = IControl & { addTo: (container: string) => void; }; const LocationSearchControl = ({ position = 'top-right', ...props }: LocationSearchProps) => { useControl( () => createAmplifyGeocoder(props) as unknown as AmplifyLocationSearch, { position, } ); return null; }; const LocationSearchStandalone = (props: LocationSearchProps) => { const hasMounted = useRef(false); useEffect(() => { if (!hasMounted.current) { (createAmplifyGeocoder(props) as unknown as AmplifyLocationSearch).addTo( `#${LOCATION_SEARCH_CONTAINER}` ); hasMounted.current = true; } }, [props]); return
; }; /** * The `