osm2geojson-lite 0.9.3 → 0.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/osm2geojson-lite.js +1 -1
- package/lib/osmobjs.js +3 -3
- package/osm2geojson-lite +2 -1
- package/package.json +1 -1
package/dist/osm2geojson-lite.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).osm2geojson=e()}(function(){return function r(n,i,o){function a(t,e){if(!i[t]){if(!n[t]){var s="function"==typeof require&&require;if(!e&&s)return s(t,!0);if(l)return l(t,!0);throw(s=new Error("Cannot find module '"+t+"'")).code="MODULE_NOT_FOUND",s}s=i[t]={exports:{}},n[t][0].call(s.exports,function(e){return a(n[t][1][e]||e)},s,s.exports,r,n,i,o)}return i[t].exports}for(var l="function"==typeof require&&require,e=0;e<o.length;e++)a(o[e]);return a}({1:[function(e,t,s){const{Node:h,Way:u,Relation:f}=e("./osmobjs.js"),{purgeProps:p,RefElements:g}=e("./utils.js"),c=e("./xmlparser.js");t.exports=(e,t)=>{let s=!1,r=!1,n=!0;(t=t)&&(s=!(!t.completeFeature&&!t.allFeatures),r=!!t.renderTagged,void 0===(t=t.suppressWay||t.excludeWay)||t||(n=!1));let i=(t=e).elements?"json":0<=t.indexOf("<osm")?"xml":t.trim().startsWith("{")?"json-raw":"invalid",a=new g,o=[];var l;"json-raw"===i&&(e=JSON.parse(e),i=e.elements?"json":"invalid"),"json"===i?(e=>{for(var r of e.elements)switch(r.type){case"node":let e=new h(r.id,a);r.tags&&e.addTags(r.tags),e.addProps(p(r,["id","type","tags","lat","lon"])),e.setLatLng(r);break;case"way":let t=new u(r.id,a);if(r.tags&&t.addTags(r.tags),t.addProps(p(r,["id","type","tags","nodes","geometry"])),r.nodes)for(var n of r.nodes)t.addNodeRef(n);else r.geometry&&t.setLatLngArray(r.geometry);break;case"relation":let s=new f(r.id,a);if(r.bounds&&s.setBounds([parseFloat(r.bounds.minlon),parseFloat(r.bounds.minlat),parseFloat(r.bounds.maxlon),parseFloat(r.bounds.maxlat)]),r.tags&&s.addTags(r.tags),s.addProps(p(r,["id","type","tags","bounds","members"])),r.members)for(var i of r.members)s.addMember(i)}})(e):"xml"===i&&(e=>{const t=new c({progressive:!0});t.on("</osm.node>",e=>{let t=new h(e.id,a);for(var[s,r]of Object.entries(e))!s.startsWith("$")&&["id","lon","lat"].indexOf(s)<0&&t.addProp(s,r);if(t.setLatLng(e),e.$innerNodes)for(var n of e.$innerNodes)"tag"===n.$tag&&t.addTag(n.k,n.v)}),t.on("</osm.way>",e=>{let t=new u(e.id,a);for(var[s,r]of Object.entries(e))!s.startsWith("$")&&["id"].indexOf(s)<0&&t.addProp(s,r);if(e.$innerNodes)for(var n of e.$innerNodes)"nd"===n.$tag?n.lon&&n.lat?t.addLatLng(n):n.ref&&t.addNodeRef(n.ref):"tag"===n.$tag&&t.addTag(n.k,n.v)}),t.on("<osm.relation>",e=>{new f(e.id,a)}),t.on("</osm.relation.member>",(s,e)=>{let t=a.get("relation/"+e.id),r={type:s.type,role:s.role||"",ref:s.ref};if(s.lat&&s.lon){r.lat=s.lat,r.lon=s.lon,r.tags={};for(var[n,i]of Object.entries(s))!n.startsWith("$")&&["type","lat","lon"].indexOf(n)<0&&(r[n]=i)}if(s.$innerNodes){let e=[],t=[];for(var o of s.$innerNodes)o.lat&&o.lon?e.push(o):t.push(o.ref);0<e.length?r.geometry=e:0<t.length&&(r.nodes=t)}t.addMember(r)}),t.on("</osm.relation.bounds>",(e,t)=>{a.get("relation/"+t.id).setBounds([parseFloat(e.minlon),parseFloat(e.minlat),parseFloat(e.maxlon),parseFloat(e.maxlat)])}),t.on("</osm.relation.tag>",(e,t)=>{a.get("relation/"+t.id).addTag(e.k,e.v)}),t.parse(e)})(e),a.bindAll();for(l of a.values())if(l.refCount<=0||l.hasTag&&r&&!(l instanceof u&&n)){var d=l.toFeatureArray();if(l instanceof f&&!s&&0<d.length)return d[0].geometry;o=o.concat(d)}return{type:"FeatureCollection",features:o}}},{"./osmobjs.js":2,"./utils.js":4,"./xmlparser.js":5}],2:[function(t,e,s){e.exports=(()=>{"use strict";const{first:p,isRing:s,ringDirection:r,ptInsidePolygon:g,strToFloat:n,LateBinder:l,WayCollection:c}=t("./utils.js"),i=t("./polytags.json");class e{constructor(e,t,s){this.type=e,this.id=t,this.refElems=s,this.tags={},this.props={id:this.getCompositeId()},this.refCount=0,this.hasTag=!1,s&&s.add(this.getCompositeId(),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)}toFeatureArray(){return[]}}class d extends e{constructor(e,t){super("node",e,t),this.latLng=null}setLatLng(e){this.latLng=e}toFeatureArray(){return this.latLng?[{type:"Feature",id:this.getCompositeId(),properties:this.getProps(),geometry:{type:"Point",coordinates:n([this.latLng.lon,this.latLng.lat])}}]:[]}getLatLng(){return this.latLng}}class h extends e{constructor(e,t){super("way",e,t),this.latLngArray=[],this.isPolygon=!1}addLatLng(e){this.latLngArray.push(e)}setLatLngArray(e){this.latLngArray=e}addNodeRef(e){e=new l(this.latLngArray,function(e){let t=this.refElems.get("node/"+e);if(t)return t.refCount++,t.getLatLng()},this,[e]);this.latLngArray.push(e),this.refElems.addBinder(e)}analyzeTag(e,t){let s=i[e];s&&(this.isPolygon=!0,s.whitelist?this.isPolygon=0<=s.whitelist.indexOf(t):s.blacklist&&(this.isPolygon=!(0<=s.blacklist.indexOf(t))))}addTags(e){super.addTags(e);for(var[t,s]of Object.entries(e))this.analyzeTag(t,s)}addTag(e,t){super.addTag(e,t),this.analyzeTag(e,t)}toCoordsArray(){return this.latLngArray.map(e=>[e.lon,e.lat])}toFeatureArray(){let t=this.toCoordsArray();if(1<t.length){t=n(t);let e={type:"Feature",id:this.getCompositeId(),properties:this.getProps(),geometry:{type:"LineString",coordinates:t}};return this.isPolygon&&s(t)?("counterclockwise"!==r(t)&&t.reverse(),e.geometry={type:"Polygon",coordinates:[t]},[e]):[e]}return[]}}return{Node:d,Way:h,Relation:class extends e{constructor(e,t){super("relation",e,t),this.relations=[],this.nodes=[],this.bounds=null}setBounds(e){this.bounds=e}addMember(s){switch(s.type){case"relation":var r=new l(this.relations,function(e){let t=this.refElems.get("relation/"+e);if(t)return t.refCount++,t},this,[s.ref]);this.relations.push(r),this.refElems.addBinder(r);break;case"way":s.role||(s.role="");let t=this[s.role];if(t=t||(this[s.role]=[]),s.geometry){let e=new h(s.ref,this.refElems);e.setLatLngArray(s.geometry),e.refCount++,t.push(e)}else if(s.nodes){let e=new h(s.ref,this.refElems);for(var n of s.nodes)e.addNodeRef(n);e.refCount++,t.push(e)}else{var i=new l(t,function(e){let t=this.refElems.get("way/"+e);if(t)return t.refCount++,t},this,[s.ref]);t.push(i),this.refElems.addBinder(i)}break;case"node":let e=null;if(s.lat&&s.lon){e=new d(s.ref,this.refElems),e.setLatLng({lon:s.lon,lat:s.lat}),s.tags&&e.addTags(s.tags);for(var[o,a]of Object.entries(s))["id","type","lat","lon"].indexOf(o)<0&&e.addProp(o,a);e.refCount++,this.nodes.push(e)}else{i=new l(this.nodes,function(e){let t=this.refElems.get("node/"+e);if(t)return t.refCount++,t},this,[s.ref]);this.nodes.push(i),this.refElems.addBinder(i)}}}toFeatureArray(){let e=[],t=[],s=[];var r,n,i,o=["outer","inner",""];for(r of this.relations)if(r)for(var a of o){var l=r[a];if(l){let e=this[a];e?[].splice.apply(e,[e.length,0].concat(l)):this[a]=l}}for(n of o){var d=this[n];if(d){this[n]=new c;for(var h of d)this[n].addWay(h)}}let u=null,f={type:"Feature",id:this.getCompositeId(),bbox:this.bounds,properties:this.getProps()};this.bounds||delete f.bbox,this.outer?(u=((e,t)=>{let s=e?e.toRings("counterclockwise"):[],r=t?t.toRings("clockwise"):[];if(0<s.length){let e=[],t=null;for(t of s)e.push([t]);for(;t=r.shift();)for(var n in s)if(g(p(t),s[n])){e[n].push(t);break}return 1===e.length?{type:"Polygon",coordinates:e[0]}:{type:"MultiPolygon",coordinates:e}}return null})(this.outer,this.inner),u&&(f.geometry=u,e.push(f))):this[""]&&(u=(e=>{e=e?e.toStrings():[];return 0<e.length?1===e.length?{type:"LineString",coordinates:e[0]}:{type:"MultiLineString",coordinates:e}:null})(this[""]),u&&(f.geometry=u,t.push(f)));for(i of this.nodes)s=s.concat(i.toFeatureArray());return e.concat(t).concat(s)}}}})()},{"./polytags.json":3,"./utils.js":4}],3:[function(e,t,s){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,s){t.exports=(()=>{"use strict";const e=e=>e[0],n=e=>e[e.length-1],i=e=>e.join(","),t=(e,t,s)=>{let r=e[t];r?r.push(s):e[t]=[s]},o=(e,t,s)=>{let r=e[t],n=null;r&&0<=(n=r.indexOf(s))&&r.splice(n,1)},a=(e,t)=>{t=e[t];return t&&0<t.length?t[0]:null},l=e=>3<e.length&&i(e[0])===i(n(e)),d=(r,n,e)=>{n=n||0,e=e||1;var t=r.reduce((e,t,s)=>r[e][n]>t[n]?e:s,0),s=t<=0?r.length-2:t-1,i=t>=r.length-1?1:t+1,o=r[s][n],a=r[t][n],l=r[i][n],s=r[s][e],t=r[t][e];return(a-o)*(r[i][e]-s)-(l-o)*(t-s)<0?"clockwise":"counterclockwise"};const h=e=>e instanceof Array?e.map(h):parseFloat(e);class s extends Map{constructor(){super(),this.binders=[]}add(e,t){this.has(e)||this.set(e,t)}addBinder(e){this.binders.push(e)}bindAll(){this.binders.forEach(e=>e.bind())}}class r extends Array{constructor(){super(),this.firstMap={},this.lastMap={}}addWay(e){0<(e=e.toCoordsArray()).length&&(this.push(e),t(this.firstMap,i(e[0]),e),t(this.lastMap,i(n(e)),e))}toStrings(){let e=[],t;for(;t=this.shift();){o(this.firstMap,i(t[0]),t),o(this.lastMap,i(n(t)),t);let s=t,r=null;do{let e=i(n(s)),t=!1;r=a(this.firstMap,e),r||(r=a(this.lastMap,e),t=!0),r&&(this.splice(this.indexOf(r),1),o(this.firstMap,i(r[0]),r),o(this.lastMap,i(n(r)),r),t&&(r.length>s.length&&([s,r]=[r,s]),r.reverse()),s=s.concat(r.slice(1)))}while(r);e.push(h(s))}return e}toRings(e){let t=this.toStrings(),s=[],r=null;for(;r=t.shift();)l(r)&&(d(r)!==e&&r.reverse(),s.push(r));return s}}return{purgeProps:(t,s)=>{if(t){let e=Object.assign({},t);if(s)for(var r of s)delete e[r];return e}return{}},mergeProps:(e,t)=>(e=e||{},t=t||{},Object.assign(e,t)),first:e,last:n,coordsToKey:i,addToMap:t,removeFromMap:o,getFirstFromMap:a,isRing:l,ringDirection:d,ptInsidePolygon:(s,r,n,i)=>{n=n||0,i=i||1;let o=!1;for(let e=0,t=r.length-1;e<r.length;t=e++)(r[e][n]<=s[n]&&s[n]<r[t][n]||r[t][n]<=s[n]&&s[n]<r[e][n])&&s[i]<(r[t][i]-r[e][i])*(s[n]-r[e][n])/(r[t][n]-r[e][n])+r[e][i]&&(o=!o);return o},strToFloat:h,RefElements:s,LateBinder:class{constructor(e,t,s,r){this.container=e,this.valueFunc=t,this.ctx=s,this.args=r}bind(){var t=this.valueFunc.apply(this.ctx,this.args);if(this.container instanceof Array){var s=this.container.indexOf(this);if(0<=s){let e=[s,1];t&&e.push(t),[].splice.apply(this.container,e)}}else"object"!=typeof this.container||(s=Object.keys(this.container).find(e=>this.container[e]===this))&&(t?this.container[s]=t:delete this.container[s])}},WayCollection:r}})()},{}],5:[function(e,t,s){t.exports=(()=>{"use strict";function r(e){return null!=e.match(/^(.+?)\[(.+?)\]>$/g)}function n(e){var 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(d,h,u){u=u?u+".":"";let f=/<([^ >\/]+)(.*?)>/gm,p=null,g=[];for(;p=f.exec(d);){let t=p[1],s={$tag:t},r=u+t,e=p[2].trim(),n=!1;(e.endsWith("/")||t.startsWith("?")||t.startsWith("!"))&&(n=!0);let i=/([^ ]+?)="(.+?)"/g,o=/([^ ]+?)='(.+?)'/g,a=null,l=!1;for(;a=i.exec(e);)l=!0,s[a[1]]=a[2];if(!l)for(;a=o.exec(e);)l=!0,s[a[1]]=a[2];if(l||""===e||(s.text=e),this.progressive&&this.emit(`<${r}>`,s,h),!n){let e=new RegExp(`([^]+?)</${t}>`,"g");e.lastIndex=f.lastIndex;var c,y=e.exec(d);y&&y[1]&&(f.lastIndex=e.lastIndex,0<(c=this.parse(y[1],s,r)).length?s.$innerNodes=c:s.$innerText=y[1])}this.queryParent&&h&&this.parentMap.set(s,h),this.progressive&&this.emit(`</${r}>`,s,h),g.push(s)}return g}getParent(e){return this.queryParent?this.parentMap.get(e):null}$addListener(e,t){let s=this.evtListeners[e];s?s.push(t):this.evtListeners[e]=[t]}addListener(e,t){var s;r(e)&&(e=n(e),t.condition=(s="return "+(s=e.exp).replace(/(\$.+?)(?=[=!.])/g,"node.$&")+";",new Function("node",s)),e=e.evt),this.$addListener(e,t)}$removeListener(e,t){let s=this.evtListeners[e],r=null;s&&0<=(r=s.indexOf(t))&&s.splice(r,1)}removeListener(e,t){r(e)&&(e=(e=n(e)).evt),this.$removeListener(e,t)}emit(e,...t){e=this.evtListeners[e];if(e)for(var s of e)(!s.condition||!0===s.condition.apply(null,t))&&s.apply(null,t)}on(e,t){this.addListener(e,t)}off(e,t){this.removeListener(e,t)}}})()},{}]},{},[1])(1)});
|
|
1
|
+
!function(e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).osm2geojson=e()}(function(){return function r(n,i,o){function a(t,e){if(!i[t]){if(!n[t]){var s="function"==typeof require&&require;if(!e&&s)return s(t,!0);if(l)return l(t,!0);throw(s=new Error("Cannot find module '"+t+"'")).code="MODULE_NOT_FOUND",s}s=i[t]={exports:{}},n[t][0].call(s.exports,function(e){return a(n[t][1][e]||e)},s,s.exports,r,n,i,o)}return i[t].exports}for(var l="function"==typeof require&&require,e=0;e<o.length;e++)a(o[e]);return a}({1:[function(e,t,s){const{Node:h,Way:u,Relation:f}=e("./osmobjs.js"),{purgeProps:p,RefElements:g}=e("./utils.js"),c=e("./xmlparser.js");t.exports=(e,t)=>{let s=!1,r=!1,n=!0;(t=t)&&(s=!(!t.completeFeature&&!t.allFeatures),r=!!t.renderTagged,void 0===(t=t.suppressWay||t.excludeWay)||t||(n=!1));let i=(t=e).elements?"json":0<=t.indexOf("<osm")?"xml":t.trim().startsWith("{")?"json-raw":"invalid",a=new g,o=[];var l;"json-raw"===i&&(e=JSON.parse(e),i=e.elements?"json":"invalid"),"json"===i?(e=>{for(var r of e.elements)switch(r.type){case"node":let e=new h(r.id,a);r.tags&&e.addTags(r.tags),e.addProps(p(r,["id","type","tags","lat","lon"])),e.setLatLng(r);break;case"way":let t=new u(r.id,a);if(r.tags&&t.addTags(r.tags),t.addProps(p(r,["id","type","tags","nodes","geometry"])),r.nodes)for(var n of r.nodes)t.addNodeRef(n);else r.geometry&&t.setLatLngArray(r.geometry);break;case"relation":let s=new f(r.id,a);if(r.bounds&&s.setBounds([parseFloat(r.bounds.minlon),parseFloat(r.bounds.minlat),parseFloat(r.bounds.maxlon),parseFloat(r.bounds.maxlat)]),r.tags&&s.addTags(r.tags),s.addProps(p(r,["id","type","tags","bounds","members"])),r.members)for(var i of r.members)s.addMember(i)}})(e):"xml"===i&&(e=>{const t=new c({progressive:!0});t.on("</osm.node>",e=>{let t=new h(e.id,a);for(var[s,r]of Object.entries(e))!s.startsWith("$")&&["id","lon","lat"].indexOf(s)<0&&t.addProp(s,r);if(t.setLatLng(e),e.$innerNodes)for(var n of e.$innerNodes)"tag"===n.$tag&&t.addTag(n.k,n.v)}),t.on("</osm.way>",e=>{let t=new u(e.id,a);for(var[s,r]of Object.entries(e))!s.startsWith("$")&&["id"].indexOf(s)<0&&t.addProp(s,r);if(e.$innerNodes)for(var n of e.$innerNodes)"nd"===n.$tag?n.lon&&n.lat?t.addLatLng(n):n.ref&&t.addNodeRef(n.ref):"tag"===n.$tag&&t.addTag(n.k,n.v)}),t.on("<osm.relation>",e=>{new f(e.id,a)}),t.on("</osm.relation.member>",(s,e)=>{let t=a.get("relation/"+e.id),r={type:s.type,role:s.role||"",ref:s.ref};if(s.lat&&s.lon){r.lat=s.lat,r.lon=s.lon,r.tags={};for(var[n,i]of Object.entries(s))!n.startsWith("$")&&["type","lat","lon"].indexOf(n)<0&&(r[n]=i)}if(s.$innerNodes){let e=[],t=[];for(var o of s.$innerNodes)o.lat&&o.lon?e.push(o):t.push(o.ref);0<e.length?r.geometry=e:0<t.length&&(r.nodes=t)}t.addMember(r)}),t.on("</osm.relation.bounds>",(e,t)=>{a.get("relation/"+t.id).setBounds([parseFloat(e.minlon),parseFloat(e.minlat),parseFloat(e.maxlon),parseFloat(e.maxlat)])}),t.on("</osm.relation.tag>",(e,t)=>{a.get("relation/"+t.id).addTag(e.k,e.v)}),t.parse(e)})(e),a.bindAll();for(l of a.values())if(l.refCount<=0||l.hasTag&&r&&!(l instanceof u&&n)){var d=l.toFeatureArray();if(l instanceof f&&!s&&0<d.length)return d[0].geometry;o=o.concat(d)}return{type:"FeatureCollection",features:o}}},{"./osmobjs.js":2,"./utils.js":4,"./xmlparser.js":5}],2:[function(t,e,s){e.exports=(()=>{"use strict";const{first:p,isRing:s,ringDirection:r,ptInsidePolygon:g,strToFloat:n,LateBinder:l,WayCollection:c}=t("./utils.js"),i=t("./polytags.json");class e{constructor(e,t,s){this.type=e,this.id=t,this.refElems=s,this.tags={},this.props={id:this.getCompositeId()},this.refCount=0,this.hasTag=!1,s&&s.add(this.getCompositeId(),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)}toFeatureArray(){return[]}}class d extends e{constructor(e,t){super("node",e,t),this.latLng=null}setLatLng(e){this.latLng=e}toFeatureArray(){return this.latLng?[{type:"Feature",id:this.getCompositeId(),properties:this.getProps(),geometry:{type:"Point",coordinates:n([this.latLng.lon,this.latLng.lat])}}]:[]}getLatLng(){return this.latLng}}class h extends e{constructor(e,t){super("way",e,t),this.latLngArray=[],this.isPolygon=!1}addLatLng(e){this.latLngArray.push(e)}setLatLngArray(e){this.latLngArray=e}addNodeRef(e){e=new l(this.latLngArray,function(e){let t=this.refElems.get("node/"+e);if(t)return t.refCount++,t.getLatLng()},this,[e]);this.latLngArray.push(e),this.refElems.addBinder(e)}analyzeGeometryType(e,t){let s=i[e];s&&(this.isPolygon=!0,s.whitelist?this.isPolygon=0<=s.whitelist.indexOf(t):s.blacklist&&(this.isPolygon=!(0<=s.blacklist.indexOf(t))))}addTags(e){super.addTags(e);for(var[t,s]of Object.entries(e))this.analyzeGeometryType(t,s)}addTag(e,t){super.addTag(e,t),this.analyzeGeometryType(e,t)}toCoordsArray(){return this.latLngArray.map(e=>[e.lon,e.lat])}toFeatureArray(){let t=this.toCoordsArray();if(1<t.length){t=n(t);let e={type:"Feature",id:this.getCompositeId(),properties:this.getProps(),geometry:{type:"LineString",coordinates:t}};return this.isPolygon&&s(t)?("counterclockwise"!==r(t)&&t.reverse(),e.geometry={type:"Polygon",coordinates:[t]},[e]):[e]}return[]}}return{Node:d,Way:h,Relation:class extends e{constructor(e,t){super("relation",e,t),this.relations=[],this.nodes=[],this.bounds=null}setBounds(e){this.bounds=e}addMember(s){switch(s.type){case"relation":var r=new l(this.relations,function(e){let t=this.refElems.get("relation/"+e);if(t)return t.refCount++,t},this,[s.ref]);this.relations.push(r),this.refElems.addBinder(r);break;case"way":s.role||(s.role="");let t=this[s.role];if(t=t||(this[s.role]=[]),s.geometry){let e=new h(s.ref,this.refElems);e.setLatLngArray(s.geometry),e.refCount++,t.push(e)}else if(s.nodes){let e=new h(s.ref,this.refElems);for(var n of s.nodes)e.addNodeRef(n);e.refCount++,t.push(e)}else{var i=new l(t,function(e){let t=this.refElems.get("way/"+e);if(t)return t.refCount++,t},this,[s.ref]);t.push(i),this.refElems.addBinder(i)}break;case"node":let e=null;if(s.lat&&s.lon){e=new d(s.ref,this.refElems),e.setLatLng({lon:s.lon,lat:s.lat}),s.tags&&e.addTags(s.tags);for(var[o,a]of Object.entries(s))["id","type","lat","lon"].indexOf(o)<0&&e.addProp(o,a);e.refCount++,this.nodes.push(e)}else{i=new l(this.nodes,function(e){let t=this.refElems.get("node/"+e);if(t)return t.refCount++,t},this,[s.ref]);this.nodes.push(i),this.refElems.addBinder(i)}}}toFeatureArray(){let e=[],t=[],s=[];var r,n,i,o=["outer","inner",""];for(r of this.relations)if(r)for(var a of o){var l=r[a];if(l){let e=this[a];e?[].splice.apply(e,[e.length,0].concat(l)):this[a]=l}}for(n of o){var d=this[n];if(d){this[n]=new c;for(var h of d)this[n].addWay(h)}}let u=null,f={type:"Feature",id:this.getCompositeId(),bbox:this.bounds,properties:this.getProps()};this.bounds||delete f.bbox,this.outer?(u=((e,t)=>{let s=e?e.toRings("counterclockwise"):[],r=t?t.toRings("clockwise"):[];if(0<s.length){let e=[],t=null;for(t of s)e.push([t]);for(;t=r.shift();)for(var n in s)if(g(p(t),s[n])){e[n].push(t);break}return 1===e.length?{type:"Polygon",coordinates:e[0]}:{type:"MultiPolygon",coordinates:e}}return null})(this.outer,this.inner),u&&(f.geometry=u,e.push(f))):this[""]&&(u=(e=>{e=e?e.toStrings():[];return 0<e.length?1===e.length?{type:"LineString",coordinates:e[0]}:{type:"MultiLineString",coordinates:e}:null})(this[""]),u&&(f.geometry=u,t.push(f)));for(i of this.nodes)s=s.concat(i.toFeatureArray());return e.concat(t).concat(s)}}}})()},{"./polytags.json":3,"./utils.js":4}],3:[function(e,t,s){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,s){t.exports=(()=>{"use strict";const e=e=>e[0],n=e=>e[e.length-1],i=e=>e.join(","),t=(e,t,s)=>{let r=e[t];r?r.push(s):e[t]=[s]},o=(e,t,s)=>{let r=e[t],n=null;r&&0<=(n=r.indexOf(s))&&r.splice(n,1)},a=(e,t)=>{t=e[t];return t&&0<t.length?t[0]:null},l=e=>3<e.length&&i(e[0])===i(n(e)),d=(r,n,e)=>{n=n||0,e=e||1;var t=r.reduce((e,t,s)=>r[e][n]>t[n]?e:s,0),s=t<=0?r.length-2:t-1,i=t>=r.length-1?1:t+1,o=r[s][n],a=r[t][n],l=r[i][n],s=r[s][e],t=r[t][e];return(a-o)*(r[i][e]-s)-(l-o)*(t-s)<0?"clockwise":"counterclockwise"};const h=e=>e instanceof Array?e.map(h):parseFloat(e);class s extends Map{constructor(){super(),this.binders=[]}add(e,t){this.has(e)||this.set(e,t)}addBinder(e){this.binders.push(e)}bindAll(){this.binders.forEach(e=>e.bind())}}class r extends Array{constructor(){super(),this.firstMap={},this.lastMap={}}addWay(e){0<(e=e.toCoordsArray()).length&&(this.push(e),t(this.firstMap,i(e[0]),e),t(this.lastMap,i(n(e)),e))}toStrings(){let e=[],t;for(;t=this.shift();){o(this.firstMap,i(t[0]),t),o(this.lastMap,i(n(t)),t);let s=t,r=null;do{let e=i(n(s)),t=!1;r=a(this.firstMap,e),r||(r=a(this.lastMap,e),t=!0),r&&(this.splice(this.indexOf(r),1),o(this.firstMap,i(r[0]),r),o(this.lastMap,i(n(r)),r),t&&(r.length>s.length&&([s,r]=[r,s]),r.reverse()),s=s.concat(r.slice(1)))}while(r);e.push(h(s))}return e}toRings(e){let t=this.toStrings(),s=[],r=null;for(;r=t.shift();)l(r)&&(d(r)!==e&&r.reverse(),s.push(r));return s}}return{purgeProps:(t,s)=>{if(t){let e=Object.assign({},t);if(s)for(var r of s)delete e[r];return e}return{}},mergeProps:(e,t)=>(e=e||{},t=t||{},Object.assign(e,t)),first:e,last:n,coordsToKey:i,addToMap:t,removeFromMap:o,getFirstFromMap:a,isRing:l,ringDirection:d,ptInsidePolygon:(s,r,n,i)=>{n=n||0,i=i||1;let o=!1;for(let e=0,t=r.length-1;e<r.length;t=e++)(r[e][n]<=s[n]&&s[n]<r[t][n]||r[t][n]<=s[n]&&s[n]<r[e][n])&&s[i]<(r[t][i]-r[e][i])*(s[n]-r[e][n])/(r[t][n]-r[e][n])+r[e][i]&&(o=!o);return o},strToFloat:h,RefElements:s,LateBinder:class{constructor(e,t,s,r){this.container=e,this.valueFunc=t,this.ctx=s,this.args=r}bind(){var t=this.valueFunc.apply(this.ctx,this.args);if(this.container instanceof Array){var s=this.container.indexOf(this);if(0<=s){let e=[s,1];t&&e.push(t),[].splice.apply(this.container,e)}}else"object"!=typeof this.container||(s=Object.keys(this.container).find(e=>this.container[e]===this))&&(t?this.container[s]=t:delete this.container[s])}},WayCollection:r}})()},{}],5:[function(e,t,s){t.exports=(()=>{"use strict";function r(e){return null!=e.match(/^(.+?)\[(.+?)\]>$/g)}function n(e){var 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(d,h,u){u=u?u+".":"";let f=/<([^ >\/]+)(.*?)>/gm,p=null,g=[];for(;p=f.exec(d);){let t=p[1],s={$tag:t},r=u+t,e=p[2].trim(),n=!1;(e.endsWith("/")||t.startsWith("?")||t.startsWith("!"))&&(n=!0);let i=/([^ ]+?)="(.+?)"/g,o=/([^ ]+?)='(.+?)'/g,a=null,l=!1;for(;a=i.exec(e);)l=!0,s[a[1]]=a[2];if(!l)for(;a=o.exec(e);)l=!0,s[a[1]]=a[2];if(l||""===e||(s.text=e),this.progressive&&this.emit(`<${r}>`,s,h),!n){let e=new RegExp(`([^]+?)</${t}>`,"g");e.lastIndex=f.lastIndex;var c,y=e.exec(d);y&&y[1]&&(f.lastIndex=e.lastIndex,0<(c=this.parse(y[1],s,r)).length?s.$innerNodes=c:s.$innerText=y[1])}this.queryParent&&h&&this.parentMap.set(s,h),this.progressive&&this.emit(`</${r}>`,s,h),g.push(s)}return g}getParent(e){return this.queryParent?this.parentMap.get(e):null}#addListener(e,t){let s=this.evtListeners[e];s?s.push(t):this.evtListeners[e]=[t]}addListener(e,t){var s;r(e)&&(e=n(e),t.condition=(s="return "+(s=e.exp).replace(/(\$.+?)(?=[=!.])/g,"node.$&")+";",new Function("node",s)),e=e.evt),this.#addListener(e,t)}#removeListener(e,t){let s=this.evtListeners[e],r=null;s&&0<=(r=s.indexOf(t))&&s.splice(r,1)}removeListener(e,t){r(e)&&(e=(e=n(e)).evt),this.#removeListener(e,t)}emit(e,...t){e=this.evtListeners[e];if(e)for(var s of e)(!s.condition||!0===s.condition.apply(null,t))&&s.apply(null,t)}on(e,t){this.addListener(e,t)}off(e,t){this.removeListener(e,t)}}})()},{}]},{},[1])(1)});
|
package/lib/osmobjs.js
CHANGED
|
@@ -111,7 +111,7 @@ module.exports = (() => {
|
|
|
111
111
|
this.refElems.addBinder(binder);
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
|
|
114
|
+
analyzeGeometryType(k, v) {
|
|
115
115
|
let o = polygonTags[k];
|
|
116
116
|
if (o) {
|
|
117
117
|
this.isPolygon = true;
|
|
@@ -126,13 +126,13 @@ module.exports = (() => {
|
|
|
126
126
|
addTags(tags) {
|
|
127
127
|
super.addTags(tags);
|
|
128
128
|
for (let [k, v] of Object.entries(tags)) {
|
|
129
|
-
this.
|
|
129
|
+
this.analyzeGeometryType(k, v);
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
addTag(k, v) {
|
|
134
134
|
super.addTag(k, v);
|
|
135
|
-
this.
|
|
135
|
+
this.analyzeGeometryType(k, v);
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
toCoordsArray() {
|
package/osm2geojson-lite
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const osm2geojson = require('./lib/index.js');
|
|
4
|
+
const fs = require('fs');
|
|
4
5
|
|
|
5
6
|
const data = fs.readFileSync("/dev/stdin", "utf-8");
|
|
6
|
-
const geojson = osm2geojson(data, {});
|
|
7
|
+
const geojson = osm2geojson(data, {completeFeature: true, renderTagged: true});
|
|
7
8
|
console.log(JSON.stringify(geojson));
|