1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-10-16 20:17:25 +00:00

🐛 Allow negative coordinates

This commit is contained in:
Steffo 2021-05-24 14:28:53 +02:00
parent c1c73caa2e
commit 18cff8a10a
Signed by: steffo
GPG key ID: 6965406171929D01
3 changed files with 11 additions and 5 deletions

View file

@ -2,6 +2,7 @@ import React, { useCallback, useEffect, useMemo, useState } from "react"
import Style from "./BoxMap.module.css"
import BoxFull from "./BoxFull"
import { MapContainer, TileLayer } from "react-leaflet"
import Coordinates from "../../objects/Coordinates"
export default function BoxMap(
@ -14,7 +15,7 @@ export default function BoxMap(
const [map, setMap] = useState(null)
const onMapMove = useCallback(
() => mapViewHook.setCenter(map.getCenter()),
() => mapViewHook.setCenter(Coordinates.fromLatLng(map.getCenter())),
[mapViewHook, map],
)

View file

@ -2,6 +2,7 @@
* A pair of coordinates, latitude `lat` and longitude `lng`.
*/
import { LatLng } from "leaflet/dist/leaflet-src.esm"
import { SerializationError } from "./Errors"
export default class Coordinates {
@ -24,11 +25,15 @@ export default class Coordinates {
* @returns {Coordinates}
*/
static fromCrawlerString(str) {
const match = /[{]([0-9.]+),([0-9.]+)[}]/.exec(str)
const match = /[{]([0-9.-]+),([0-9.-]+)[}]/.exec(str)
if(!match) {
throw new Error(`Invalid location string: ${str}`)
throw new SerializationError(str)
}
return new Coordinates(match[1], match[2])
return new Coordinates(Number(match[1]), Number(match[2]))
}
static fromLatLng(latlng) {
return new Coordinates(latlng.lat, latlng.lng)
}
/**

View file

@ -34,7 +34,7 @@ export default class MapArea {
return new MapArea(osmZoomLevels[zoom], center)
}
static rawRegex = /^< (?<radius>[0-9.]+) (?<lat>[0-9.]+) (?<lng>[0-9.]+)$/
static rawRegex = /^< (?<radius>[0-9.]+) (?<lat>[0-9.-]+) (?<lng>[0-9.-]+)$/
static fromRaw(data) {
const match = this.rawRegex.exec(data)