-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflip.js
38 lines (31 loc) · 1.11 KB
/
flip.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
(function (exports) {
exports.flip = function (json) {
function findAllCoordinates(obj) {
var objects = [];
for (var i in obj) {
if (i === "coordinates") {
objects.push(obj[i]);
} else if (typeof obj[i] == 'object') {
objects = objects.concat(
findAllCoordinates(obj[i])
);
}
}
return objects;
}
function flipAllCoordinatesArray(coordinates) {
if (coordinates && coordinates.length === 2 && typeof coordinates[0] === 'number') {
coordinates.reverse();
} else {
for (var p = 0; p < coordinates.length; p++) {
flipAllCoordinatesArray(coordinates[p]);
}
}
}
var values = findAllCoordinates(json);
for (var i = 0; i < values.length; i++) {
flipAllCoordinatesArray(values[i]);
}
return json;
}
})(typeof exports === 'undefined' ? this['geojson-flip'] = {} : exports);