我目前正在與 algolia 合作,我對地圖有一些奇怪的問題。我有這個界面(左欄是結果,右欄是地圖)就像這張圖片:

當我試圖拖動我的地圖時,我得到了幾秒鐘的結果,這是我需要的,但由于某種原因,它們從搜索框重置為以前的結果。我的地圖代碼是這樣的:
const Marker = ({ hit }: { hit: any }) => {
const rHit = hit;
return (
<CustomMarker
key={rHit.objectID}
hit={rHit}
anchor={{ x: 0, y: (rHit.position - rHit.count) * 50 }} // if there are several markers at the exact same position
>
<ArtistsMarker hit={rHit} />
</CustomMarker>
);
};
const Map: FC<MapProps> = ({ fullscreen }): ReactElement => {
const [google, setGoogle] = useState<any>();
useEffect(() => {
if (window) {
setGoogle(window.google);
}
}, []);
const getKey = (hit: any): string => `${hit._geoloc.lat} ${hit._geoloc.lng}`;
const groupThoseWithIdenticalCoordinates = (array: any[]) =>
array.reduce((acc, value) => {
if (!acc[getKey(value)]) {
acc[getKey(value)] = [];
}
acc[getKey(value)].push(value);
value.position = acc[getKey(value)].length;
return acc;
}, []);
const addPositionForIdenticalCoordinates = (
array: any[],
grouped: any
): any[] =>
array.map((e: any) => ({ ...e, count: grouped[getKey(e)].length }));
return google ? (
<GeoSearch
google={google}
enableRefine={true}
enableRefineOnMapMove={true}
maxZoom={17}
gestureHandling={fullscreen ? 'cooperative' : 'greedy'}
>
{(value: any) => {
const grouped = groupThoseWithIdenticalCoordinates(value.hits);
const hits = addPositionForIdenticalCoordinates(value.hits, grouped);
const markers = hits.map((hit: any) => (
<Marker hit={hit} key={hit.uid} />
));
return (
<div>
<Control />
{markers}
</div>
);
}}
</GeoSearch>
) : (
<></>
);
};
export default Map;
我還注意到在我的控制臺中,searchState 物件有時會錯過 boundingBox 物件,如下所示:

也許有人知道它為什么會發生或我應該在哪里搜索?
uj5u.com熱心網友回復:
該問題是由過濾器引起的。我按位置過濾了結果,這就是為什么我回傳到以前的位置。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/477139.html
