import React, { ReactElement, useState } from "react"; import { AnyGeocoderQuery } from "./geocoders/types"; import getGeocoder from "./index"; const GeocoderTester = ({ at = { lat: 0, lng: 0 }, endpoint, geocodeEarthApiKey, hereApiKey, onResults }: { at?: { lat: number; lng: number }; endpoint: string; geocodeEarthApiKey: string; hereApiKey: string; onResults: (any) => void; }): ReactElement => { const [searchTerm, setSearchTerm] = useState(""); const [focusPoint, setFocusPoint] = useState({ lat: at.lat, lng: at.lng }); const [boundary, setBoundary] = useState({ maxLat: 48.687912, minLat: 46.981852, maxLon: -121.467028, minLon: -123.148723 }); const [enableBoundary, setEnableBoundary] = useState(false); const [enableFocusPoint, setEnableFocusPoint] = useState(true); const [enableGeocodeEarth, setEnableGeocodeEarth] = useState(true); const [enableHere, setEnableHere] = useState(true); const [enablePhoton, setEnablePhoton] = useState(true); const [enableOtp, setEnableOtp] = useState(false); const [otpHost, setOtpHost] = useState(""); const [ reverseUseFeatureCollection, setReverseUseFeatureCollection ] = useState(false); const hereGeocoder = getGeocoder({ apiKey: hereApiKey, focusPoint, reverseUseFeatureCollection, type: "HERE" }); const peliasGeocoder = getGeocoder({ apiKey: geocodeEarthApiKey, baseUrl: "https://api.geocode.earth/v1", focusPoint, reverseUseFeatureCollection, size: 1, type: "PELIAS" }); const photonGeocoder = getGeocoder({ baseUrl: "https://photon.komoot.io", focusPoint, reverseUseFeatureCollection, size: 1, type: "PHOTON" }); const otpGeocoder = getGeocoder({ baseUrl: otpHost, size: 1, type: "OTP" }); const searchObj: AnyGeocoderQuery = { text: searchTerm }; if (enableBoundary) { searchObj.boundary = { rect: boundary }; } if (enableFocusPoint) { searchObj.point = focusPoint; searchObj.focusPoint = focusPoint; } const search = async () => { const hereRes = enableHere ? await hereGeocoder[endpoint](searchObj) : null; const peliasRes = enableGeocodeEarth ? await peliasGeocoder[endpoint](searchObj) : null; const photonRes = enablePhoton ? await photonGeocoder[endpoint](searchObj) : null; const otpRes = enableOtp ? await otpGeocoder[endpoint](searchObj) : null; onResults({ hereRes, peliasRes, photonRes, otpRes }); }; return (