osm2geojson-lite
Advanced tools
Comparing version 0.4.4 to 0.4.5
@@ -47,2 +47,10 @@ const {Node, Way, Relation} = require('./osmobjs.js'), | ||
xmlParser.on('<osm.node>', node => { | ||
new Node(node.$id, refElements); | ||
}); | ||
xmlParser.on('<osm.way>', node => { | ||
new Way(node.$id, refElements); | ||
}); | ||
xmlParser.on('<osm.relation>', node => { | ||
@@ -54,9 +62,12 @@ new Relation(node.$id, refElements); | ||
with (node) { | ||
let way = new Way($id, refElements); | ||
let way = refElements[$id]; | ||
for (let [k, v] of Object.entries(node)) | ||
if (k.startsWith('$') && ['$id'].indexOf(k) < 0) | ||
way.addTag(k.substring(1), v); | ||
if (node.innerNodes) { | ||
for (let nd of innerNodes) { | ||
if (nd.$lon && nd.$lat) | ||
way.addCoords([nd.$lon, nd.$lat]); | ||
else if (nd.$ref) { | ||
way.addNodeRef(nd.$ref); | ||
for (let ind of innerNodes) { | ||
if (ind.$lon && ind.$lat) | ||
way.addCoords([ind.$lon, ind.$lat]); | ||
else if (ind.$ref) { | ||
way.addNodeRef(ind.$ref); | ||
} | ||
@@ -70,7 +81,7 @@ } | ||
with (node) { | ||
let nd = new Node($id, refElements); | ||
let nd = refElements[$id]; | ||
for (let [k, v] of Object.entries(node)) | ||
if (k.startsWith('$') && ['$id', '$lon', '$lat'].indexOf(k) < 0) | ||
nd.addTag(k.substring(1), v); | ||
nd.setCoords([$lon, $lat]); | ||
if (node.innerNodes) | ||
for (let tag of innerNodes) | ||
nd.addTag(tag.$k, tag.$v); | ||
} | ||
@@ -90,8 +101,6 @@ }); | ||
if (node.$lat && node.$lon) { | ||
member.lat = $lat, member.lon = $lon; | ||
member.tags = {}; | ||
for (let [k, v] of Object.entries(node)) { | ||
if (k.startsWith('$') && ['$lat', '$lon', '$type'].indexOf(k) < 0) | ||
member.lat = $lat, member.lon = $lon, member.tags = {}; | ||
for (let [k, v] of Object.entries(node)) | ||
if (k.startsWith('$') && ['$type', '$lat', '$lon'].indexOf(k) < 0) | ||
member.tags[k.substring(1)] = v; | ||
} | ||
} | ||
@@ -117,7 +126,14 @@ | ||
xmlParser.on('</osm.relation.bounds>', (node, parent) => refElements[parent.$id].addProperty('bbox', [parseFloat(node.$minlon), parseFloat(node.$minlat), parseFloat(node.$maxlon), parseFloat(node.$maxlat)])); | ||
xmlParser.on('</osm.relation.bounds>', (node, parent) => { | ||
with (node) | ||
refElements[parent.$id].addProperty('bbox', [parseFloat($minlon), parseFloat($minlat), parseFloat($maxlon), parseFloat($maxlat)]); | ||
}); | ||
xmlParser.on('</osm.relation.tag>', (node, parent) => { | ||
refElements[parent.$id].addTag(node.$k, node.$v) | ||
}); | ||
let addTagToParent = (node, parent) => { | ||
refElements[parent.$id].addTag(node.$k, node.$v); | ||
} | ||
xmlParser.on('</osm.node.tag>', addTagToParent); | ||
xmlParser.on('</osm.way.tag>', addTagToParent); | ||
xmlParser.on('</osm.relation.tag>', addTagToParent); | ||
@@ -124,0 +140,0 @@ xmlParser.parse(osm); |
@@ -39,7 +39,12 @@ module.exports = (() => { | ||
let attRegEx = /([^ ]+?)="(.+?)"/g, attMatch = null, hasAttrs = false; | ||
while (attMatch = attRegEx.exec(attrText)) { | ||
let attRegEx1 = /([^ ]+?)="(.+?)"/g, attRegEx2 = /([^ ]+?)='(.+?)'/g, attMatch = null, hasAttrs = false; | ||
while (attMatch = attRegEx1.exec(attrText)) { | ||
hasAttrs = true; | ||
node[`$${attMatch[1]}`] = attMatch[2]; | ||
} | ||
if (!hasAttrs) | ||
while (attMatch = attRegEx2.exec(attrText)) { | ||
hasAttrs = true; | ||
node[`$${attMatch[1]}`] = attMatch[2]; | ||
} | ||
@@ -46,0 +51,0 @@ if (!hasAttrs && attrText !== '') node.text = attrText; |
@@ -55,3 +55,3 @@ { | ||
}, | ||
"version": "0.4.4", | ||
"version": "0.4.5", | ||
"directories": { | ||
@@ -58,0 +58,0 @@ "lib": "lib", |
@@ -9,3 +9,3 @@ const fs = require('fs'), | ||
for (let file of xmlFiles) { | ||
let osm = fs.readFileSync(file, 'utf-8'); | ||
let osm = fs.readFileSync(`./data/${file}`, 'utf-8'); | ||
console.log(`---processing time comparison for ${file}---`); | ||
@@ -29,3 +29,3 @@ let stime = new Date().getTime(); | ||
for (let file of jsonFiles) { | ||
let osm = require('./' + file); | ||
let osm = require(`./data/${file}`); | ||
console.log(`---processing time comparison for ${file}---`); | ||
@@ -32,0 +32,0 @@ let stime = new Date().getTime(); |
@@ -6,4 +6,4 @@ const fs = require('fs'), | ||
for (let file of xmlFiles) { | ||
let osm = fs.readFileSync(file, 'utf-8'); | ||
console.log('---------------------------------------------------------------------') | ||
console.log(`------------------------------${file}------------------------------`); | ||
let osm = fs.readFileSync(`./data/${file}`, 'utf-8'); | ||
console.log(JSON.stringify(osm2geojson(osm, {allFeatures: true}))); | ||
@@ -14,6 +14,5 @@ } | ||
for (let file of jsonFiles) { | ||
file = './' + file; | ||
let osm = require(file); | ||
console.log('---------------------------------------------------------------------') | ||
console.log(`------------------------------${file}------------------------------`); | ||
let osm = require(`./data/${file}`); | ||
console.log(JSON.stringify(osm2geojson(osm, {allFeatures: true}))); | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
7674610
28
4765
3