UNPKG

make-geo-json

Version:

Converts polylines, wkts, wkbs, polygons, circles, rectangles, as well as standard geoJSON into geoJSON MultiPolygon Feature Objects. Converts wkb_list and FeatureCollection to arrays.

30 lines (26 loc) 741 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = rectFrom2Points; // input p_1 = [ <long>, <lat> ] p_2 = [ <long>, <lat> ] const dist = (p_1, p_2) => Math.sqrt((p_1[0] - p_2[0]) ** 2 + (p_1[1] - p_2[1]) ** 2); function rectFrom2Points(p_1, p_2) { const d = dist(p_1, p_2) / 2; const r = []; if (p_1[0] < p_2[0]) { r.push([p_1[0] - d, p_1[1]]); r.push([p_2[0] + d, p_2[1]]); } else { r.push([p_2[0] - d, p_2[1]]); r.push([p_1[0] + d, p_1[1]]); } if (p_1[1] < p_2[1]) { r.push([p_1[0], p_1[1] - d]); r.push([p_2[0], p_2[1] + d]); } else { r.push([p_2[0], p_2[1] - d]); r.push([p_1[0], p_1[1] + d]); } return [r[0], r[2], r[1], r[3], r[0]]; }