positic
manipulate positions from GeoJSON.
install
$ npm install --save positic
or
$ yarn add positic
Usage
Javascript
// CommonsJsconst createTrack = createTrack; // ES Modules;
TypeScript
; ;
api
createTrack: (positions: Positions[]) => Track
Given any valid position array, return an object that manipulate positions and calculate data.
type definitions
- based types
;;;;;;
;
;
;
;
- Track
;
Track usage
; const positions = 577367 4507122 279608 577367 4507122 279608 577407 4507117 279926 577467 4507108 280112 577487 4507091 280871 577501 4507069 281516 577515 4507045 282205 577573 4507057 280301 ... 630269 4554447 320 630273 4554463 320 630281 455447 320 630275 4554486 320 630267 4554509 320 630259 4554522 320 630245 4554534 320 630233 4554542 320 ; const track = ;
or
const track = ;
- calculate track length
const distance = track;// distance = 144670 (in meters);
- calculate track elevation
const elevation = track;// elevation = {positive:1243.33, negative:1209.34} (in meters)
- calculate track bounding box
const area = track;// area = {// "maxLatitude": 45.55014,// "maxLongitude": 6.30281,// "minLatitude": 45.06822,// "minLongitude": 5.77311,// }
- get positions at 10km and 20km marks
const marks = 10000 20000;const positions = get;// positions = [// [5.77501, 45.07069, 281.516],// [6.30259, 45.54522, 320],//]
- find the closest track position to a given position
const PARIS = 23488 488534;const closestPosition = track;// closestPosition = [6.30259, 45.54522, 320]
- get progression statistics
const currentIndex = 1200;const statistics = track;// statistics = [120.23, 6787.34, 5683.22] (distance in meters, positive elevation in meters, negative elevation in meters)
generic helper functions
- calculate distance between two positions
; const origin = 37618423 55751244;const destination = 23488 488534; const distance = ;// distance = 2486688.9750256147 (in meters)
- calculate bearing between two positions
; const origin = -394915 512194;const destination = -395935 512392; const bearing = ;// bearing = 342.1247653798634 (in deg)
- check if position is in a given area
; const current = -394915 512194; const area = maxLatitude: 4907122 minLatitude: 4007122 minLongitude: 177367 maxLongitude: 977367;const isIn = ;// isIn = true / false
- check if position is in a given radius
; const current = -394915 512194;const center = 623828 4550127 888336;const radius = 70; const isIn = location;// isIn = true / false
TypeScript
positic includes TypeScript definitions.