diff options
author | Christopher Baines <cbaines8@gmail.com> | 2012-12-09 17:22:24 +0000 |
---|---|---|
committer | Christopher Baines <cbaines8@gmail.com> | 2012-12-09 17:22:24 +0000 |
commit | 0e4c0c4653ee72bb1d8a4c3d7adadf57b0d79024 (patch) | |
tree | 07acad57ebb51a154e0def57608b0c62b7d1e91c /resources/op2geojson.js | |
parent | 23f22db20c725d6bb79db1d43d1ddd81c8a1d73b (diff) | |
download | health-map-0e4c0c4653ee72bb1d8a4c3d7adadf57b0d79024.tar health-map-0e4c0c4653ee72bb1d8a4c3d7adadf57b0d79024.tar.gz |
Fix problems with displaying polygons
Diffstat (limited to 'resources/op2geojson.js')
-rw-r--r-- | resources/op2geojson.js | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/resources/op2geojson.js b/resources/op2geojson.js index cff2dea..5a979b1 100644 --- a/resources/op2geojson.js +++ b/resources/op2geojson.js @@ -99,19 +99,33 @@ op2geojson = function() { instance.polygon = function(relation, ways, nodes) { polyCoordinates = []; + var firstCheck = true; $.each(relation.members, function(i, member) { if (member.role == "outer") { var way = ways[member.ref]; var wayCoordinates = instance.lineString(way, nodes).geometry.coordinates; + + // Need to ensure that the first way is in the correct direction, but this can + // only be checked when looking at the second way + if (firstCheck && polyCoordinates.length != 0) { + firstCheck = false; + if ((polyCoordinates[0][0] == wayCoordinates[0][0] && + polyCoordinates[0][1] == wayCoordinates[0][1]) || + (polyCoordinates[0][0] == wayCoordinates[wayCoordinates.length - 1][0] && + polyCoordinates[0][1] == wayCoordinates[wayCoordinates.length - 1][1])) { + polyCoordinates.reverse(); + } + } + if (polyCoordinates.length != 0) { // If this way is backward if (polyCoordinates[polyCoordinates.length - 1][0] != wayCoordinates[0][0] || polyCoordinates[polyCoordinates.length - 1][1] != wayCoordinates[0][1]) { wayCoordinates.reverse(); } + polyCoordinates.pop(); } - polyCoordinates.shift(); polyCoordinates = polyCoordinates.concat( wayCoordinates ); } }); |