Skip to content

Commit

Permalink
Fix terra draw error when precision is over max
Browse files Browse the repository at this point in the history
  • Loading branch information
hvangeffen committed Apr 25, 2024
1 parent ed184ba commit 181c376
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/components/map/DrawBoundingBoxControl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,28 @@ watch(
() => {
draw.clear()
if (modelValue.value !== null) {
// Round to 9 decimal places as this is the default max precision in terra draw
// https://github.com/JamesLMilner/terra-draw/blob/main/src/adapters/common/base.adapter.ts#L46
const round = (value: number) => {
return Math.round(value * 1000000000) / 1000000000
}
const lonMin = round(modelValue.value.lonMin)
const lonMax = round(modelValue.value.lonMax)
const latMin = round(modelValue.value.latMin)
const latMax = round(modelValue.value.latMax)
const feature: GeoJSONStoreFeatures = {
type: 'Feature',
geometry: {
type: 'Polygon',
coordinates: [
[
[modelValue.value.lonMin, modelValue.value.latMin],
[modelValue.value.lonMax, modelValue.value.latMin],
[modelValue.value.lonMax, modelValue.value.latMax],
[modelValue.value.lonMin, modelValue.value.latMax],
[modelValue.value.lonMin, modelValue.value.latMin],
[lonMin, latMin],
[lonMax, latMin],
[lonMax, latMax],
[lonMin, latMax],
[lonMin, latMin]
],
],
},
Expand Down

0 comments on commit 181c376

Please sign in to comment.