Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions GeofenceGenerator/GeofenceGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ async function request() {
polygons[i].remove()
}
polygons = []
features = []

// Remove crop polygon and enable button its button
if (crop_polygon != null) {
Expand Down Expand Up @@ -154,6 +155,10 @@ function apply_crop() {
// Apply to all features
const crop_JSON = crop_polygon.toGeoJSON()
for (const feature of features) {
if ((feature.geometry.type != "Polygon") && (feature.geometry.type != "MultiPolygon")) {
// Only polygons can be cropped, the others are not displayed
continue
}
const cropped = turf.intersect(feature, crop_JSON)
if (cropped != null) {
cropped.id = feature.id,
Expand Down Expand Up @@ -230,7 +235,8 @@ async function generate_fence(feature, name) {
// Convert to cartesian
const cartesian = { x: new Array(len), y: new Array(len) }
for (let i = 0; i<len; i++) {
const points = polys[i]
// Work on a copy so downloading does not edit the feature
const points = polys[i].slice()
let xy_len = points.length
if ((points[0][0] == points[xy_len-1][0]) && (points[0][1] == points[xy_len-1][1])) {
// Drop last point if it is the same as the first
Expand Down Expand Up @@ -259,8 +265,8 @@ async function generate_fence(feature, name) {

// Save to file
// sanitize name for use in file
name = name.replace('/', '_')
name = name.replace('\\', '_')
name = name.replaceAll('/', '_')
name = name.replaceAll('\\', '_')

let text = 'QGC WPL 110\n'
let points = 1
Expand Down Expand Up @@ -295,7 +301,12 @@ async function generate_fence(feature, name) {
}

function wrap_180(angle) {
return ((angle + 180) % 360) - 180;
// JS remainder keeps the sign of the dividend, so shift negative results up
let wrapped = (angle + 180) % 360
if (wrapped < 0) {
wrapped += 360
}
return wrapped - 180;
}

function longitude_scale(lat) {
Expand Down
Loading