Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

osm2geojson-lite

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

osm2geojson-lite - npm Package Compare versions

Comparing version 0.4.5 to 0.4.6

286

dist/osm2geojson-lite.js
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
const {Node, Way, Relation} = require('./osmobjs.js'),
{RefElements} = require('./utils.js'),
{purgeProps, RefElements} = require('./utils.js'),
XmlParser = require('./xmlparser.js');
module.exports = (osm, opts) => {
let completeFeature = false, renderTagged = false, suppressWay = true;
let parseOpts = opts => {
if (opts) {
completeFeature = opts.completeFeature || opts.allFeatures? true : false;
renderTagged = opts.renderTagged? true : false;
if (opts.suppressWay !== undefined && !opts.suppressWay) suppressWay = false;
}
}
parseOpts(opts);
let refElements = new RefElements(), featureArray = [];

@@ -14,5 +26,6 @@

let node = new Node(elem.id, refElements);
if (elem.tags) node.addTags(elem.tags);
if (elem.tags)
node.addTags(elem.tags);
node.addProps(purgeProps(elem, ['id', 'type', 'tags', 'lat', 'lon']));
node.setCoords([elem.lon, elem.lat]);
node.addTags(elem.tags);
break;

@@ -23,2 +36,3 @@

if (elem.tags) way.addTags(elem.tags);
way.addProps(purgeProps(elem, ['id', 'type', 'tags', 'nodes', 'geometry']));
if (elem.nodes)

@@ -34,6 +48,6 @@ for (let n of elem.nodes)

let relation = new Relation(elem.id, refElements);
if (elem.bounds)
with (elem.bounds)
relation.addProperty('bbox', [parseFloat(minlon), parseFloat(minlat), parseFloat(maxlon), parseFloat(maxlat)]);
if (elem.bounds) with (elem.bounds)
relation.addProp('bbox', [parseFloat(minlon), parseFloat(minlat), parseFloat(maxlon), parseFloat(maxlat)]);
if (elem.tags) relation.addTags(elem.tags);
relation.addProps(purgeProps(elem, ['id', 'type', 'tags', 'bounds', 'members']));
if (elem.members)

@@ -52,17 +66,28 @@ for (let member of elem.members)

xmlParser.addListener('<osm.relation>', node => {
new Relation(node.$id, refElements);
xmlParser.on('<osm.node>', node => {
new Node(node.$id, refElements);
});
xmlParser.addListener('</osm.way>', node => {
xmlParser.on('<osm.way>', node => {
new Way(node.$id, refElements);
});
xmlParser.on('<osm.relation>', node => {
new Relation(node.$id, refElements);
});
xmlParser.on('</osm.way>', node => {
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.addProp(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);
else if(ind.tag === 'tag')
way.addTag(ind.$k, ind.$v);
}

@@ -72,20 +97,18 @@ }

xmlParser.addListener('</osm.node>', node => {
xmlParser.on('</osm.node>', node => {
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.addProp(k.substring(1), v);
nd.setCoords([$lon, $lat]);
if (node.innerNodes)
for (let tag of innerNodes)
nd.addTag(tag.$k, tag.$v);
for (let ind of innerNodes)
if(ind.tag === 'tag')
nd.addTag(ind.$k, ind.$v);
}
});
xmlParser.addListener('<osm.relation>', (node, parent) => {
xmlParser.on('</osm.relation.member>', (node, parent) => {
with (node) {
new Relation($id, refElements);
}
});
xmlParser.addListener('</osm.relation.member>', (node, parent) => {
with (node) {
let relation = refElements[parent.$id];

@@ -95,3 +118,2 @@ let member = {

role: node.$role? $role : '',
id: $ref,
ref: $ref

@@ -101,9 +123,6 @@ };

if (node.$lat && node.$lon) {
member.lat = $lat, member.lon = $lon;
member.tags = {};
let entries = Object.entries(node);
for (let [k, v] of entries) {
if (k.startsWith('$') && ['$lat', '$lon', '$type'].indexOf(k) < 0)
member.tags[k.substring(1)] = v;
}
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[k.substring(1)] = v;
}

@@ -129,6 +148,10 @@

xmlParser.addListener('</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].addProp('bbox', [parseFloat($minlon), parseFloat($minlat), parseFloat($maxlon), parseFloat($maxlat)]);
});
xmlParser.addListener('</osm.relation.tag>', (node, parent) => {
refElements[parent.$id].addTag(node.$k, node.$v)
xmlParser.on('</osm.relation.tag>', (node, parent) => {
let elem = refElements[parent.$id];
if (elem) elem.addTag(node.$k, node.$v);
});

@@ -144,11 +167,9 @@

let entries = Object.entries(refElements);
for (let [k, v] of entries) {
if (v && v.refCount <= 0) {
for (let [k, v] of Object.entries(refElements)) {
if (v && (v.refCount <= 0 || (renderTagged && v.hasTag && !(v instanceof Way && suppressWay)))) {
if (v.toFeature) {
let feature = v.toFeature();
if (feature) featureArray.push(feature);
} else if (v.toFeatureArray) {
} else if (v.toFeatureArray)
featureArray = featureArray.concat(v.toFeatureArray());
}
}

@@ -159,3 +180,3 @@ }

if ((!opts || !opts.allFeatures) && featureArray.length > 0)
if (!completeFeature && featureArray.length > 0)
return featureArray[0].geometry;

@@ -165,8 +186,11 @@

}
},{"./osmobjs.js":2,"./utils.js":3,"./xmlparser.js":4}],2:[function(require,module,exports){
},{"./osmobjs.js":2,"./utils.js":4,"./xmlparser.js":5}],2:[function(require,module,exports){
module.exports = (() => {
'use strict';
const {first, last, coordsToKey, addToMap, removeFromMap, getFirstFromMap,
const {first, last, coordsToKey,
addToMap, removeFromMap, getFirstFromMap,
isRing, ringDirection, ptInsidePolygon, strToFloat,
LateBinder, WayCollection} = require('./utils.js');
LateBinder, WayCollection} = require('./utils.js'),
polygonTags = require('./polytags.json');

@@ -179,4 +203,5 @@ class OsmObject {

this.tags = {};
this.properties = {id: this.getCompositeId()};
this.props = {id: this.getCompositeId()};
this.refCount = 0;
this.hasTag = false;
if (refElems) refElems.add(id, this);

@@ -187,2 +212,3 @@ }

this.tags = Object.assign(this.tags, tags);
this.hasTag = tags? true : false;
}

@@ -192,8 +218,13 @@

this.tags[k] = v;
this.hasTag = k? true : false;
}
addProperty(k, v) {
this.properties[k] = v;
addProp(k, v) {
this.props[k] = v;
}
addProps(props) {
this.props = Object.assign(this.props, props);
}
getCompositeId() {

@@ -203,4 +234,4 @@ return `${this.type}/${this.id}`;

getProperties() {
return Object.assign(this.properties, this.tags);
getProps() {
return Object.assign(this.props, this.tags);
}

@@ -231,3 +262,3 @@

id: this.getCompositeId(),
properties: this.getProperties(),
properties: this.getProps(),
geometry: {

@@ -250,2 +281,4 @@ type: 'Point',

this.coordsArray = [];
this.isPolygon = false;
this.isBound = false;
}

@@ -267,6 +300,28 @@

analyzeTag(k, v) {
let o = polygonTags[k];
if (o) {
this.isPolygon = true;
if (o.whitelist) this.isPolygon = o.whitelist.indexOf(v) >= 0? true : false;
else if(o.blacklist) this.isPolygon = o.blacklist.indexOf(v) >= 0? false : true;
// console.log(`${k}: ${v} => way/${this.id} is a polygon: ${this.isPolygon}`);
}
}
addTags(tags) {
super.addTags(tags);
for (let [k, v] of Object.entries(tags))
this.analyzeTag(k, v);
}
addTag(k, v) {
super.addTag(k, v);
this.analyzeTag(k, v);
}
bindRefs() {
// for (let nd of this.coordsArray)
// if (nd instanceof LateBinder) nd.bind();
this.coordsArray.reduce((a, v) => v instanceof LateBinder? a.concat([v]) : a, []).forEach(lb => lb.bind());
if (!this.isBound) {
this.coordsArray.reduce((a, v) => v instanceof LateBinder? a.concat([v]) : a, []).forEach(lb => lb.bind());
this.isBound = true;
}
}

@@ -282,3 +337,3 @@

if (this.coordsArray.length > 1) {
if (isRing(this.coordsArray)) {
if (this.isPolygon && isRing(this.coordsArray)) {
if (ringDirection(this.coordsArray) !== 'counterclockwise') this.coordsArray.reverse();

@@ -288,3 +343,3 @@ return {

id: this.getCompositeId(),
properties: this.getProperties(),
properties: this.getProps(),
geometry: {

@@ -300,3 +355,3 @@ type: 'Polygon',

id: this.getCompositeId(),
properties: this.getProperties(),
properties: this.getProps(),
geometry: {

@@ -316,2 +371,3 @@ type: 'LineString',

this.nodes = [];
this.isBound = false;
}

@@ -343,3 +399,3 @@

} else if (member.nodes) {
let way = new Way(member.id, this.refElems);
let way = new Way(member.ref, this.refElems);
for (let nid of nodes) {

@@ -364,6 +420,5 @@ way.addNodeRef(nid);

if (member.tags) node.addTags(member.tags);
let entries = Object.entries(member);
for (let [k, v] of entries) {
if (k !== 'lat' && k !== 'lon' && k !== 'id' && k !== 'tags')
node.addTag(k, v);
for (let [k, v] of Object.entries(member)) {
if (k !== 'id' && k !== 'type' && k !== 'lat' && k !== 'lon')
node.addProp(k, v);
}

@@ -388,12 +443,16 @@ node.refCount++;

bindRefs() {
const fieldsToBind = ['relations', 'nodes', 'outer', 'inner', ''];
for (let fieldName of fieldsToBind) {
let field = this[fieldName];
if (field && field.length > 0) {
let clone = field.slice(0);
for (let item of clone) {
if (item instanceof LateBinder) item.bind();
else if (item.bindRefs) item.bindRefs();
if (!this.isBound) {
const fieldsToBind = ['relations', 'nodes', 'outer', 'inner', ''];
for (let fieldName of fieldsToBind) {
let field = this[fieldName];
if (field && field.length > 0) {
// need a clone 'coz bind will remove elements
let clone = field.slice(0);
for (let item of clone) {
if (item instanceof LateBinder) item.bind();
else if (item.bindRefs) item.bindRefs();
}
}
}
this.isBound = true;
}

@@ -458,13 +517,12 @@ }

let polygonFeatures = [], stringFeatures = [], pointFeatures = [];
const waysToProcess = ['outer', 'inner', ''];
const waysFieldNames = ['outer', 'inner', ''];
for (let relation of this.relations) {
console.log(relation.constructor.name);
console.log(relation.id);
if (relation && relation.bindRefs()) {
for (let waysName of waysToProcess) {
let ways = relation[waysName];
if (relation) {
relation.bindRefs();
for (let fieldName of waysFieldNames) {
let ways = relation[fieldName];
if (ways) {
let thisWays = this[waysName];
let thisWays = this[field];
if (thisWays) [].splice.apply(thisWays, [thisWays.length, 0].concat(ways));
else this[waysName] = ways;
else this[fieldName] = ways;
}

@@ -475,9 +533,8 @@ }

for (let waysName of waysToProcess) {
let ways = this[waysName];
for (let fieldName of waysFieldNames) {
let ways = this[fieldName];
if (ways) {
this[waysName] = new WayCollection();
for (let way of ways) {
this[waysName].addWay(way);
}
this[fieldName] = new WayCollection();
for (let way of ways)
this[fieldName].addWay(way);
}

@@ -493,3 +550,3 @@ }

id: this.getCompositeId(),
properties: this.getProperties(),
properties: this.getProps(),
geometry

@@ -504,3 +561,3 @@ });

id: this.getCompositeId(),
properties: this.getProperties(),
properties: this.getProps(),
geometry

@@ -519,6 +576,23 @@ });

})();
},{"./utils.js":3}],3:[function(require,module,exports){
},{"./polytags.json":3,"./utils.js":4}],3:[function(require,module,exports){
module.exports={"building":{},"highway":{"whitelist":["services","rest_area","escape","elevator"]},"natural":{"blacklist":["coastline","cliff","ridge","arete","tree_row"]},"landuse":{},"waterway":{"whitelist":["riverbank","dock","boatyard","dam"]},"amenity":{},"leisure":{},"barrier":{"whitelist":["city_wall","ditch","hedge","retaining_wall","wall","spikes"]},"railway":{"whitelist":["station","turntable","roundhouse","platform"]},"area":{},"boundary":{},"man_made":{"blacklist":["cutline","embankment","pipeline"]},"power":{"whitelist":["plant","substation","generator","transformer"]},"place":{},"shop":{},"aeroway":{"blacklist":["taxiway"]},"tourism":{},"historic":{},"public_transport":{},"office":{},"building:part":{},"military":{},"ruins":{},"area:highway":{},"craft":{},"golf":{},"indoor":{}}
},{}],4:[function(require,module,exports){
module.exports = (() => {
'use strict';
let purgeProps = (obj, blacklist) => {
if (obj) {
let rs = Object.assign({}, obj);
for (let prop of blacklist) delete rs[prop];
return rs;
}
return {};
}
let mergeProps = (obj1, obj2) => {
obj1 = obj1? obj1 : {};
obj2 = obj2? obj2 : {};
return Object.assign(obj1, obj2);
}
let first = a => a[0];

@@ -545,3 +619,3 @@ let last = a => a[a.length - 1];

let isRing = a => (a.length > 2 && coordsToKey(first(a)) === coordsToKey(last(a)));
let isRing = a => a.length > 2 && coordsToKey(first(a)) === coordsToKey(last(a));

@@ -578,4 +652,3 @@ let ringDirection = (a, xIdx, yIdx) => {

cleanup() {
let entries = Object.entries(this);
for (let [k, v] of entries) {
for (let [k, v] of Object.entries(this)) {
if (v && v.unlinkRef) v.unlinkRef();

@@ -601,2 +674,7 @@ delete this[k];

[].splice.apply(this.container, args);
} else if (typeof this.container === 'object') {
let k = Object.keys(this.container).find(v => this.container[v] === this);
if (k)
if (v) this.container[k] = v;
else delete this.container[k];
}

@@ -669,8 +747,12 @@ }

return {first, last, coordsToKey, addToMap, removeFromMap, getFirstFromMap,
isRing, ringDirection, ptInsidePolygon, strToFloat,
return {purgeProps, mergeProps,
first, last, coordsToKey,
addToMap, removeFromMap, getFirstFromMap,
isRing, ringDirection, ptInsidePolygon, strToFloat,
RefElements, LateBinder, WayCollection};
})();
},{}],4:[function(require,module,exports){
},{}],5:[function(require,module,exports){
module.exports = (() => {
'use strict';
function conditioned(evt) {

@@ -713,7 +795,13 @@ return evt.match(/^(.+?)\[(.+?)\]>$/g) != null;

let attRegEx = /([^ ]+?)="(.+?)"/g, attMatch = null, hasAttrs = false;
while (attMatch = attRegEx.exec(attrText)) {
let attRegEx1 = /([^ ]+?)="(.+?)"/g, attRegEx2 = /([^ ]+?)='(.+?)'/g;
let 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];
}

@@ -723,2 +811,3 @@ if (!hasAttrs && attrText !== '') node.text = attrText;

if (!closed) {

@@ -740,2 +829,3 @@ let innerRegEx = new RegExp(`([^]+?)<\/${tag}>`, 'g');

if (this.progressive) this.emit(`</${fullTag}>`, node, parent);
nodes.push(node);

@@ -742,0 +832,0 @@ }

@@ -1,1 +0,1 @@

!function(){return function e(t,r,s){function o(i,l){if(!r[i]){if(!t[i]){var a="function"==typeof require&&require;if(!l&&a)return a(i,!0);if(n)return n(i,!0);var d=new Error("Cannot find module '"+i+"'");throw d.code="MODULE_NOT_FOUND",d}var f=r[i]={exports:{}};t[i][0].call(f.exports,function(e){return o(t[i][1][e]||e)},f,f.exports,e,t,r,s)}return r[i].exports}for(var n="function"==typeof require&&require,i=0;i<s.length;i++)o(s[i]);return o}}()({1:[function(require,module,exports){const{Node:Node,Way:Way,Relation:Relation}=require("./osmobjs.js"),{RefElements:RefElements}=require("./utils.js"),XmlParser=require("./xmlparser.js");module.exports=((osm,opts)=>{let refElements=new RefElements,featureArray=[],analyzefeaturesFromJson=()=>{for(let elem of osm.elements)switch(elem.type){case"node":let node=new Node(elem.id,refElements);elem.tags&&node.addTags(elem.tags),node.setCoords([elem.lon,elem.lat]),node.addTags(elem.tags);break;case"way":let way=new Way(elem.id,refElements);if(elem.tags&&way.addTags(elem.tags),elem.nodes)for(let e of elem.nodes)way.addNodeRef(e);else if(elem.geometry)for(let e of elem.geometry)way.addCoords([e.lon,e.lat]);break;case"relation":let relation=new Relation(elem.id,refElements);if(elem.bounds)with(elem.bounds)relation.addProperty("bbox",[parseFloat(minlon),parseFloat(minlat),parseFloat(maxlon),parseFloat(maxlat)]);if(elem.tags&&relation.addTags(elem.tags),elem.members)for(let member of elem.members)relation.addMember(member)}},analyzefeaturesFromXml=()=>{const xmlParser=new XmlParser({progressive:!0});xmlParser.addListener("<osm.relation>",e=>{new Relation(e.$id,refElements)}),xmlParser.addListener("</osm.way>",node=>{with(node){let way=new Way($id,refElements);if(node.innerNodes)for(let nd of innerNodes)nd.$lon&&nd.$lat?way.addCoords([nd.$lon,nd.$lat]):nd.$ref&&way.addNodeRef(nd.$ref)}}),xmlParser.addListener("</osm.node>",node=>{with(node){let nd=new Node($id,refElements);if(nd.setCoords([$lon,$lat]),node.innerNodes)for(let tag of innerNodes)nd.addTag(tag.$k,tag.$v)}}),xmlParser.addListener("<osm.relation>",(node,parent)=>{with(node)new Relation($id,refElements)}),xmlParser.addListener("</osm.relation.member>",(node,parent)=>{with(node){let relation=refElements[parent.$id],member={type:$type,role:node.$role?$role:"",id:$ref,ref:$ref};if(node.$lat&&node.$lon){member.lat=$lat,member.lon=$lon,member.tags={};let entries=Object.entries(node);for(let[k,v]of entries)k.startsWith("$")&&["$lat","$lon","$type"].indexOf(k)<0&&(member.tags[k.substring(1)]=v)}if(node.innerNodes){let geometry=[],nodes=[];for(let ind of innerNodes)ind.$lat&&ind.$lon?geometry.push({lat:ind.$lat,lon:ind.$lon}):nodes.push(ind.$ref);geometry.length>0?member.geometry=geometry:nodes.length>0&&(member.nodes=nodes)}relation.addMember(member)}}),xmlParser.addListener("</osm.relation.bounds>",(e,t)=>refElements[t.$id].addProperty("bbox",[parseFloat(e.$minlon),parseFloat(e.$minlat),parseFloat(e.$maxlon),parseFloat(e.$maxlat)])),xmlParser.addListener("</osm.relation.tag>",(e,t)=>{refElements[t.$id].addTag(e.$k,e.$v)}),xmlParser.parse(osm)};osm.elements?analyzefeaturesFromJson(osm):analyzefeaturesFromXml(osm);let entries=Object.entries(refElements);for(let[k,v]of entries)if(v&&v.refCount<=0)if(v.toFeature){let feature=v.toFeature();feature&&featureArray.push(feature)}else v.toFeatureArray&&(featureArray=featureArray.concat(v.toFeatureArray()));return refElements.cleanup(),opts&&opts.allFeatures||!(featureArray.length>0)?{type:"FeatureCollection",features:featureArray}:featureArray[0].geometry})},{"./osmobjs.js":2,"./utils.js":3,"./xmlparser.js":4}],2:[function(e,t,r){t.exports=(()=>{"use strict";const{first:t,last:r,coordsToKey:s,addToMap:o,removeFromMap:n,getFirstFromMap:i,isRing:l,ringDirection:a,ptInsidePolygon:d,strToFloat:f,LateBinder:h,WayCollection:u}=e("./utils.js");class m{constructor(e,t,r){this.type=e,this.id=t,this.refElems=r,this.tags={},this.properties={id:this.getCompositeId()},this.refCount=0,r&&r.add(t,this)}addTags(e){this.tags=Object.assign(this.tags,e)}addTag(e,t){this.tags[e]=t}addProperty(e,t){this.properties[e]=t}getCompositeId(){return`${this.type}/${this.id}`}getProperties(){return Object.assign(this.properties,this.tags)}unlinkRef(){this.refElems=null}}class p extends m{constructor(e,t){super("node",e,t),this.coords=null}setCoords(e){e instanceof Array&&(this.coords=e)}toFeature(){if(this.coords)return{type:"Feature",id:this.getCompositeId(),properties:this.getProperties(),geometry:{type:"Point",coordinates:f(this.coords)}}}getCoords(){return this.coords}}class c extends m{constructor(e,t){super("way",e,t),this.coordsArray=[]}addCoords(e){this.coordsArray.push(e)}addNodeRef(e){this.coordsArray.push(new h(this.coordsArray,function(e){let t=this.refElems[e];if(t)return t.refCount++,t.getCoords()},this,[e]))}bindRefs(){this.coordsArray.reduce((e,t)=>t instanceof h?e.concat([t]):e,[]).forEach(e=>e.bind())}toCoordsArray(){return this.bindRefs(),this.coordsArray}toFeature(){if(this.bindRefs(),this.coordsArray.length>1)return l(this.coordsArray)?("counterclockwise"!==a(this.coordsArray)&&this.coordsArray.reverse(),{type:"Feature",id:this.getCompositeId(),properties:this.getProperties(),geometry:{type:"Polygon",coordinates:[f(this.coordsArray)]}}):{type:"Feature",id:this.getCompositeId(),properties:this.getProperties(),geometry:{type:"LineString",coordinates:f(this.coordsArray)}}}}return{Node:p,Way:c,Relation:class extends m{constructor(e,t){super("relation",e,t),this.relations=[],this.nodes=[]}addMember(e){switch(e.type){case"relation":this.relations.push(new h(this.relations,function(e){let t=this.refElems[e];if(t)return t.refCount++,t},this,[e.ref]));break;case"way":e.role||e.role;let t=this[e.role];if(t||(t=this[e.role]=[]),e.geometry){let r=new c(e.ref,this.refElems);for(let t of e.geometry)r.addCoords([t.lon,t.lat]),r.refCount++;t.push(r)}else if(e.nodes){let r=new c(e.id,this.refElems);for(let e of nodes)r.addNodeRef(e),r.refCount++;t.push(r)}else t.push(new h(t,function(e){let t=this.refElems[e];if(t)return t.refCount++,t},this,[e.ref]));break;case"node":let r=null;if(e.lat&&e.lon){(r=new p(e.ref,this.refElems)).setCoords([e.lon,e.lat]),e.tags&&r.addTags(e.tags);let t=Object.entries(e);for(let[e,s]of t)"lat"!==e&&"lon"!==e&&"id"!==e&&"tags"!==e&&r.addTag(e,s);r.refCount++,this.nodes.push(r)}else this.nodes.push(new h(this.nodes,function(e){let t=this.refElems[e];if(t)return t.refCount++,t},this,[e.ref]))}}bindRefs(){const e=["relations","nodes","outer","inner",""];for(let t of e){let e=this[t];if(e&&e.length>0){let t=e.slice(0);for(let e of t)e instanceof h?e.bind():e.bindRefs&&e.bindRefs()}}}toFeatureArray(){this.bindRefs();let e=[],r=[],s=[];const o=["outer","inner",""];for(let e of this.relations)if(console.log(e.constructor.name),console.log(e.id),e&&e.bindRefs())for(let t of o){let r=e[t];if(r){let e=this[t];e?[].splice.apply(e,[e.length,0].concat(r)):this[t]=r}}for(let e of o){let t=this[e];if(t){this[e]=new u;for(let r of t)this[e].addWay(r)}}let n=null;this.outer?(n=((e,r)=>{let s=e?e.toRings("counterclockwise"):[],o=r?r.toRings("clockwise"):[];if(s.length>0){let e=[],r=null;for(r of s)e.push([r]);for(;r=o.shift();)for(let o in s)if(d(t(r),s[o])){e[o].push(r);break}return 1===e.length?{type:"Polygon",coordinates:e[0]}:{type:"MultiPolygon",coordinates:e}}return null})(this.outer,this.inner))&&e.push({type:"Feature",id:this.getCompositeId(),properties:this.getProperties(),geometry:n}):this[""]&&(n=(e=>{let t=e?e.toStrings():[];return t.length>0?1===t.length?{type:"LineString",coordinates:t[0]}:{type:"MultiLineString",coordinates:t}:null})(this[""]))&&r.push({type:"Feature",id:this.getCompositeId(),properties:this.getProperties(),geometry:n});for(let e of this.nodes)s.push(e.toFeature());return e.concat(r).concat(s)}}}})()},{"./utils.js":3}],3:[function(e,t,r){t.exports=(()=>{"use strict";let e=e=>e[0],t=e=>e[e.length-1],r=e=>e.join(","),s=(e,t,r)=>{let s=e[t];s?s.push(r):e[t]=[r]},o=(e,t,r)=>{let s=e[t];s&&s.splice(s.indexOf(r),1)},n=(e,t)=>{let r=e[t];return r&&r.length>0?r[0]:null},i=s=>s.length>2&&r(e(s))===r(t(s)),l=(e,t,r)=>{t=t||0,r=r||1;let s=e.reduce((r,s,o)=>e[r][t]>s[t]?r:o,0),o=s<=0?e.length-1:s-1,n=s>=e.length-1?0:s+1,i=e[o][t],l=e[s][t],a=e[n][t],d=e[o][r],f=e[s][r];return(l-i)*(e[n][r]-d)-(a-i)*(f-d)<0?"clockwise":"counterclockwise"},a=e=>e instanceof Array?e.map(a):parseFloat(e);return{first:e,last:t,coordsToKey:r,addToMap:s,removeFromMap:o,getFirstFromMap:n,isRing:i,ringDirection:l,ptInsidePolygon:(e,t,r,s)=>{r=r||0,s=s||1;let o=!1;for(let n=0,i=t.length-1;n<t.length;i=n++)(t[n][r]<=e[r]&&e[r]<t[i][r]||t[i][r]<=e[r]&&e[r]<t[n][r])&&e[s]<(t[i][s]-t[n][s])*(e[r]-t[n][r])/(t[i][r]-t[n][r])+t[n][s]&&(o=!o);return o},strToFloat:a,RefElements:class{add(e,t){this[e]=t}cleanup(){let e=Object.entries(this);for(let[t,r]of e)r&&r.unlinkRef&&r.unlinkRef(),delete this[t]}},LateBinder:class{constructor(e,t,r,s){this.container=e,this.valueFunc=t,this.ctx=r,this.args=s}bind(){let e=this.valueFunc.apply(this.ctx,this.args);if(this.container instanceof Array){let t=[this.container.indexOf(this),1];e&&t.push(e),[].splice.apply(this.container,t)}}},WayCollection:class extends Array{constructor(){super(),this.firstMap={},this.lastMap={}}addWay(o){o=o.toCoordsArray(),this.push(o),s(this.firstMap,r(e(o)),o),s(this.lastMap,r(t(o)),o)}toStrings(){let s=[],i=null;for(;i=this.shift();){o(this.firstMap,r(e(i)),i),o(this.lastMap,r(t(i)),i);let l=i,d=null;do{let s=r(t(l)),i=!1;(d=n(this.firstMap,s))||(d=n(this.lastMap,s),i=!0),d&&(this.splice(this.indexOf(d),1),o(this.firstMap,r(e(d)),d),o(this.lastMap,r(t(d)),d),i&&(d.length>l.length&&([l,d]=[d,l]),d.reverse()),l=l.concat(d.slice(1)))}while(d);s.push(a(l))}return s}toRings(e){let t=this.toStrings(),r=[],s=null;for(;s=t.shift();)i(s)&&(l(s)!=e&&s.reverse(),r.push(s));return r}}}})()},{}],4:[function(e,t,r){t.exports=(()=>{function e(e){return null!=e.match(/^(.+?)\[(.+?)\]>$/g)}function t(e){let t=/^(.+?)\[(.+?)\]>$/g.exec(e);return t?{evt:t[1]+">",exp:t[2]}:{evt:e}}return class{constructor(e){e&&(this.queryParent=!!e.queryParent,this.progressive=e.progressive,this.queryParent&&(this.parentMap=new WeakMap)),this.evtListeners={}}parse(e,t,r){r=r?r+".":"";let s=/<([^ >\/]+)(.*?)>/gm,o=null,n=[];for(;o=s.exec(e);){let i=o[1],l={tag:i},a=r+i,d=o[2].trim(),f=!1;(d.endsWith("/")||i.startsWith("?")||i.startsWith("!"))&&(f=!0);let h=/([^ ]+?)="(.+?)"/g,u=null,m=!1;for(;u=h.exec(d);)m=!0,l[`$${u[1]}`]=u[2];if(m||""===d||(l.text=d),this.progressive&&this.emit(`<${a}>`,l,t),!f){let t=new RegExp(`([^]+?)</${i}>`,"g");t.lastIndex=s.lastIndex;let r=t.exec(e);if(r&&r[1]){s.lastIndex=t.lastIndex;let e=this.parse(r[1],l,a);e.length>0?l.innerNodes=e:l.innerText=r[1]}}this.queryParent&&t&&this.parentMap.set(l,t),this.progressive&&this.emit(`</${a}>`,l,t),n.push(l)}return n}getParent(e){return this.queryParent?this.parentMap.get(e):null}$addListener(e,t){let r=this.evtListeners[e];r?r.push(t):this.evtListeners[e]=[t]}addListener(r,s){e(r)&&(r=t(r),s.condition=function(e){let t="return "+e.replace(/(\$.+?)(?=[=!.])/g,"node.$&")+";";return new Function("node",t)}(r.exp),r=r.evt),this.$addListener(r,s)}$removeListener(e,t){let r=this.evtListeners[e];r&&r.splice(r.indexOf(t),1)}removeListener(r,s){e(r)&&(r=(r=t(r)).evt),this.$removeListener(r,s)}emit(e,...t){let r=this.evtListeners[e];if(r)for(let e of r)e.condition?!0===e.condition.apply(null,t)&&e.apply(null,t):e.apply(null,t)}on(e,t){this.addListener(e,t)}off(e,t){this.removeListener(e,t)}}})()},{}]},{},[1]);
!function(){return function e(t,r,s){function o(n,a){if(!r[n]){if(!t[n]){var l="function"==typeof require&&require;if(!a&&l)return l(n,!0);if(i)return i(n,!0);var d=new Error("Cannot find module '"+n+"'");throw d.code="MODULE_NOT_FOUND",d}var h=r[n]={exports:{}};t[n][0].call(h.exports,function(e){return o(t[n][1][e]||e)},h,h.exports,e,t,r,s)}return r[n].exports}for(var i="function"==typeof require&&require,n=0;n<s.length;n++)o(s[n]);return o}}()({1:[function(require,module,exports){const{Node:Node,Way:Way,Relation:Relation}=require("./osmobjs.js"),{purgeProps:purgeProps,RefElements:RefElements}=require("./utils.js"),XmlParser=require("./xmlparser.js");module.exports=((osm,opts)=>{let completeFeature=!1,renderTagged=!1,suppressWay=!0,parseOpts=e=>{e&&(completeFeature=!(!e.completeFeature&&!e.allFeatures),renderTagged=!!e.renderTagged,void 0===e.suppressWay||e.suppressWay||(suppressWay=!1))};parseOpts(opts);let refElements=new RefElements,featureArray=[],analyzefeaturesFromJson=()=>{for(let elem of osm.elements)switch(elem.type){case"node":let node=new Node(elem.id,refElements);elem.tags&&node.addTags(elem.tags),node.addProps(purgeProps(elem,["id","type","tags","lat","lon"])),node.setCoords([elem.lon,elem.lat]);break;case"way":let way=new Way(elem.id,refElements);if(elem.tags&&way.addTags(elem.tags),way.addProps(purgeProps(elem,["id","type","tags","nodes","geometry"])),elem.nodes)for(let e of elem.nodes)way.addNodeRef(e);else if(elem.geometry)for(let e of elem.geometry)way.addCoords([e.lon,e.lat]);break;case"relation":let relation=new Relation(elem.id,refElements);if(elem.bounds)with(elem.bounds)relation.addProp("bbox",[parseFloat(minlon),parseFloat(minlat),parseFloat(maxlon),parseFloat(maxlat)]);if(elem.tags&&relation.addTags(elem.tags),relation.addProps(purgeProps(elem,["id","type","tags","bounds","members"])),elem.members)for(let member of elem.members)relation.addMember(member)}},analyzefeaturesFromXml=()=>{const xmlParser=new XmlParser({progressive:!0});xmlParser.on("<osm.node>",e=>{new Node(e.$id,refElements)}),xmlParser.on("<osm.way>",e=>{new Way(e.$id,refElements)}),xmlParser.on("<osm.relation>",e=>{new Relation(e.$id,refElements)}),xmlParser.on("</osm.way>",node=>{with(node){let way=refElements[$id];for(let[k,v]of Object.entries(node))k.startsWith("$")&&["$id"].indexOf(k)<0&&way.addProp(k.substring(1),v);if(node.innerNodes)for(let ind of innerNodes)ind.$lon&&ind.$lat?way.addCoords([ind.$lon,ind.$lat]):ind.$ref?way.addNodeRef(ind.$ref):"tag"===ind.tag&&way.addTag(ind.$k,ind.$v)}}),xmlParser.on("</osm.node>",node=>{with(node){let nd=refElements[$id];for(let[k,v]of Object.entries(node))k.startsWith("$")&&["$id","$lon","$lat"].indexOf(k)<0&&nd.addProp(k.substring(1),v);if(nd.setCoords([$lon,$lat]),node.innerNodes)for(let ind of innerNodes)"tag"===ind.tag&&nd.addTag(ind.$k,ind.$v)}}),xmlParser.on("</osm.relation.member>",(node,parent)=>{with(node){let relation=refElements[parent.$id],member={type:$type,role:node.$role?$role:"",ref:$ref};if(node.$lat&&node.$lon){member.lat=$lat,member.lon=$lon,member.tags={};for(let[k,v]of Object.entries(node))k.startsWith("$")&&["$type","$lat","$lon"].indexOf(k)<0&&(member[k.substring(1)]=v)}if(node.innerNodes){let geometry=[],nodes=[];for(let ind of innerNodes)ind.$lat&&ind.$lon?geometry.push({lat:ind.$lat,lon:ind.$lon}):nodes.push(ind.$ref);geometry.length>0?member.geometry=geometry:nodes.length>0&&(member.nodes=nodes)}relation.addMember(member)}}),xmlParser.on("</osm.relation.bounds>",(node,parent)=>{with(node)refElements[parent.$id].addProp("bbox",[parseFloat($minlon),parseFloat($minlat),parseFloat($maxlon),parseFloat($maxlat)])}),xmlParser.on("</osm.relation.tag>",(e,t)=>{let r=refElements[t.$id];r&&r.addTag(e.$k,e.$v)}),xmlParser.parse(osm)};osm.elements?analyzefeaturesFromJson(osm):analyzefeaturesFromXml(osm);for(let[k,v]of Object.entries(refElements))if(v&&(v.refCount<=0||renderTagged&&v.hasTag&&!(v instanceof Way&&suppressWay)))if(v.toFeature){let feature=v.toFeature();feature&&featureArray.push(feature)}else v.toFeatureArray&&(featureArray=featureArray.concat(v.toFeatureArray()));return refElements.cleanup(),!completeFeature&&featureArray.length>0?featureArray[0].geometry:{type:"FeatureCollection",features:featureArray}})},{"./osmobjs.js":2,"./utils.js":4,"./xmlparser.js":5}],2:[function(e,t,r){t.exports=(()=>{"use strict";const{first:t,last:r,coordsToKey:s,addToMap:o,removeFromMap:i,getFirstFromMap:n,isRing:a,ringDirection:l,ptInsidePolygon:d,strToFloat:h,LateBinder:f,WayCollection:u}=e("./utils.js"),p=e("./polytags.json");class c{constructor(e,t,r){this.type=e,this.id=t,this.refElems=r,this.tags={},this.props={id:this.getCompositeId()},this.refCount=0,this.hasTag=!1,r&&r.add(t,this)}addTags(e){this.tags=Object.assign(this.tags,e),this.hasTag=!!e}addTag(e,t){this.tags[e]=t,this.hasTag=!!e}addProp(e,t){this.props[e]=t}addProps(e){this.props=Object.assign(this.props,e)}getCompositeId(){return`${this.type}/${this.id}`}getProps(){return Object.assign(this.props,this.tags)}unlinkRef(){this.refElems=null}}class m extends c{constructor(e,t){super("node",e,t),this.coords=null}setCoords(e){e instanceof Array&&(this.coords=e)}toFeature(){if(this.coords)return{type:"Feature",id:this.getCompositeId(),properties:this.getProps(),geometry:{type:"Point",coordinates:h(this.coords)}}}getCoords(){return this.coords}}class g extends c{constructor(e,t){super("way",e,t),this.coordsArray=[],this.isPolygon=!1,this.isBound=!1}addCoords(e){this.coordsArray.push(e)}addNodeRef(e){this.coordsArray.push(new f(this.coordsArray,function(e){let t=this.refElems[e];if(t)return t.refCount++,t.getCoords()},this,[e]))}analyzeTag(e,t){let r=p[e];r&&(this.isPolygon=!0,r.whitelist?this.isPolygon=r.whitelist.indexOf(t)>=0:r.blacklist&&(this.isPolygon=!(r.blacklist.indexOf(t)>=0)))}addTags(e){super.addTags(e);for(let[t,r]of Object.entries(e))this.analyzeTag(t,r)}addTag(e,t){super.addTag(e,t),this.analyzeTag(e,t)}bindRefs(){this.isBound||(this.coordsArray.reduce((e,t)=>t instanceof f?e.concat([t]):e,[]).forEach(e=>e.bind()),this.isBound=!0)}toCoordsArray(){return this.bindRefs(),this.coordsArray}toFeature(){if(this.bindRefs(),this.coordsArray.length>1)return this.isPolygon&&a(this.coordsArray)?("counterclockwise"!==l(this.coordsArray)&&this.coordsArray.reverse(),{type:"Feature",id:this.getCompositeId(),properties:this.getProps(),geometry:{type:"Polygon",coordinates:[h(this.coordsArray)]}}):{type:"Feature",id:this.getCompositeId(),properties:this.getProps(),geometry:{type:"LineString",coordinates:h(this.coordsArray)}}}}return{Node:m,Way:g,Relation:class extends c{constructor(e,t){super("relation",e,t),this.relations=[],this.nodes=[],this.isBound=!1}addMember(e){switch(e.type){case"relation":this.relations.push(new f(this.relations,function(e){let t=this.refElems[e];if(t)return t.refCount++,t},this,[e.ref]));break;case"way":e.role||e.role;let t=this[e.role];if(t||(t=this[e.role]=[]),e.geometry){let r=new g(e.ref,this.refElems);for(let t of e.geometry)r.addCoords([t.lon,t.lat]),r.refCount++;t.push(r)}else if(e.nodes){let r=new g(e.ref,this.refElems);for(let e of nodes)r.addNodeRef(e),r.refCount++;t.push(r)}else t.push(new f(t,function(e){let t=this.refElems[e];if(t)return t.refCount++,t},this,[e.ref]));break;case"node":let r=null;if(e.lat&&e.lon){(r=new m(e.ref,this.refElems)).setCoords([e.lon,e.lat]),e.tags&&r.addTags(e.tags);for(let[t,s]of Object.entries(e))"id"!==t&&"type"!==t&&"lat"!==t&&"lon"!==t&&r.addProp(t,s);r.refCount++,this.nodes.push(r)}else this.nodes.push(new f(this.nodes,function(e){let t=this.refElems[e];if(t)return t.refCount++,t},this,[e.ref]))}}bindRefs(){if(!this.isBound){const e=["relations","nodes","outer","inner",""];for(let t of e){let e=this[t];if(e&&e.length>0){let t=e.slice(0);for(let e of t)e instanceof f?e.bind():e.bindRefs&&e.bindRefs()}}this.isBound=!0}}toFeatureArray(){this.bindRefs();let e=[],r=[],s=[];const o=["outer","inner",""];for(let e of this.relations)if(e){e.bindRefs();for(let t of o){let r=e[t];if(r){let e=this[field];e?[].splice.apply(e,[e.length,0].concat(r)):this[t]=r}}}for(let e of o){let t=this[e];if(t){this[e]=new u;for(let r of t)this[e].addWay(r)}}let i=null;this.outer?(i=((e,r)=>{let s=e?e.toRings("counterclockwise"):[],o=r?r.toRings("clockwise"):[];if(s.length>0){let e=[],r=null;for(r of s)e.push([r]);for(;r=o.shift();)for(let o in s)if(d(t(r),s[o])){e[o].push(r);break}return 1===e.length?{type:"Polygon",coordinates:e[0]}:{type:"MultiPolygon",coordinates:e}}return null})(this.outer,this.inner))&&e.push({type:"Feature",id:this.getCompositeId(),properties:this.getProps(),geometry:i}):this[""]&&(i=(e=>{let t=e?e.toStrings():[];return t.length>0?1===t.length?{type:"LineString",coordinates:t[0]}:{type:"MultiLineString",coordinates:t}:null})(this[""]))&&r.push({type:"Feature",id:this.getCompositeId(),properties:this.getProps(),geometry:i});for(let e of this.nodes)s.push(e.toFeature());return e.concat(r).concat(s)}}}})()},{"./polytags.json":3,"./utils.js":4}],3:[function(e,t,r){t.exports={building:{},highway:{whitelist:["services","rest_area","escape","elevator"]},natural:{blacklist:["coastline","cliff","ridge","arete","tree_row"]},landuse:{},waterway:{whitelist:["riverbank","dock","boatyard","dam"]},amenity:{},leisure:{},barrier:{whitelist:["city_wall","ditch","hedge","retaining_wall","wall","spikes"]},railway:{whitelist:["station","turntable","roundhouse","platform"]},area:{},boundary:{},man_made:{blacklist:["cutline","embankment","pipeline"]},power:{whitelist:["plant","substation","generator","transformer"]},place:{},shop:{},aeroway:{blacklist:["taxiway"]},tourism:{},historic:{},public_transport:{},office:{},"building:part":{},military:{},ruins:{},"area:highway":{},craft:{},golf:{},indoor:{}}},{}],4:[function(e,t,r){t.exports=(()=>{"use strict";let e=e=>e[0],t=e=>e[e.length-1],r=e=>e.join(","),s=(e,t,r)=>{let s=e[t];s?s.push(r):e[t]=[r]},o=(e,t,r)=>{let s=e[t];s&&s.splice(s.indexOf(r),1)},i=(e,t)=>{let r=e[t];return r&&r.length>0?r[0]:null},n=s=>s.length>2&&r(e(s))===r(t(s)),a=(e,t,r)=>{t=t||0,r=r||1;let s=e.reduce((r,s,o)=>e[r][t]>s[t]?r:o,0),o=s<=0?e.length-1:s-1,i=s>=e.length-1?0:s+1,n=e[o][t],a=e[s][t],l=e[i][t],d=e[o][r],h=e[s][r];return(a-n)*(e[i][r]-d)-(l-n)*(h-d)<0?"clockwise":"counterclockwise"},l=e=>e instanceof Array?e.map(l):parseFloat(e);return{purgeProps:(e,t)=>{if(e){let r=Object.assign({},e);for(let e of t)delete r[e];return r}return{}},mergeProps:(e,t)=>(e=e||{},t=t||{},Object.assign(e,t)),first:e,last:t,coordsToKey:r,addToMap:s,removeFromMap:o,getFirstFromMap:i,isRing:n,ringDirection:a,ptInsidePolygon:(e,t,r,s)=>{r=r||0,s=s||1;let o=!1;for(let i=0,n=t.length-1;i<t.length;n=i++)(t[i][r]<=e[r]&&e[r]<t[n][r]||t[n][r]<=e[r]&&e[r]<t[i][r])&&e[s]<(t[n][s]-t[i][s])*(e[r]-t[i][r])/(t[n][r]-t[i][r])+t[i][s]&&(o=!o);return o},strToFloat:l,RefElements:class{add(e,t){this[e]=t}cleanup(){for(let[e,t]of Object.entries(this))t&&t.unlinkRef&&t.unlinkRef(),delete this[e]}},LateBinder:class{constructor(e,t,r,s){this.container=e,this.valueFunc=t,this.ctx=r,this.args=s}bind(){let e=this.valueFunc.apply(this.ctx,this.args);if(this.container instanceof Array){let t=[this.container.indexOf(this),1];e&&t.push(e),[].splice.apply(this.container,t)}else if("object"==typeof this.container){let t=Object.keys(this.container).find(e=>this.container[e]===this);t&&(e?this.container[t]=e:delete this.container[t])}}},WayCollection:class extends Array{constructor(){super(),this.firstMap={},this.lastMap={}}addWay(o){o=o.toCoordsArray(),this.push(o),s(this.firstMap,r(e(o)),o),s(this.lastMap,r(t(o)),o)}toStrings(){let s=[],n=null;for(;n=this.shift();){o(this.firstMap,r(e(n)),n),o(this.lastMap,r(t(n)),n);let a=n,d=null;do{let s=r(t(a)),n=!1;(d=i(this.firstMap,s))||(d=i(this.lastMap,s),n=!0),d&&(this.splice(this.indexOf(d),1),o(this.firstMap,r(e(d)),d),o(this.lastMap,r(t(d)),d),n&&(d.length>a.length&&([a,d]=[d,a]),d.reverse()),a=a.concat(d.slice(1)))}while(d);s.push(l(a))}return s}toRings(e){let t=this.toStrings(),r=[],s=null;for(;s=t.shift();)n(s)&&(a(s)!=e&&s.reverse(),r.push(s));return r}}}})()},{}],5:[function(e,t,r){t.exports=(()=>{"use strict";function e(e){return null!=e.match(/^(.+?)\[(.+?)\]>$/g)}function t(e){let t=/^(.+?)\[(.+?)\]>$/g.exec(e);return t?{evt:t[1]+">",exp:t[2]}:{evt:e}}return class{constructor(e){e&&(this.queryParent=!!e.queryParent,this.progressive=e.progressive,this.queryParent&&(this.parentMap=new WeakMap)),this.evtListeners={}}parse(e,t,r){r=r?r+".":"";let s=/<([^ >\/]+)(.*?)>/gm,o=null,i=[];for(;o=s.exec(e);){let n=o[1],a={tag:n},l=r+n,d=o[2].trim(),h=!1;(d.endsWith("/")||n.startsWith("?")||n.startsWith("!"))&&(h=!0);let f=/([^ ]+?)="(.+?)"/g,u=/([^ ]+?)='(.+?)'/g,p=null,c=!1;for(;p=f.exec(d);)c=!0,a[`$${p[1]}`]=p[2];if(!c)for(;p=u.exec(d);)c=!0,a[`$${p[1]}`]=p[2];if(c||""===d||(a.text=d),this.progressive&&this.emit(`<${l}>`,a,t),!h){let t=new RegExp(`([^]+?)</${n}>`,"g");t.lastIndex=s.lastIndex;let r=t.exec(e);if(r&&r[1]){s.lastIndex=t.lastIndex;let e=this.parse(r[1],a,l);e.length>0?a.innerNodes=e:a.innerText=r[1]}}this.queryParent&&t&&this.parentMap.set(a,t),this.progressive&&this.emit(`</${l}>`,a,t),i.push(a)}return i}getParent(e){return this.queryParent?this.parentMap.get(e):null}$addListener(e,t){let r=this.evtListeners[e];r?r.push(t):this.evtListeners[e]=[t]}addListener(r,s){e(r)&&(r=t(r),s.condition=function(e){let t="return "+e.replace(/(\$.+?)(?=[=!.])/g,"node.$&")+";";return new Function("node",t)}(r.exp),r=r.evt),this.$addListener(r,s)}$removeListener(e,t){let r=this.evtListeners[e];r&&r.splice(r.indexOf(t),1)}removeListener(r,s){e(r)&&(r=(r=t(r)).evt),this.$removeListener(r,s)}emit(e,...t){let r=this.evtListeners[e];if(r)for(let e of r)e.condition?!0===e.condition.apply(null,t)&&e.apply(null,t):e.apply(null,t)}on(e,t){this.addListener(e,t)}off(e,t){this.removeListener(e,t)}}})()},{}]},{},[1]);
const {Node, Way, Relation} = require('./osmobjs.js'),
{purgeProps, mergeProps, RefElements} = require('./utils.js'),
{purgeProps, RefElements} = require('./utils.js'),
XmlParser = require('./xmlparser.js');
module.exports = (osm, opts) => {
let completeFeature = false, renderTagged = false, suppressWay = true;
let parseOpts = opts => {
if (opts) {
completeFeature = opts.completeFeature || opts.allFeatures? true : false;
renderTagged = opts.renderTagged? true : false;
if (opts.suppressWay !== undefined && !opts.suppressWay) suppressWay = false;
}
}
parseOpts(opts);
let refElements = new RefElements(), featureArray = [];

@@ -13,5 +25,6 @@

let node = new Node(elem.id, refElements);
node.addTags(mergeProps(elem.tags, purgeProps(elem, ['id', 'type', 'tags', 'lat', 'lon'])));
if (elem.tags)
node.addTags(elem.tags);
node.addProps(purgeProps(elem, ['id', 'type', 'tags', 'lat', 'lon']));
node.setCoords([elem.lon, elem.lat]);
node.addTags(elem.tags);
break;

@@ -21,3 +34,4 @@

let way = new Way(elem.id, refElements);
way.addTags(mergeProps(elem.tags, purgeProps(elem, ['id', 'type', 'tags', 'nodes', 'geometry'])));
if (elem.tags) way.addTags(elem.tags);
way.addProps(purgeProps(elem, ['id', 'type', 'tags', 'nodes', 'geometry']));
if (elem.nodes)

@@ -34,4 +48,5 @@ for (let n of elem.nodes)

if (elem.bounds) with (elem.bounds)
relation.addProperty('bbox', [parseFloat(minlon), parseFloat(minlat), parseFloat(maxlon), parseFloat(maxlat)]);
relation.addTags(mergeProps(elem.tags, purgeProps(elem, ['id', 'type', 'tags', 'bounds', 'members'])));
relation.addProp('bbox', [parseFloat(minlon), parseFloat(minlat), parseFloat(maxlon), parseFloat(maxlat)]);
if (elem.tags) relation.addTags(elem.tags);
relation.addProps(purgeProps(elem, ['id', 'type', 'tags', 'bounds', 'members']));
if (elem.members)

@@ -67,11 +82,11 @@ for (let member of elem.members)

if (k.startsWith('$') && ['$id'].indexOf(k) < 0)
way.addTag(k.substring(1), v);
way.addProp(k.substring(1), v);
if (node.innerNodes) {
for (let ind of innerNodes) {
for (let ind of innerNodes)
if (ind.$lon && ind.$lat)
way.addCoords([ind.$lon, ind.$lat]);
else if (ind.$ref) {
else if (ind.$ref)
way.addNodeRef(ind.$ref);
}
}
else if(ind.tag === 'tag')
way.addTag(ind.$k, ind.$v);
}

@@ -86,4 +101,8 @@ }

if (k.startsWith('$') && ['$id', '$lon', '$lat'].indexOf(k) < 0)
nd.addTag(k.substring(1), v);
nd.addProp(k.substring(1), v);
nd.setCoords([$lon, $lat]);
if (node.innerNodes)
for (let ind of innerNodes)
if(ind.tag === 'tag')
nd.addTag(ind.$k, ind.$v);
}

@@ -98,3 +117,2 @@ });

role: node.$role? $role : '',
id: $ref,
ref: $ref

@@ -107,3 +125,3 @@ };

if (k.startsWith('$') && ['$type', '$lat', '$lon'].indexOf(k) < 0)
member.tags[k.substring(1)] = v;
member[k.substring(1)] = v;
}

@@ -131,12 +149,9 @@

with (node)
refElements[parent.$id].addProperty('bbox', [parseFloat($minlon), parseFloat($minlat), parseFloat($maxlon), parseFloat($maxlat)]);
refElements[parent.$id].addProp('bbox', [parseFloat($minlon), parseFloat($minlat), parseFloat($maxlon), parseFloat($maxlat)]);
});
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);
xmlParser.on('</osm.relation.tag>', (node, parent) => {
let elem = refElements[parent.$id];
if (elem) elem.addTag(node.$k, node.$v);
});

@@ -152,9 +167,8 @@ xmlParser.parse(osm);

for (let [k, v] of Object.entries(refElements)) {
if (v && v.refCount <= 0) {
if (v && (v.refCount <= 0 || (renderTagged && v.hasTag && !(v instanceof Way && suppressWay)))) {
if (v.toFeature) {
let feature = v.toFeature();
if (feature) featureArray.push(feature);
} else if (v.toFeatureArray) {
} else if (v.toFeatureArray)
featureArray = featureArray.concat(v.toFeatureArray());
}
}

@@ -165,3 +179,3 @@ }

if ((!opts || !opts.allFeatures) && featureArray.length > 0)
if (!completeFeature && featureArray.length > 0)
return featureArray[0].geometry;

@@ -168,0 +182,0 @@

module.exports = (() => {
'use strict';
const {first, last, coordsToKey,

@@ -15,4 +16,5 @@ addToMap, removeFromMap, getFirstFromMap,

this.tags = {};
this.properties = {id: this.getCompositeId()};
this.props = {id: this.getCompositeId()};
this.refCount = 0;
this.hasTag = false;
if (refElems) refElems.add(id, this);

@@ -23,2 +25,3 @@ }

this.tags = Object.assign(this.tags, tags);
this.hasTag = tags? true : false;
}

@@ -28,8 +31,13 @@

this.tags[k] = v;
this.hasTag = k? true : false;
}
addProperty(k, v) {
this.properties[k] = v;
addProp(k, v) {
this.props[k] = v;
}
addProps(props) {
this.props = Object.assign(this.props, props);
}
getCompositeId() {

@@ -39,4 +47,4 @@ return `${this.type}/${this.id}`;

getProperties() {
return Object.assign(this.properties, this.tags);
getProps() {
return Object.assign(this.props, this.tags);
}

@@ -67,3 +75,3 @@

id: this.getCompositeId(),
properties: this.getProperties(),
properties: this.getProps(),
geometry: {

@@ -145,3 +153,3 @@ type: 'Point',

id: this.getCompositeId(),
properties: this.getProperties(),
properties: this.getProps(),
geometry: {

@@ -157,3 +165,3 @@ type: 'Polygon',

id: this.getCompositeId(),
properties: this.getProperties(),
properties: this.getProps(),
geometry: {

@@ -200,3 +208,3 @@ type: 'LineString',

} else if (member.nodes) {
let way = new Way(member.id, this.refElems);
let way = new Way(member.ref, this.refElems);
for (let nid of nodes) {

@@ -222,4 +230,4 @@ way.addNodeRef(nid);

for (let [k, v] of Object.entries(member)) {
if (k !== 'lat' && k !== 'lon' && k !== 'id' && k !== 'tags')
node.addTag(k, v);
if (k !== 'id' && k !== 'type' && k !== 'lat' && k !== 'lon')
node.addProp(k, v);
}

@@ -249,2 +257,3 @@ node.refCount++;

if (field && field.length > 0) {
// need a clone 'coz bind will remove elements
let clone = field.slice(0);

@@ -319,3 +328,4 @@ for (let item of clone) {

for (let relation of this.relations) {
if (relation && relation.bindRefs()) {
if (relation) {
relation.bindRefs();
for (let fieldName of waysFieldNames) {

@@ -326,3 +336,3 @@ let ways = relation[fieldName];

if (thisWays) [].splice.apply(thisWays, [thisWays.length, 0].concat(ways));
else this[field] = ways;
else this[fieldName] = ways;
}

@@ -349,3 +359,3 @@ }

id: this.getCompositeId(),
properties: this.getProperties(),
properties: this.getProps(),
geometry

@@ -360,3 +370,3 @@ });

id: this.getCompositeId(),
properties: this.getProperties(),
properties: this.getProps(),
geometry

@@ -363,0 +373,0 @@ });

module.exports = (() => {
'use strict';
function conditioned(evt) {

@@ -39,3 +41,4 @@ return evt.match(/^(.+?)\[(.+?)\]>$/g) != null;

let attRegEx1 = /([^ ]+?)="(.+?)"/g, attRegEx2 = /([^ ]+?)='(.+?)'/g, attMatch = null, hasAttrs = false;
let attRegEx1 = /([^ ]+?)="(.+?)"/g, attRegEx2 = /([^ ]+?)='(.+?)'/g;
let attMatch = null, hasAttrs = false;
while (attMatch = attRegEx1.exec(attrText)) {

@@ -54,2 +57,3 @@ hasAttrs = true;

if (!closed) {

@@ -71,2 +75,3 @@ let innerRegEx = new RegExp(`([^]+?)<\/${tag}>`, 'g');

if (this.progressive) this.emit(`</${fullTag}>`, node, parent);
nodes.push(node);

@@ -73,0 +78,0 @@ }

@@ -55,3 +55,3 @@ {

},
"version": "0.4.5",
"version": "0.4.6",
"directories": {

@@ -58,0 +58,0 @@ "lib": "lib",

@@ -8,3 +8,3 @@ const fs = require('fs'),

let osm = fs.readFileSync(`./data/${file}`, 'utf-8');
console.log(JSON.stringify(osm2geojson(osm, {allFeatures: true})));
console.log(JSON.stringify(osm2geojson(osm, {completeFeature: true, renderTagged: true})));
}

@@ -14,5 +14,7 @@

for (let file of jsonFiles) {
let file = 'map.json';
console.log(`------------------------------${file}------------------------------`);
let osm = require(`./data/${file}`);
console.log(JSON.stringify(osm2geojson(osm, {allFeatures: true})));
console.log(JSON.stringify(osm2geojson(osm, {completeFeature: true, renderTagged: true})));
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc