forked from mapbox/node-s2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (46 loc) · 1.11 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
var s2 = require('./build/Release/_s2.node');
module.exports = s2;
s2.S2LatLng.prototype.toGeoJSON = function() {
return {
type: 'Point',
coordinates: [this.lng, this.lat]
};
};
s2.S2Cell.prototype.toGeoJSON = function() {
var vs = [];
for (var i = 0; i < 4; i++) {
vs.push(new s2.S2LatLng(this.getVertex(i)));
}
vs.push(new s2.S2LatLng(this.getVertex(0)));
return {
type: 'Polygon',
coordinates: [
vs.map(function(v) {
return [v.lng, v.lat];
})
]
};
};
s2.S2LatLngRect.prototype.toGeoJSON = function() {
var vs = [];
for (var i = 0; i < 4; i++) {
vs.push(this.getVertex(i));
}
vs.push(this.getVertex(0));
return {
type: 'Polygon',
coordinates: [
[
vs.map(function(v) {
return [v.lng, v.lat];
})
]
]
};
};
s2.S2Point.prototype.toArray = function() {
return [this.x(), this.y(), this.z()];
};
s2.S2Point.prototype.toString = function() {
return this.toArray().toString();
};