Marker bug fix

This commit is contained in:
Eric van der Vlist 2022-11-03 12:19:21 +01:00
parent ba78422a29
commit 45ab894622
1 changed files with 15 additions and 5 deletions

View File

@ -11,18 +11,28 @@ export interface MarkerProperties {
}
export const Marker: react.FC<MarkerProperties> = (props: MarkerProperties) => {
if (props.keyObject === undefined || props.zoom === undefined) return null;
if (
props.keyObject === undefined ||
props.zoom === undefined ||
props.viewPort === undefined
) {
console.log(`Marker props undefined: ${JSON.stringify(props)} `);
return null;
}
const x = lon2tile(props.coordinates.lon, 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 ||
x > props.viewPort.bottomRight.x + 1 ||
y < props.viewPort.topLeft.y ||
y > props.viewPort.bottomRight.y
)
y > props.viewPort.bottomRight.y + 1
) {
console.log(
`Marker ${x}, ${y} out of viewport: ${JSON.stringify(props.viewPort)} `
);
return null;
}
return (
<g transform={`translate(${x}, ${y}) scale(${1 / props.zoom})`}>
{props.icon}