Markers check that they belong to the current viewport to display.
This commit is contained in:
parent
c4094b28ae
commit
ba78422a29
|
@ -1,11 +1,12 @@
|
||||||
import { atom, useAtom } from 'jotai';
|
import { atom, useAtom } from 'jotai';
|
||||||
import react from 'react';
|
import react from 'react';
|
||||||
import Marker from './Marker';
|
import Marker from './Marker';
|
||||||
import { geoPoint, TileKeyObject } from './types';
|
import { geoPoint, Rectangle, TileKeyObject } from './types';
|
||||||
|
|
||||||
export interface CurrentLocationProperties {
|
export interface CurrentLocationProperties {
|
||||||
keyObject?: TileKeyObject;
|
keyObject?: TileKeyObject;
|
||||||
zoom?: number;
|
zoom?: number;
|
||||||
|
viewPort?: Rectangle;
|
||||||
}
|
}
|
||||||
|
|
||||||
const initialLocation: geoPoint | null = null;
|
const initialLocation: geoPoint | null = null;
|
||||||
|
@ -33,6 +34,7 @@ export const CurrentLocation: react.FC<CurrentLocationProperties> = (
|
||||||
}
|
}
|
||||||
keyObject={props.keyObject}
|
keyObject={props.keyObject}
|
||||||
zoom={props.zoom}
|
zoom={props.zoom}
|
||||||
|
viewPort={props.viewPort}
|
||||||
/>
|
/>
|
||||||
) : null;
|
) : null;
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,6 +15,14 @@ export const Marker: react.FC<MarkerProperties> = (props: MarkerProperties) => {
|
||||||
|
|
||||||
const x = lon2tile(props.coordinates.lon, props.keyObject.zoomLevel);
|
const x = lon2tile(props.coordinates.lon, props.keyObject.zoomLevel);
|
||||||
const y = lat2tile(props.coordinates.lat, props.keyObject.zoomLevel);
|
const y = lat2tile(props.coordinates.lat, props.keyObject.zoomLevel);
|
||||||
|
if (props.viewPort === undefined) return null;
|
||||||
|
if (
|
||||||
|
x < props.viewPort.topLeft.x ||
|
||||||
|
x > props.viewPort.bottomRight.x ||
|
||||||
|
y < props.viewPort.topLeft.y ||
|
||||||
|
y > props.viewPort.bottomRight.y
|
||||||
|
)
|
||||||
|
return null;
|
||||||
return (
|
return (
|
||||||
<g transform={`translate(${x}, ${y}) scale(${1 / props.zoom})`}>
|
<g transform={`translate(${x}, ${y}) scale(${1 / props.zoom})`}>
|
||||||
{props.icon}
|
{props.icon}
|
||||||
|
|
Loading…
Reference in New Issue