Frontline
This commit is contained in:
@@ -2,8 +2,8 @@ import * as turf from "@turf/turf";
|
||||
import { toMercator, toWgs84 } from '@turf/projection';
|
||||
|
||||
//CIRCLE
|
||||
const distancePerDegreeLongitude = 111.320; // 2π×6378.1km/360
|
||||
const distancePerDegreeLatitude = 110.574; // 2π×6356.75km/360
|
||||
const DISTANCE_PER_DEGREE_LONGITUDE = 111.320; // 2π×6378.1km/360
|
||||
const DISTANCE_PER_DEGREE_LATITUDE = 110.574; // 2π×6356.75km/360
|
||||
|
||||
//GEOJSON
|
||||
/**
|
||||
@@ -16,15 +16,20 @@ const distancePerDegreeLatitude = 110.574; // 2π×6356.75km/360
|
||||
* @returns {GeoJSON.Feature<GeoJSON.Polygon>} GeoJSON Feature representing the circle polygon.
|
||||
*/
|
||||
export function getCirclePolygon(center, radius, density = 64) {
|
||||
if (!center || !radius ) {
|
||||
console.warn("getCirclePolygon: Invalid center, radius.");
|
||||
return [];
|
||||
}
|
||||
|
||||
const points = [];
|
||||
|
||||
const coords = {
|
||||
latitude: center[1], // Latitude
|
||||
longitude: center[0] // Longitude
|
||||
latitude: center[1],
|
||||
longitude: center[0]
|
||||
};
|
||||
|
||||
const distanceX = radius / (distancePerDegreeLongitude * Math.cos(coords.latitude * Math.PI / 180));
|
||||
const distanceY = radius / distancePerDegreeLatitude;
|
||||
const distanceX = radius / (DISTANCE_PER_DEGREE_LONGITUDE * Math.cos(coords.latitude * Math.PI / 180));
|
||||
const distanceY = radius / DISTANCE_PER_DEGREE_LATITUDE;
|
||||
|
||||
for (let i = 0; i < density; i++) {
|
||||
const angle = (i / density) * Math.PI * 2;
|
||||
@@ -37,6 +42,7 @@ export function getCirclePolygon(center, radius, density = 64) {
|
||||
points.push(points[0]);
|
||||
|
||||
return turf.polygon([[...points]]);
|
||||
/*
|
||||
return {
|
||||
"type": "Feature",
|
||||
"geometry": {
|
||||
@@ -44,7 +50,7 @@ export function getCirclePolygon(center, radius, density = 64) {
|
||||
"coordinates": [points]
|
||||
},
|
||||
"properties": {}
|
||||
};
|
||||
};*/
|
||||
}
|
||||
//GEOJSON
|
||||
//CANVAS
|
||||
@@ -58,6 +64,11 @@ export function getCirclePolygon(center, radius, density = 64) {
|
||||
* @returns {{x: number, y: number}[]} An array of points representing the vertices of the circle polygon.
|
||||
*/
|
||||
export function getCirclePolygonEuclidean(center, radius, density) {
|
||||
if (!center || !radius || !density) {
|
||||
console.warn("getCirclePolygonEuclidean: Invalid center, radius or density.");
|
||||
return [];
|
||||
}
|
||||
|
||||
const points = [];
|
||||
for (let i = 0; i < density; i++) {
|
||||
const angle = (i / density) * Math.PI * 2;
|
||||
@@ -83,6 +94,11 @@ export function getCirclePolygonEuclidean(center, radius, density) {
|
||||
* @returns {GeoJSON.Feature<GeoJSON.Polygon>} GeoJSON Feature representing the rectangle polygon.
|
||||
*/
|
||||
export function getRectanglePolygon(center, width, height, rotation = 0) {
|
||||
if (!center || !width || !height) {
|
||||
console.warn("getRectanglePolygon: Invalid center, width or height.");
|
||||
return [];
|
||||
}
|
||||
|
||||
const widthMeters = width * 1000 ;
|
||||
const heightMeters = height * 1000;
|
||||
|
||||
@@ -130,7 +146,12 @@ function rotateXY(x, y, cx, cy, angleRad) {
|
||||
*
|
||||
* @returns {{x: number, y: number}[]} An array of points representing the vertices of the rectangle polygon.
|
||||
*/
|
||||
export function getRectanglePolygonEuclidean(center, sideA, sideB, rotation) {
|
||||
export function getRectanglePolygonEuclidean(center, sideA, sideB, rotation = 0) {
|
||||
if (!center || !sideA || !sideB) {
|
||||
console.warn("getRectanglePolygonEuclidean: Invalid center, sideA or sideB.");
|
||||
return [];
|
||||
}
|
||||
|
||||
const halfA = sideA / 2;
|
||||
const halfB = sideB / 2;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user