@mapbox/graph-normalizer
Advanced tools
Comparing version 2.2.1 to 2.3.0
@@ -5,3 +5,3 @@ 'use strict'; | ||
module.exports = function (wayList) { | ||
module.exports = function (wayList, options) { | ||
// build node and way hashes | ||
@@ -44,6 +44,2 @@ var nodes = new Map(); | ||
( | ||
owners[0].properties.highway !== | ||
owners[1].properties.highway | ||
) || | ||
( | ||
owners[0].properties.oneway !== | ||
@@ -53,8 +49,21 @@ owners[1].properties.oneway | ||
( | ||
owners[0].properties.bridge !== | ||
owners[1].properties.bridge | ||
(!options.mergeHighways) && | ||
( | ||
owners[0].properties.highway !== | ||
owners[1].properties.highway | ||
) | ||
) || | ||
( | ||
owners[0].properties.tunnel !== | ||
owners[1].properties.tunnel | ||
(!options.mergeBridges) && | ||
( | ||
owners[0].properties.bridge !== | ||
owners[1].properties.bridge | ||
) | ||
) || | ||
( | ||
(!options.mergeTunnels) && | ||
( | ||
owners[0].properties.tunnel !== | ||
owners[1].properties.tunnel | ||
) | ||
) | ||
@@ -138,6 +147,22 @@ ) nodes.delete(node); | ||
if (opening.properties.hasOwnProperty('oneway')) combined.properties.oneway = opening.properties.oneway; | ||
if (opening.properties.hasOwnProperty('highway')) combined.properties.highway = opening.properties.highway; | ||
if (opening.properties.hasOwnProperty('bridge')) combined.properties.bridge = opening.properties.bridge; | ||
if (opening.properties.hasOwnProperty('tunnel')) combined.properties.tunnel = opening.properties.tunnel; | ||
if (options.mergeHighways) { | ||
// if highway tags are the same, keep them, else set as unclassified | ||
if (opening.properties.hasOwnProperty('highway') && closing.properties.hasOwnProperty('highway') && (opening.properties.highway === closing.properties.highway)) { | ||
combined.properties.highway = opening.properties.highway; | ||
} else { | ||
combined.properties.highway = 'unclassified'; | ||
} | ||
} else if (opening.properties.hasOwnProperty('highway')) combined.properties.highway = opening.properties.highway; | ||
if (options.mergeBridges) { | ||
if (opening.properties.hasOwnProperty('bridge')) combined.properties.bridge = opening.properties.bridge; | ||
else if (closing.properties.hasOwnProperty('bridge')) combined.properties.bridge = closing.properties.bridge; | ||
} else if (opening.properties.hasOwnProperty('bridge')) combined.properties.bridge = opening.properties.bridge; | ||
if (options.mergeTunnels) { | ||
if (opening.properties.hasOwnProperty('tunnel')) combined.properties.tunnel = opening.properties.tunnel; | ||
else if (closing.properties.hasOwnProperty('tunnel')) combined.properties.tunnel = closing.properties.tunnel; | ||
} else if (opening.properties.hasOwnProperty('tunnel')) combined.properties.bridge = opening.properties.bridge; | ||
// insert combined way into hash | ||
@@ -144,0 +169,0 @@ ways[combined.properties.id] = combined; |
{ | ||
"name": "@mapbox/graph-normalizer", | ||
"version": "2.2.1", | ||
"version": "2.3.0", | ||
"description": "Takes nodes and ways and turn them into a normalized graph of intersections and ways.", | ||
@@ -5,0 +5,0 @@ "bin": "./bin/normalize-ways", |
@@ -20,3 +20,6 @@ # Graph-normalizer | ||
--outputPath <output path> \ | ||
--zoomLevel <output zoom level - default 14> | ||
--zoomLevel <output zoom level - default 14> \ | ||
--mergeHighways <optional - merge ways with different highway tags - default false> \ | ||
--mergeTunnels <optional - merge ways with different tunnel tags - default false> \ | ||
--mergeBridges <optional - merge ways with different bridge tags - default false> | ||
``` | ||
@@ -30,3 +33,7 @@ | ||
- Normalized way ids keep track of the history of transformations that led to it. | ||
- `highway`, `oneway`, `bridge` and `tunnel` tags are conserved from the original graph. | ||
- `highway`, `oneway`, `bridge` and `tunnel` tags are conserved from the original graph by default. | ||
- `highway`, `bridge` and `tunnel` tags can be merged using optional arguments. When merging different tags: | ||
- `highway` tag is set as `unclassified` | ||
- `tunnel` tag is set to `yes` i.e. we keep the info that there is a tunnel in the merged way | ||
- `bridge` tag is set to `yes` i.e. we keep the info that there is a bridge in the merged way | ||
@@ -63,2 +70,2 @@ Edges that are shared by multiple tiles are conserved in all of them. | ||
npm run bench | ||
``` | ||
``` |
@@ -12,6 +12,7 @@ 'use strict'; | ||
fixtures.forEach(function (fixture) { | ||
var options = JSON.parse(fs.readFileSync(path.join(__dirname, './fixtures/merge-ways/', fixture, 'options'))); | ||
var before = JSON.parse(fs.readFileSync(path.join(__dirname, './fixtures/merge-ways/', fixture, 'before'))); | ||
var after = JSON.parse(fs.readFileSync(path.join(__dirname, './fixtures/merge-ways/', fixture, 'after'))); | ||
var result = normalizer.mergeWays(before); | ||
var result = normalizer.mergeWays(before, options); | ||
t.deepEqual(result, after, fixture + ' output matches expected result'); | ||
@@ -18,0 +19,0 @@ }); |
Sorry, the diff of this file is not supported yet
2369024
95
833
69