@turf/midpoint
Advanced tools
+3
-2
| /// <reference types="geojson" /> | ||
| type Point = GeoJSON.Feature<GeoJSON.Point>; | ||
| type Point = GeoJSON.Feature<GeoJSON.Point> | GeoJSON.Point | number[]; | ||
| type Feature = GeoJSON.Feature<GeoJSON.Point>; | ||
@@ -8,4 +9,4 @@ /** | ||
| */ | ||
| declare function midpoint(from: Point, to: Point): Point; | ||
| declare function midpoint(point1: Point, point2: Point): Feature; | ||
| declare namespace midpoint { } | ||
| export = midpoint; |
+11
-25
@@ -10,35 +10,21 @@ var bearing = require('@turf/bearing'); | ||
| * @name midpoint | ||
| * @param {Feature<Point>} from first point | ||
| * @param {Feature<Point>} to second point | ||
| * @param {Geometry|Feature<Point>|Array<number>} point1 first point | ||
| * @param {Geometry|Feature<Point>|Array<number>} point2 second point | ||
| * @returns {Feature<Point>} a point midway between `pt1` and `pt2` | ||
| * @example | ||
| * var pt1 = { | ||
| * "type": "Feature", | ||
| * "properties": {}, | ||
| * "geometry": { | ||
| * "type": "Point", | ||
| * "coordinates": [144.834823, -37.771257] | ||
| * } | ||
| * }; | ||
| * var pt2 = { | ||
| * "type": "Feature", | ||
| * "properties": {}, | ||
| * "geometry": { | ||
| * "type": "Point", | ||
| * "coordinates": [145.14244, -37.830937] | ||
| * } | ||
| * }; | ||
| * var point1 = turf.point([144.834823, -37.771257]); | ||
| * var point2 = turf.point([145.14244, -37.830937]); | ||
| * | ||
| * var midpoint = turf.midpoint(pt1, pt2); | ||
| * var midpoint = turf.midpoint(point1, point2); | ||
| * | ||
| * //addToMap | ||
| * var addToMap = [point1, point2, midpoint]; | ||
| * midpoint.properties['marker-color'] = '#f00'; | ||
| * var addToMap = [pt1, pt2, midpoint]; | ||
| */ | ||
| module.exports = function (from, to) { | ||
| var dist = distance(from, to, 'miles'); | ||
| var heading = bearing(from, to); | ||
| var midpoint = destination(from, dist / 2, heading, 'miles'); | ||
| */ | ||
| module.exports = function (point1, point2) { | ||
| var dist = distance(point1, point2, 'miles'); | ||
| var heading = bearing(point1, point2); | ||
| var midpoint = destination(point1, dist / 2, heading, 'miles'); | ||
| return midpoint; | ||
| }; |
+5
-5
| { | ||
| "name": "@turf/midpoint", | ||
| "version": "4.5.2", | ||
| "version": "4.6.0", | ||
| "description": "turf midpoint module", | ||
@@ -33,3 +33,3 @@ "main": "index.js", | ||
| "devDependencies": { | ||
| "@turf/helpers": "^4.5.2", | ||
| "@turf/helpers": "^4.6.0", | ||
| "benchmark": "^2.1.4", | ||
@@ -39,6 +39,6 @@ "tape": "^4.6.3" | ||
| "dependencies": { | ||
| "@turf/bearing": "^4.5.2", | ||
| "@turf/destination": "^4.5.2", | ||
| "@turf/distance": "^4.5.2" | ||
| "@turf/bearing": "^4.6.0", | ||
| "@turf/destination": "^4.6.0", | ||
| "@turf/distance": "^4.6.0" | ||
| } | ||
| } |
+6
-20
@@ -10,4 +10,4 @@ # @turf/midpoint | ||
| - `from` **[Feature](http://geojson.org/geojson-spec.html#feature-objects)<[Point](http://geojson.org/geojson-spec.html#point)>** first point | ||
| - `to` **[Feature](http://geojson.org/geojson-spec.html#feature-objects)<[Point](http://geojson.org/geojson-spec.html#point)>** second point | ||
| - `point1` **([Geometry](http://geojson.org/geojson-spec.html#geometry) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects)<[Point](http://geojson.org/geojson-spec.html#point)> | [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>)** first point | ||
| - `point2` **([Geometry](http://geojson.org/geojson-spec.html#geometry) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects)<[Point](http://geojson.org/geojson-spec.html#point)> | [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>)** second point | ||
@@ -17,24 +17,10 @@ **Examples** | ||
| ```javascript | ||
| var pt1 = { | ||
| "type": "Feature", | ||
| "properties": {}, | ||
| "geometry": { | ||
| "type": "Point", | ||
| "coordinates": [144.834823, -37.771257] | ||
| } | ||
| }; | ||
| var pt2 = { | ||
| "type": "Feature", | ||
| "properties": {}, | ||
| "geometry": { | ||
| "type": "Point", | ||
| "coordinates": [145.14244, -37.830937] | ||
| } | ||
| }; | ||
| var point1 = turf.point([144.834823, -37.771257]); | ||
| var point2 = turf.point([145.14244, -37.830937]); | ||
| var midpoint = turf.midpoint(pt1, pt2); | ||
| var midpoint = turf.midpoint(point1, point2); | ||
| //addToMap | ||
| var addToMap = [point1, point2, midpoint]; | ||
| midpoint.properties['marker-color'] = '#f00'; | ||
| var addToMap = [pt1, pt2, midpoint]; | ||
| ``` | ||
@@ -41,0 +27,0 @@ |
5462
6%36
-26.53%52
-21.21%Updated
Updated
Updated