mirror of
https://github.com/pds-nest/nest.git
synced 2024-11-24 22:14:18 +00:00
🐛 Allow negative coordinates
This commit is contained in:
parent
c1c73caa2e
commit
18cff8a10a
3 changed files with 11 additions and 5 deletions
|
@ -2,6 +2,7 @@ import React, { useCallback, useEffect, useMemo, useState } from "react"
|
||||||
import Style from "./BoxMap.module.css"
|
import Style from "./BoxMap.module.css"
|
||||||
import BoxFull from "./BoxFull"
|
import BoxFull from "./BoxFull"
|
||||||
import { MapContainer, TileLayer } from "react-leaflet"
|
import { MapContainer, TileLayer } from "react-leaflet"
|
||||||
|
import Coordinates from "../../objects/Coordinates"
|
||||||
|
|
||||||
|
|
||||||
export default function BoxMap(
|
export default function BoxMap(
|
||||||
|
@ -14,7 +15,7 @@ export default function BoxMap(
|
||||||
const [map, setMap] = useState(null)
|
const [map, setMap] = useState(null)
|
||||||
|
|
||||||
const onMapMove = useCallback(
|
const onMapMove = useCallback(
|
||||||
() => mapViewHook.setCenter(map.getCenter()),
|
() => mapViewHook.setCenter(Coordinates.fromLatLng(map.getCenter())),
|
||||||
[mapViewHook, map],
|
[mapViewHook, map],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
* A pair of coordinates, latitude `lat` and longitude `lng`.
|
* A pair of coordinates, latitude `lat` and longitude `lng`.
|
||||||
*/
|
*/
|
||||||
import { LatLng } from "leaflet/dist/leaflet-src.esm"
|
import { LatLng } from "leaflet/dist/leaflet-src.esm"
|
||||||
|
import { SerializationError } from "./Errors"
|
||||||
|
|
||||||
|
|
||||||
export default class Coordinates {
|
export default class Coordinates {
|
||||||
|
@ -24,11 +25,15 @@ export default class Coordinates {
|
||||||
* @returns {Coordinates}
|
* @returns {Coordinates}
|
||||||
*/
|
*/
|
||||||
static fromCrawlerString(str) {
|
static fromCrawlerString(str) {
|
||||||
const match = /[{]([0-9.]+),([0-9.]+)[}]/.exec(str)
|
const match = /[{]([0-9.-]+),([0-9.-]+)[}]/.exec(str)
|
||||||
if(!match) {
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -34,7 +34,7 @@ export default class MapArea {
|
||||||
return new MapArea(osmZoomLevels[zoom], center)
|
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) {
|
static fromRaw(data) {
|
||||||
const match = this.rawRegex.exec(data)
|
const match = this.rawRegex.exec(data)
|
||||||
|
|
Loading…
Reference in a new issue