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

Commit e915253

Browse files
committed
fix(osmtogeojson): order of coordinates + parseFloat
1 parent 71eb56e commit e915253

File tree

2 files changed

+56
-66
lines changed

2 files changed

+56
-66
lines changed

src/togeojson/togeojson.factory.js

+22-24
Original file line numberDiff line numberDiff line change
@@ -30,41 +30,45 @@ function factory(options) {
3030
}
3131

3232
for (let i = 0; i < data.length; i++) {
33-
var feature = {};
3433
var d = data[i];
35-
feature.properties = {
36-
id: d._id,
37-
tags: d.tags
34+
var feature = {
35+
type: 'Feature',
36+
geometry: {},
37+
properties: {
38+
id: d.id,
39+
tags: d.tags
40+
}
3841
};
3942
if (d.type === "changeset") {
4043
//build rectangle
4144
// X = Long; Y = Lat, lets do it clockwise
42-
feature.type = 'Polygon';
45+
feature.geometry.type = 'Polygon';
4346
var bounds = d.latLngBounds;
44-
feature.coordinates = [
45-
[bounds._min_lon, bounds._min_lat],
46-
[bounds._min_lon, bounds._max_lat],
47-
[bounds._max_lon, bounds._max_lat],
48-
[bounds._max_lon, bounds._min_lat]
47+
feature.geometry.coordinates = [
48+
[parseFloat(bounds._min_lon), parseFloat(bounds._min_lat)],
49+
[parseFloat(bounds._min_lon), parseFloat(bounds._max_lat)],
50+
[parseFloat(bounds._max_lon), parseFloat(bounds._max_lat)],
51+
[parseFloat(bounds._max_lon), parseFloat(bounds._min_lat)]
4952
];
5053
} else if (d.type === "node") {
5154
//add a Point
52-
feature.type = 'Point';
53-
feature.coordinates = [d.latLng[1], d.latLng[0]];
55+
feature.geometry.type = 'Point';
56+
feature.geometry.coordinates = [d.latLng[1], d.latLng[0]];
5457
} else {
5558
var lngLats = new Array(d.nodes.length);
5659

5760
for (let j = 0; j < d.nodes.length; j++) {
58-
lngLats[j] = d.nodes[j].latLng;
61+
let latLng = d.nodes[j].latLng;
62+
lngLats[j] = [latLng[1], latLng[0]];
5963
}
6064

6165
if (isWayArea(d)) {
6266
lngLats.pop(); // Remove last == first.
63-
feature.type = 'Polygon';
64-
feature.coordinates = lngLats;
67+
feature.geometry.type = 'Polygon';
68+
feature.geometry.coordinates = lngLats;
6569
} else {
66-
feature.type = 'MultiLineString';
67-
feature.coordinates = lngLats;
70+
feature.geometry.type = 'LineString';
71+
feature.geometry.coordinates = lngLats;
6872
}
6973
}
7074
features.push(feature);
@@ -113,7 +117,7 @@ function factory(options) {
113117
nodesById[node._id] = {
114118
id: node._id,
115119
type: 'node',
116-
latLng: [node._lon, node._lat],
120+
latLng: [parseFloat(node._lat), parseFloat(node._lon)],
117121
tags: getTags(node)
118122
};
119123
});
@@ -219,12 +223,6 @@ function factory(options) {
219223
}
220224
}
221225

222-
for (let key in node.tags) {
223-
if (options.uninterestingTags.indexOf(key) < 0) {
224-
return true;
225-
}
226-
}
227-
228226
return false;
229227
}
230228
function togeojson(data, options) {

src/togeojson/togeojson.spec.js

+34-42
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ ngDescribe({
6262
expect(nodes['3'].id).toBe(3);
6363
expect(nodes['3'].type).toBe('node');
6464
expect(nodes['3'].latLng.length).toBe(2);
65-
expect(nodes['3'].latLng[0]).toBe(321);
66-
expect(nodes['3'].latLng[1]).toBe(123);
65+
expect(nodes['3'].latLng[0]).toBe(123);
66+
expect(nodes['3'].latLng[1]).toBe(321);
6767
expect(nodes['3'].tags.highway).toBe('mini_roundabout');
6868

6969
//must work the same if node is array & tag is array of tags
@@ -76,8 +76,8 @@ ngDescribe({
7676
expect(nodes['3'].id).toBe(3);
7777
expect(nodes['3'].type).toBe('node');
7878
expect(nodes['3'].latLng.length).toBe(2);
79-
expect(nodes['3'].latLng[0]).toBe(321);
80-
expect(nodes['3'].latLng[1]).toBe(123);
79+
expect(nodes['3'].latLng[0]).toBe(123);
80+
expect(nodes['3'].latLng[1]).toBe(321);
8181
expect(nodes['3'].tags.highway).toBe(undefined);
8282

8383
});
@@ -251,14 +251,6 @@ ngDescribe({
251251
result = deps.osmtogeojson.interestingNode(node, ways, relations);
252252
expect(result).toBe(true);
253253

254-
relations = [];
255-
node.tags = {name: 'toto'};
256-
result = deps.osmtogeojson.interestingNode(node, ways, relations);
257-
expect(result).toBe(true);
258-
259-
node.tags = {source: 'uninterestingTags'};
260-
result = deps.osmtogeojson.interestingNode(node, ways, relations);
261-
expect(result).toBe(false);
262254
});
263255

264256
it('should getFeatures to work with changeset', function() {
@@ -274,16 +266,16 @@ ngDescribe({
274266
}];
275267
var features = deps.osmtogeojson.getFeatures(data);
276268
expect(features.length).toBe(1);
277-
expect(features[0].type).toBe('Polygon');
278-
expect(features[0].coordinates[0][0]).toBe(-234);
279-
expect(features[0].coordinates[0][1]).toBe(-123);
280-
expect(features[0].coordinates[1][0]).toBe(-234);
281-
expect(features[0].coordinates[1][1]).toBe(123);
282-
expect(features[0].coordinates[2][0]).toBe(234);
283-
expect(features[0].coordinates[2][1]).toBe(123);
284-
expect(features[0].coordinates[3][0]).toBe(234);
285-
expect(features[0].coordinates[3][1]).toBe(-123);
286-
expect(features[0].coordinates[4]).toBe();
269+
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();
287279
});
288280
it('should getFeatures to work with node', function() {
289281
var data = [{
@@ -294,10 +286,10 @@ ngDescribe({
294286
}];
295287
var features = deps.osmtogeojson.getFeatures(data);
296288
expect(features.length).toBe(1);
297-
expect(features[0].type).toBe('Point');
298-
expect(features[0].coordinates[0]).toBe(234);
299-
expect(features[0].coordinates[1]).toBe(123);
300-
expect(features[0].coordinates[2]).toBe();
289+
expect(features[0].geometry.type).toBe('Point');
290+
expect(features[0].geometry.coordinates[0]).toBe(234);
291+
expect(features[0].geometry.coordinates[1]).toBe(123);
292+
expect(features[0].geometry.coordinates[2]).toBe();
301293
});
302294
it('should getFeatures to work with way', function() {
303295
var n1 = {
@@ -320,13 +312,13 @@ ngDescribe({
320312
}];
321313
var features = deps.osmtogeojson.getFeatures(data);
322314
expect(features.length).toBe(1);
323-
expect(features[0].type).toBe('MultiLineString');
315+
expect(features[0].geometry.type).toBe('LineString');
324316
expect(features[0].properties.tags.name).toBe('my way');
325-
expect(features[0].coordinates[0][0]).toBe(123);
326-
expect(features[0].coordinates[0][1]).toBe(234);
327-
expect(features[0].coordinates[1][0]).toBe(1234);
328-
expect(features[0].coordinates[1][1]).toBe(2345);
329-
expect(features[0].coordinates[2]).toBe();
317+
expect(features[0].geometry.coordinates[0][0]).toBe(234);
318+
expect(features[0].geometry.coordinates[0][1]).toBe(123);
319+
expect(features[0].geometry.coordinates[1][0]).toBe(2345);
320+
expect(features[0].geometry.coordinates[1][1]).toBe(1234);
321+
expect(features[0].geometry.coordinates[2]).toBe();
330322
});
331323

332324
it('should getFeatures to work with way (area)', function() {
@@ -356,14 +348,14 @@ ngDescribe({
356348
}];
357349
var features = deps.osmtogeojson.getFeatures(data);
358350
expect(features.length).toBe(1);
359-
expect(features[0].type).toBe('Polygon');
360-
expect(features[0].coordinates[0][0]).toBe(1);
361-
expect(features[0].coordinates[0][1]).toBe(2);
362-
expect(features[0].coordinates[1][0]).toBe(12);
363-
expect(features[0].coordinates[1][1]).toBe(23);
364-
expect(features[0].coordinates[2][0]).toBe(123);
365-
expect(features[0].coordinates[2][1]).toBe(234);
366-
expect(features[0].coordinates[3]).toBe();
351+
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();
367359
});
368360

369361

@@ -422,8 +414,8 @@ ngDescribe({
422414
expect(geojson.features.length).toBe(2);
423415
expect(Array.isArray(geojson.features)).toBe(true);
424416
expect(geojson.features[1].properties.tags.highway).toBe('mini_roundabout');
425-
expect(geojson.features[1].type).toBe('MultiLineString');
426-
expect(geojson.features[0].type).toBe('Point');
417+
expect(geojson.features[1].geometry.type).toBe('LineString');
418+
expect(geojson.features[0].geometry.type).toBe('Point');
427419
});
428420

429421
}

0 commit comments

Comments
 (0)