Skip to content
This repository was archived by the owner on Feb 28, 2022. It is now read-only.

Commit e65fbd7

Browse files
committed
fix(osm/togeojson): Polygon geojson coordinates is array of array of array of coordinates
1 parent 3654fe3 commit e65fbd7

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

src/togeojson/togeojson.factory.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@ function factory(options) {
4444
// X = Long; Y = Lat, lets do it clockwise
4545
feature.geometry.type = 'Polygon';
4646
var bounds = d.latLngBounds;
47-
feature.geometry.coordinates = [
47+
feature.geometry.coordinates = [[
4848
[parseFloat(bounds._min_lon), parseFloat(bounds._min_lat)],
4949
[parseFloat(bounds._min_lon), parseFloat(bounds._max_lat)],
5050
[parseFloat(bounds._max_lon), parseFloat(bounds._max_lat)],
51-
[parseFloat(bounds._max_lon), parseFloat(bounds._min_lat)]
52-
];
51+
[parseFloat(bounds._max_lon), parseFloat(bounds._min_lat)],
52+
[parseFloat(bounds._min_lon), parseFloat(bounds._min_lat)]
53+
]];
5354
} else if (d.type === "node") {
5455
//add a Point
5556
feature.geometry.type = 'Point';
@@ -63,9 +64,8 @@ function factory(options) {
6364
}
6465

6566
if (isWayArea(d)) {
66-
lngLats.pop(); // Remove last == first.
6767
feature.geometry.type = 'Polygon';
68-
feature.geometry.coordinates = lngLats;
68+
feature.geometry.coordinates = [lngLats];
6969
} else {
7070
feature.geometry.type = 'LineString';
7171
feature.geometry.coordinates = lngLats;

src/togeojson/togeojson.spec.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,17 @@ ngDescribe({
267267
var features = deps.osmtogeojson.getFeatures(data);
268268
expect(features.length).toBe(1);
269269
expect(features[0].geometry.type).toBe('Polygon');
270-
expect(features[0].geometry.coordinates[0][0]).toBe(-234);
271-
expect(features[0].geometry.coordinates[0][1]).toBe(-123);
272-
expect(features[0].geometry.coordinates[1][0]).toBe(-234);
273-
expect(features[0].geometry.coordinates[1][1]).toBe(123);
274-
expect(features[0].geometry.coordinates[2][0]).toBe(234);
275-
expect(features[0].geometry.coordinates[2][1]).toBe(123);
276-
expect(features[0].geometry.coordinates[3][0]).toBe(234);
277-
expect(features[0].geometry.coordinates[3][1]).toBe(-123);
278-
expect(features[0].geometry.coordinates[4]).toBe();
270+
expect(features[0].geometry.coordinates[0][0][0]).toBe(-234);
271+
expect(features[0].geometry.coordinates[0][0][1]).toBe(-123);
272+
expect(features[0].geometry.coordinates[0][1][0]).toBe(-234);
273+
expect(features[0].geometry.coordinates[0][1][1]).toBe(123);
274+
expect(features[0].geometry.coordinates[0][2][0]).toBe(234);
275+
expect(features[0].geometry.coordinates[0][2][1]).toBe(123);
276+
expect(features[0].geometry.coordinates[0][3][0]).toBe(234);
277+
expect(features[0].geometry.coordinates[0][3][1]).toBe(-123);
278+
//last must be same as first
279+
expect(features[0].geometry.coordinates[0][4][0]).toBe(-234);
280+
expect(features[0].geometry.coordinates[0][4][1]).toBe(-123);
279281
});
280282
it('should getFeatures to work with node', function() {
281283
var data = [{
@@ -349,13 +351,15 @@ ngDescribe({
349351
var features = deps.osmtogeojson.getFeatures(data);
350352
expect(features.length).toBe(1);
351353
expect(features[0].geometry.type).toBe('Polygon');
352-
expect(features[0].geometry.coordinates[0][0]).toBe(2);
353-
expect(features[0].geometry.coordinates[0][1]).toBe(1);
354-
expect(features[0].geometry.coordinates[1][0]).toBe(23);
355-
expect(features[0].geometry.coordinates[1][1]).toBe(12);
356-
expect(features[0].geometry.coordinates[2][0]).toBe(234);
357-
expect(features[0].geometry.coordinates[2][1]).toBe(123);
358-
expect(features[0].geometry.coordinates[3]).toBe();
354+
expect(features[0].geometry.coordinates[0][0][0]).toBe(2);
355+
expect(features[0].geometry.coordinates[0][0][1]).toBe(1);
356+
expect(features[0].geometry.coordinates[0][1][0]).toBe(23);
357+
expect(features[0].geometry.coordinates[0][1][1]).toBe(12);
358+
expect(features[0].geometry.coordinates[0][2][0]).toBe(234);
359+
expect(features[0].geometry.coordinates[0][2][1]).toBe(123);
360+
//last must be same as first
361+
expect(features[0].geometry.coordinates[0][3][0]).toBe(2);
362+
expect(features[0].geometry.coordinates[0][3][1]).toBe(1);
359363
});
360364

361365

0 commit comments

Comments
 (0)