-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
122 lines (120 loc) · 3.02 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
var extent = require('turf-extent'),
point = require('turf-point');
/**
* Takes a {@link FeatureCollection} and returns the absolute center point of all features.
*
* @module turf/center
* @category measurement
* @param {FeatureCollection} features input features
* @return {Feature<Point>} a Point feature at the
* absolute center point of all input features
* @example
* var features = {
* "type": "FeatureCollection",
* "features": [
* {
* "type": "Feature",
* "properties": {},
* "geometry": {
* "type": "Point",
* "coordinates": [-97.522259, 35.4691]
* }
* }, {
* "type": "Feature",
* "properties": {},
* "geometry": {
* "type": "Point",
* "coordinates": [-97.502754, 35.463455]
* }
* }, {
* "type": "Feature",
* "properties": {},
* "geometry": {
* "type": "Point",
* "coordinates": [-97.508269, 35.463245]
* }
* }, {
* "type": "Feature",
* "properties": {},
* "geometry": {
* "type": "Point",
* "coordinates": [-97.516809, 35.465779]
* }
* }, {
* "type": "Feature",
* "properties": {},
* "geometry": {
* "type": "Point",
* "coordinates": [-97.515372, 35.467072]
* }
* }, {
* "type": "Feature",
* "properties": {},
* "geometry": {
* "type": "Point",
* "coordinates": [-97.509363, 35.463053]
* }
* }, {
* "type": "Feature",
* "properties": {},
* "geometry": {
* "type": "Point",
* "coordinates": [-97.511123, 35.466601]
* }
* }, {
* "type": "Feature",
* "properties": {},
* "geometry": {
* "type": "Point",
* "coordinates": [-97.518547, 35.469327]
* }
* }, {
* "type": "Feature",
* "properties": {},
* "geometry": {
* "type": "Point",
* "coordinates": [-97.519706, 35.469659]
* }
* }, {
* "type": "Feature",
* "properties": {},
* "geometry": {
* "type": "Point",
* "coordinates": [-97.517839, 35.466998]
* }
* }, {
* "type": "Feature",
* "properties": {},
* "geometry": {
* "type": "Point",
* "coordinates": [-97.508678, 35.464942]
* }
* }, {
* "type": "Feature",
* "properties": {},
* "geometry": {
* "type": "Point",
* "coordinates": [-97.514914, 35.463453]
* }
* }
* ]
* };
*
* var centerPt = turf.center(features);
* centerPt.properties['marker-size'] = 'large';
* centerPt.properties['marker-color'] = '#000';
*
* var resultFeatures = features.features.concat(centerPt);
* var result = {
* "type": "FeatureCollection",
* "features": resultFeatures
* };
*
* //=result
*/
module.exports = function(layer) {
var ext = extent(layer);
var x = (ext[0] + ext[2])/2;
var y = (ext[1] + ext[3])/2;
return point([x, y]);
};