Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
holi-app-volunteering
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
app
holi-app-volunteering
Commits
2d0058e2
Commit
2d0058e2
authored
1 year ago
by
Taha Cherfia
Browse files
Options
Downloads
Patches
Plain Diff
HOLI-5486: add util function to calculate radius
parent
79c70820
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/utils.ts
+38
-0
38 additions, 0 deletions
app/utils.ts
with
38 additions
and
0 deletions
app/utils.ts
0 → 100644
+
38
−
0
View file @
2d0058e2
import
{
GeolocationGeometry
}
from
"
./types.ts
"
;
import
{
turf
}
from
"
./deps.ts
"
;
import
{
ApiDefaults
}
from
"
./api_types.ts
"
;
/**
* Calculates the radius of a given polygon or multi-polygon geometry.
*
* @param {GeolocationGeometry} geometry - The input geometry to calculate the radius for.
* @returns {number} The calculated radius in kilometers.
*/
export
function
calculateRadius
(
geometry
:
GeolocationGeometry
)
{
if
(
geometry
.
type
!==
"
Polygon
"
&&
geometry
.
type
!==
"
MultiPolygon
"
)
{
return
ApiDefaults
.
MIN_RADIUS
;
}
const
center
=
turf
.
center
(
geometry
);
const
vertices
=
turf
.
explode
(
geometry
);
let
maxDistance
:
number
=
ApiDefaults
.
MIN_RADIUS
;
turf
.
coordEach
(
vertices
,
(
vertice
)
=>
{
const
distance
=
turf
.
distance
(
center
,
turf
.
point
(
vertice
),
{
units
:
"
kilometers
"
,
});
if
(
distance
>
maxDistance
)
{
maxDistance
=
distance
;
}
});
const
radius
=
Math
.
ceil
(
maxDistance
);
if
(
radius
>=
ApiDefaults
.
MAX_RADIUS
)
{
return
ApiDefaults
.
MAX_RADIUS
;
}
return
radius
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment