osm2geojson-lite 0.9.4 → 1.0.0
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/package.json +15 -8
- package/ts/release/index.d.ts +12 -0
- package/ts/release/index.js +14 -10
- package/ts/release/osmobjs.d.ts +73 -0
- package/ts/release/osmobjs.js +50 -21
- package/ts/release/utils.d.ts +60 -0
- package/ts/release/utils.js +40 -31
- package/ts/release/xmlparser.d.ts +32 -0
- package/ts/release/xmlparser.js +3 -0
- package/Makefile +0 -2
- package/bench/data/hebei.json +0 -10748
- package/bench/data/hebei.osm +0 -8764
- package/bench/data/tokyodo.json +0 -17113
- package/bench/data/tokyodo.osm +0 -15588
- package/bench/data/usa.json +0 -135488
- package/bench/data/usa.osm +0 -131346
- package/bench/data/zhucheng.json +0 -781
- package/bench/data/zhucheng.osm +0 -724
- package/bench/o2gl-bench.js +0 -31
- package/bench/otg-bench.js +0 -32
- package/bench/package-lock.json +0 -598
- package/bench/package.json +0 -15
- package/bower.json +0 -32
- package/index.html +0 -270
- package/lib/index.d.ts +0 -21
- package/lib/index.js +0 -205
- package/lib/osmobjs.js +0 -391
- package/lib/utils.js +0 -227
- package/lib/xmlparser.js +0 -157
- package/test/data/empty.json +0 -3
- package/test/data/empty.osm +0 -1
- package/test/data/hebei.osm +0 -8764
- package/test/data/herne.json +0 -1613
- package/test/data/map.json +0 -1586
- package/test/data/map.osm +0 -428
- package/test/data/node.json +0 -10
- package/test/data/node.osm +0 -3
- package/test/data/original.osm +0 -1449
- package/test/data/relation.json +0 -89
- package/test/data/relation.osm +0 -28
- package/test/data/tokyodo.osm +0 -15588
- package/test/data/usa.osm +0 -131346
- package/test/data/way.json +0 -31
- package/test/data/way.osm +0 -10
- package/test/data/zhucheng.osm +0 -724
- package/test/osm2geojson +0 -43
- package/test/package.json +0 -11
- package/test/test.js +0 -20
- package/ts/src/index.d.ts +0 -17
- package/ts/src/index.ts +0 -220
- package/ts/src/osmobjs.ts +0 -413
- package/ts/src/polytags.json +0 -84
- package/ts/src/typings.d.ts +0 -4
- package/ts/src/utils.ts +0 -235
- package/ts/src/xmlparser.ts +0 -181
- package/ts/tsconfig.json +0 -23
- package/ts/tslint.json +0 -24
- package/ts/types/imports.d.ts +0 -1
- /package/{lib → ts/release}/polytags.json +0 -0
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)}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)});
|
|
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 s(i,o,n){function a(t,e){if(!o[t]){if(!i[t]){var r="function"==typeof require&&require;if(!e&&r)return r(t,!0);if(l)return l(t,!0);throw(e=new Error("Cannot find module '"+t+"'")).code="MODULE_NOT_FOUND",e}r=o[t]={exports:{}},i[t][0].call(r.exports,function(e){return a(i[t][1][e]||e)},r,r.exports,s,i,o,n)}return o[t].exports}for(var l="function"==typeof require&&require,e=0;e<n.length;e++)a(n[e]);return a}({1:[function(e,t,r){let s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}},f=e("./osmobjs"),u=e("./utils"),p=s(e("./xmlparser"));t.exports=function(n,e){let t=!1,r=!1,s=!0,i=(e&&(e=e)&&(t=!(!e.completeFeature&&!e.allFeatures),r=!!e.renderTagged,void 0===(e=e.suppressWay||e.excludeWay)||e||(s=!1)),(e=n).elements?"json":0<=e.indexOf("<osm")?"xml":e.trim().startsWith("{")?"json-raw":"invalid"),l=new u.RefElements,o=[];var a,d;"json-raw"===i&&(n=JSON.parse(n),i=n.elements?"json":"invalid"),"json"===i?(()=>{for(var e of n.elements)switch(e.type){case"node":var t=new f.Node(e.id,l);e.tags&&t.addTags(e.tags),t.addProps((0,u.purgeProps)(e,["id","type","tags","lat","lon"])),t.setLatLng(e);break;case"way":var r=new f.Way(e.id,l);if(e.tags&&r.addTags(e.tags),r.addProps((0,u.purgeProps)(e,["id","type","tags","nodes","geometry"])),e.nodes)for(var s of e.nodes)r.addNodeRef(s);else e.geometry&&r.setLatLngArray(e.geometry);break;case"relation":var i=new f.Relation(e.id,l);if(e.bounds&&i.setBounds([parseFloat(e.bounds.minlon),parseFloat(e.bounds.minlat),parseFloat(e.bounds.maxlon),parseFloat(e.bounds.maxlat)]),e.tags&&i.addTags(e.tags),i.addProps((0,u.purgeProps)(e,["id","type","tags","bounds","members"])),e.members)for(var o of e.members)i.addMember(o)}})():"xml"===i&&(e=n,(a=new p.default({progressive:!0})).on("</osm.node>",e=>{var t,r,s=new f.Node(e.id,l);for([t,r]of Object.entries(e))!t.startsWith("$")&&["id","lon","lat"].indexOf(t)<0&&s.addProp(t,r);if(s.setLatLng(e),e.$innerNodes)for(var i of e.$innerNodes)"tag"===i.$tag&&s.addTag(i.k,i.v)}),a.on("</osm.way>",e=>{var t,r,s=new f.Way(e.id,l);for([t,r]of Object.entries(e))!t.startsWith("$")&&["id"].indexOf(t)<0&&s.addProp(t,r);if(e.$innerNodes)for(var i of e.$innerNodes)"nd"===i.$tag?i.lon&&i.lat?s.addLatLng(i):i.ref&&s.addNodeRef(i.ref):"tag"===i.$tag&&s.addTag(i.k,i.v)}),a.on("<osm.relation>",e=>new f.Relation(e.id,l)),a.on("</osm.relation.member>",(e,t)=>{var t=l.get("relation/"+(null==t?void 0:t.id)),r={type:e.type,role:e.role||"",ref:e.ref};if(e.lat&&e.lon){r.lat=e.lat,r.lon=e.lon,r.tags={};for(var[s,i]of Object.entries(e))!s.startsWith("$")&&["type","lat","lon"].indexOf(s)<0&&(r[s]=i)}if(e.$innerNodes){var o,n=[],a=[];for(o of e.$innerNodes)o.lat&&o.lon?n.push(o):o.ref&&a.push(o.ref);0<n.length?r.geometry=n:0<a.length&&(r.nodes=a)}t.addMember(r)}),a.on("</osm.relation.bounds>",(e,t)=>{l.get("relation/"+(null==t?void 0:t.id)).setBounds([parseFloat(e.minlon),parseFloat(e.minlat),parseFloat(e.maxlon),parseFloat(e.maxlat)])}),a.on("</osm.relation.tag>",(e,t)=>{l.get("relation/"+(null==t?void 0:t.id)).addTag(e.k,e.v)}),a.parse(e)),l.bindAll();for(d of l.values())if(d.refCount<=0||d.hasTag&&r&&!(d instanceof f.Way&&s)){var h=d.toFeatureArray();if(d instanceof f.Relation&&!t&&0<h.length)return h[0].geometry;o=o.concat(h)}return{type:"FeatureCollection",features:o}}},{"./osmobjs":2,"./utils":4,"./xmlparser":5}],2:[function(e,t,r){var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:!0}),r.Relation=r.Way=r.Node=void 0;let w=e("./utils"),L=e("./utils"),i=s(e("./polytags.json"));class o{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(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 l extends o{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:(0,w.strToFloat)([this.latLng.lon,this.latLng.lat])}}]:[]}getLatLng(){return this.latLng}}r.Node=l;class d extends o{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.LateBinder(this.latLngArray,e=>{e=this.refElems.get("node/"+e);if(e)return e.refCount++,e.getLatLng()},this,[e]);this.latLngArray.push(e),this.refElems.addBinder(e)}addTags(e){super.addTags(e);for(var[t,r]of Object.entries(e))this.analyzeTag(t,r)}addTag(e,t){super.addTag(e,t),this.analyzeTag(e,t)}toCoordsArray(){return this.latLngArray.map(e=>[e.lon,e.lat])}toFeatureArray(){var e,t=this.toCoordsArray();return 1<t.length?(t=(0,w.strToFloat)(t),e={type:"Feature",id:this.getCompositeId(),properties:this.getProps(),geometry:{type:"LineString",coordinates:t}},this.isPolygon&&(0,w.isRing)(t)&&("counterclockwise"!==(0,w.ringDirection)(t)&&t.reverse(),e.geometry={type:"Polygon",coordinates:[t]}),[e]):[]}analyzeTag(e,t){e=i.default[e];e&&(this.isPolygon=!0,e.whitelist?this.isPolygon=0<=e.whitelist.indexOf(t):e.blacklist&&(this.isPolygon=!(0<=e.blacklist.indexOf(t))))}}r.Way=d;class n extends o{constructor(e,t){super("relation",e,t),this.relations=[],this.nodes=[],this.bounds=void 0}setBounds(e){this.bounds=e}addMember(t){switch(t.type){case"relation":var r=new L.LateBinder(this.relations,e=>{e=this.refElems.get("relation/"+e);if(e)return e.refCount++,e},this,[t.ref]);this.relations.push(r),this.refElems.addBinder(r);break;case"way":t.role||(t.role="");let e=this[t.role];if(e=e||(this[t.role]=[]),t.geometry){r=new d(t.ref,this.refElems);r.setLatLngArray(t.geometry),r.refCount++,e.push(r)}else if(t.nodes){var s,i=new d(t.ref,this.refElems);for(s of t.nodes)i.addNodeRef(s);i.refCount++,e.push(i)}else{r=new L.LateBinder(e,e=>{e=this.refElems.get("way/"+e);if(e)return e.refCount++,e},this,[t.ref]);e.push(r),this.refElems.addBinder(r)}break;case"node":var o=null;if(t.lat&&t.lon){(o=new l(t.ref,this.refElems)).setLatLng({lon:t.lon,lat:t.lat}),t.tags&&o.addTags(t.tags);for(var[n,a]of Object.entries(t))["id","type","lat","lon"].indexOf(n)<0&&o.addProp(n,a);o.refCount++,this.nodes.push(o)}else{r=new L.LateBinder(this.nodes,e=>{e=this.refElems.get("node/"+e);if(e)return e.refCount++,e},this,[t.ref]);this.nodes.push(r),this.refElems.addBinder(r)}}}toFeatureArray(){var e,t,r=[],s=[];let i=[],o=["type","id","refElems","tags","props","refCount","hasTag","relations","nodes","bounds"];for(e of this.relations)if(e)for(t of Object.keys(e).filter(e=>o.indexOf(e)<0)){var n,a=e[t];a&&((n=this[t])?n.push(...a):this[t]=a)}var l,d=Object.keys(this).filter(e=>o.indexOf(e)<0);for(l of d){var h=this[l];if(h){this[l]=new L.WayCollection;for(var f of h)this[l].addWay(f)}}var u,p={type:"Feature",id:this.getCompositeId(),bbox:this.bounds,properties:this.getProps(),geometry:null};if(this.bounds||delete p.bbox,this.outer){var g=Object.assign({},p),c=((e,t)=>{var r=e?e.toRings("counterclockwise"):[],s=t?t.toRings("clockwise"):[];if(0<r.length){var i=[];let e;for(e of r)i.push([e]);for(e=s.shift();e;){for(var o in r)if((0,w.ptInsidePolygon)((0,w.first)(e),r[o])){i[o].push(e);break}e=s.shift()}return 1===i.length?{type:"Polygon",coordinates:i[0]}:{type:"MultiPolygon",coordinates:i}}return null})(this.outer,this.inner);c&&(g.geometry=c,r.push(g))}else{var y,m,v,b={type:"MultiLineString",coordinates:[]};for(y of d)null!=y&&"inner"!==y&&(m=this[y])&&(m=0<(m=(m=m)?m.toStrings():[]).length?1===m.length?{type:"LineString",coordinates:m[0]}:{type:"MultiLineString",coordinates:m}:null)&&("LineString"===m.type?b.coordinates.push(m.coordinates):"MultiLineString"===m.type&&((v=Object.assign({},p)).geometry=m,s.push(v)));0<b.coordinates.length&&((c=Object.assign({},p)).geometry=b,s.push(c))}for(u of this.nodes)i=i.concat(u.toFeatureArray());return[...r,...s,...i]}}r.Relation=n},{"./polytags.json":3,"./utils":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,o){function i(e,t,r){e.properties&&t&&r&&(e.properties[t]=r)}Object.defineProperty(o,"__esModule",{value:!0}),o.WayCollection=o.RefElements=o.LateBinder=o.strToFloat=o.ptInsidePolygon=o.ringDirection=o.isRing=o.coordsToKey=o.last=o.first=void 0,o.purgeProps=function(e,t){if(e){var r=Object.assign({},e);if(t)for(var s of t)delete r[s];return r}return{}},o.mergeProps=function(e,t){return e=e||{},t=t||{},Object.assign(e,t)},o.addPropToFeature=i,o.addPropToFeatures=function(e,t,r){for(var s of e)i(s,t,r)},o.addToMap=r,o.removeFromMap=n,o.getFirstFromMap=a;o.first=e=>e[0],o.last=e=>e[e.length-1];function r(e,t,r){var s=e[t];s?s.push(r):e[t]=[r]}function n(e,t,r){e=e[t];let s=-1;0<=(s=e?e.indexOf(r):s)&&e.splice(s,1)}function a(e,t){e=e[t];return e&&0<e.length?e[0]:null}o.coordsToKey=e=>e.join(",");o.isRing=e=>3<e.length&&(0,o.coordsToKey)((0,o.first)(e))===(0,o.coordsToKey)((0,o.last)(e)),o.ringDirection=(s,i,e)=>{i=i||0,e=e||1;var t=s.reduce((e,t,r)=>s[e][i||0]>t[i||0]?e:r,0),r=t<=0?s.length-2:t-1,o=t>=s.length-1?1:t+1,n=s[r][i],a=s[t][i],l=s[o][i],r=s[r][e],t=s[t][e];return(a-n)*(s[o][e]-r)-(l-n)*(t-r)<0?"clockwise":"counterclockwise"},o.ptInsidePolygon=(r,s,i,o)=>{i=i||0,o=o||1;let n=!1;for(let e=0,t=s.length-1;e<s.length;t=e++)(s[e][i]<=r[i]&&r[i]<s[t][i]||s[t][i]<=r[i]&&r[i]<s[e][i])&&r[o]<(s[t][o]-s[e][o])*(r[i]-s[e][i])/(s[t][i]-s[e][i])+s[e][o]&&(n=!n);return n};o.strToFloat=e=>e instanceof Array?e.map(o.strToFloat):parseFloat(e);o.LateBinder=class{constructor(e,t,r,s){this.container=e,this.valueFunc=t,this.ctx=r,this.args=s}bind(){var e=this.valueFunc.apply(this.ctx,this.args);if(this.container instanceof Array){var r=this.container.indexOf(this);0<=r&&(r=[r,1],e&&r.push(e),Array.prototype.splice.apply(this.container,r))}else if("object"==typeof this.container&&!Array.isArray(this.container)){let t=this.container;r=Object.keys(t).find(e=>t[e]===this);r&&(e?t[r]=e:delete t[r])}}};class s extends Map{constructor(){super(),this.binders=[]}add(e,t){this.set(e,t)}addBinder(e){this.binders.push(e)}bindAll(){this.binders.forEach(e=>e.bind())}}o.RefElements=s;class l extends Array{constructor(){super(),this.firstMap={},this.lastMap={}}addWay(e){e=e.toCoordsArray();0<e.length&&(this.push(e),r(this.firstMap,(0,o.coordsToKey)((0,o.first)(e)),e),r(this.lastMap,(0,o.coordsToKey)((0,o.last)(e)),e))}toStrings(){var e=[];let s=this.shift();for(;s;){n(this.firstMap,(0,o.coordsToKey)((0,o.first)(s)),s),n(this.lastMap,(0,o.coordsToKey)((0,o.last)(s)),s);let t=s,r;do{var i=(0,o.coordsToKey)((0,o.last)(t));let e=!1;(r=a(this.firstMap,i))||(r=a(this.lastMap,i),e=!0),r&&(this.splice(this.indexOf(r),1),n(this.firstMap,(0,o.coordsToKey)((0,o.first)(r)),r),n(this.lastMap,(0,o.coordsToKey)((0,o.last)(r)),r),e&&(r.length>t.length&&([t,r]=[r,t]),r.reverse()),t=t.concat(r.slice(1)))}while(r);e.push((0,o.strToFloat)(t)),s=this.shift()}return e}toRings(e){var t=this.toStrings(),r=[];let s=t.shift();for(;s;)(0,o.isRing)(s)&&((0,o.ringDirection)(s)!==e&&s.reverse(),r.push(s)),s=t.shift();return r}}o.WayCollection=l},{}],5:[function(e,t,r){function i(e){return null!==e.match(/^(.+?)\[(.+?)\]>$/g)}function o(e){var t=/^(.+?)\[(.+?)\]>$/g.exec(e);return t?{evt:t[1]+">",exp:t[2]}:{evt:e}}Object.defineProperty(r,"__esModule",{value:!0});class s{constructor(e){this.queryParent=!1,this.progressive=!1,this.parentMap=new WeakMap,e&&(this.queryParent=!!e.queryParent,this.progressive=e.progressive,this.queryParent)&&(this.parentMap=new WeakMap),this.evtListeners={}}parse(s,i,o){o=o?o+".":"";var n=/<([^ >\/]+)(.*?)>/gm,a=[];let l=n.exec(s);for(;l;){var d=l[1],h={$tag:d},f=o+d,u=l[2].trim();let e=!1;(u.endsWith("/")||d.startsWith("?")||d.startsWith("!"))&&(e=!0);var p,g=/([^ ]+?)="(.+?)"/g,c=/([^ ]+?)='(.+?)'/g;let t=g.exec(u),r=!1;for(;t;)r=!0,h[t[1]]=t[2],t=g.exec(u);if(!r)for(t=c.exec(u);t;)r=!0,h[t[1]]=t[2],t=c.exec(u);r||""===u||(h.text=u),this.progressive&&this.emit(`<${f}>`,h,i),e||((d=new RegExp(`([^]+?)</${d}>`,"g")).lastIndex=n.lastIndex,(p=d.exec(s))&&p[1]&&(n.lastIndex=d.lastIndex,0<(d=this.parse(p[1],h,f)).length?h.$innerNodes=d:h.$innerText=p[1])),this.queryParent&&i&&this.parentMap.set(h,i),this.progressive&&this.emit(`</${f}>`,h,i),a.push(h),l=n.exec(s)}return a}getParent(e){return this.queryParent?this.parentMap.get(e):null}addListener(e,t){var r,s;i(e)&&((r=o(e)).exp&&(t.condition=(s="return "+(s=r.exp).replace(/(\$.+?)(?=[=!.])/g,"node.$&")+";",new Function("node",s))),e=r.evt),this.$addListener(e,t)}removeListener(e,t){i(e)&&(e=o(e).evt),this.$removeListener(e,t)}on(e,t){this.addListener(e,t)}off(e,t){this.removeListener(e,t)}$addListener(e,t){var r=this.evtListeners[e];r?r.push(t):this.evtListeners[e]=[t]}$removeListener(e,t){e=this.evtListeners[e];let r=-1;0<=(r=e?e.indexOf(t):r)&&e.splice(r,1)}emit(e,...t){e=this.evtListeners[e];if(e)for(var r of e)(!r.condition||!0===r.condition.apply(null,t))&&r.apply(null,t)}}r.default=s},{}]},{},[1])(1)});
|
package/package.json
CHANGED
|
@@ -45,26 +45,33 @@
|
|
|
45
45
|
"multipolygon"
|
|
46
46
|
],
|
|
47
47
|
"license": "ISC",
|
|
48
|
-
"main": "
|
|
48
|
+
"main": "ts/release/index.js",
|
|
49
|
+
"types": "ts/release/index.d.ts",
|
|
49
50
|
"name": "osm2geojson-lite",
|
|
50
51
|
"repository": {
|
|
51
52
|
"type": "git",
|
|
52
53
|
"url": "git+https://github.com/tibetty/osm2geojson-lite.git"
|
|
53
54
|
},
|
|
54
55
|
"scripts": {
|
|
55
|
-
"
|
|
56
|
+
"build": "npm install && make",
|
|
57
|
+
"test": "make test"
|
|
56
58
|
},
|
|
57
59
|
"optionalDependencies": {
|
|
58
|
-
"@types/geojson": "^
|
|
60
|
+
"@types/geojson": "^7946.0.16"
|
|
59
61
|
},
|
|
60
|
-
"
|
|
61
|
-
"version": "0.9.4",
|
|
62
|
+
"version": "1.0.0",
|
|
62
63
|
"directories": {
|
|
63
64
|
"lib": "lib",
|
|
64
65
|
"test": "test"
|
|
65
66
|
},
|
|
66
67
|
"devDependencies": {
|
|
67
|
-
"browserify": "^17.0.
|
|
68
|
-
"uglify-js": "^3.
|
|
69
|
-
}
|
|
68
|
+
"browserify": "^17.0.1",
|
|
69
|
+
"uglify-js": "^3.19.3"
|
|
70
|
+
},
|
|
71
|
+
"files": [
|
|
72
|
+
"ts/release/**/*.js",
|
|
73
|
+
"ts/release/**/*.d.ts",
|
|
74
|
+
"ts/release/**/*.json",
|
|
75
|
+
"dist/osm2geojson-lite.js"
|
|
76
|
+
]
|
|
70
77
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FeatureCollection, GeometryObject } from 'geojson';
|
|
2
|
+
interface IOptions {
|
|
3
|
+
completeFeature?: boolean;
|
|
4
|
+
allFeatures?: boolean;
|
|
5
|
+
renderTagged?: boolean;
|
|
6
|
+
excludeWay?: boolean;
|
|
7
|
+
suppressWay?: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare function osm2geojson(osm: string | {
|
|
10
|
+
[k: string]: any;
|
|
11
|
+
}, opts?: IOptions): FeatureCollection<GeometryObject>;
|
|
12
|
+
export = osm2geojson;
|
package/ts/release/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
3
5
|
const osmobjs_1 = require("./osmobjs");
|
|
4
6
|
const utils_1 = require("./utils");
|
|
5
|
-
const xmlparser_1 = require("./xmlparser");
|
|
6
|
-
|
|
7
|
+
const xmlparser_1 = __importDefault(require("./xmlparser"));
|
|
8
|
+
function osm2geojson(osm, opts) {
|
|
7
9
|
let completeFeature = false;
|
|
8
10
|
let renderTagged = false;
|
|
9
11
|
let excludeWay = true;
|
|
@@ -43,7 +45,7 @@ exports.default = (osm, opts) => {
|
|
|
43
45
|
if (elem.tags) {
|
|
44
46
|
node.addTags(elem.tags);
|
|
45
47
|
}
|
|
46
|
-
node.addProps(utils_1.purgeProps(elem, ['id', 'type', 'tags', 'lat', 'lon']));
|
|
48
|
+
node.addProps((0, utils_1.purgeProps)(elem, ['id', 'type', 'tags', 'lat', 'lon']));
|
|
47
49
|
node.setLatLng(elem);
|
|
48
50
|
break;
|
|
49
51
|
case 'way':
|
|
@@ -51,7 +53,7 @@ exports.default = (osm, opts) => {
|
|
|
51
53
|
if (elem.tags) {
|
|
52
54
|
way.addTags(elem.tags);
|
|
53
55
|
}
|
|
54
|
-
way.addProps(utils_1.purgeProps(elem, ['id', 'type', 'tags', 'nodes', 'geometry']));
|
|
56
|
+
way.addProps((0, utils_1.purgeProps)(elem, ['id', 'type', 'tags', 'nodes', 'geometry']));
|
|
55
57
|
if (elem.nodes) {
|
|
56
58
|
for (const n of elem.nodes) {
|
|
57
59
|
way.addNodeRef(n);
|
|
@@ -69,7 +71,7 @@ exports.default = (osm, opts) => {
|
|
|
69
71
|
if (elem.tags) {
|
|
70
72
|
relation.addTags(elem.tags);
|
|
71
73
|
}
|
|
72
|
-
relation.addProps(utils_1.purgeProps(elem, ['id', 'type', 'tags', 'bounds', 'members']));
|
|
74
|
+
relation.addProps((0, utils_1.purgeProps)(elem, ['id', 'type', 'tags', 'bounds', 'members']));
|
|
73
75
|
if (elem.members) {
|
|
74
76
|
for (const member of elem.members) {
|
|
75
77
|
relation.addMember(member);
|
|
@@ -123,7 +125,7 @@ exports.default = (osm, opts) => {
|
|
|
123
125
|
});
|
|
124
126
|
xmlParser.on('<osm.relation>', (node) => new osmobjs_1.Relation(node.id, refElements));
|
|
125
127
|
xmlParser.on('</osm.relation.member>', (node, parent) => {
|
|
126
|
-
const relation = refElements.get(`relation/${parent.id}`);
|
|
128
|
+
const relation = refElements.get(`relation/${parent === null || parent === void 0 ? void 0 : parent.id}`);
|
|
127
129
|
const member = {
|
|
128
130
|
type: node.type,
|
|
129
131
|
role: node.role ? node.role : '',
|
|
@@ -158,10 +160,10 @@ exports.default = (osm, opts) => {
|
|
|
158
160
|
relation.addMember(member);
|
|
159
161
|
});
|
|
160
162
|
xmlParser.on('</osm.relation.bounds>', (node, parent) => {
|
|
161
|
-
refElements.get(`relation/${parent.id}`).setBounds([parseFloat(node.minlon), parseFloat(node.minlat), parseFloat(node.maxlon), parseFloat(node.maxlat)]);
|
|
163
|
+
refElements.get(`relation/${parent === null || parent === void 0 ? void 0 : parent.id}`).setBounds([parseFloat(node.minlon), parseFloat(node.minlat), parseFloat(node.maxlon), parseFloat(node.maxlat)]);
|
|
162
164
|
});
|
|
163
165
|
xmlParser.on('</osm.relation.tag>', (node, parent) => {
|
|
164
|
-
refElements.get(`relation/${parent.id}`).addTag(node.k, node.v);
|
|
166
|
+
refElements.get(`relation/${parent === null || parent === void 0 ? void 0 : parent.id}`).addTag(node.k, node.v);
|
|
165
167
|
});
|
|
166
168
|
xmlParser.parse(o);
|
|
167
169
|
};
|
|
@@ -192,4 +194,6 @@ exports.default = (osm, opts) => {
|
|
|
192
194
|
}
|
|
193
195
|
}
|
|
194
196
|
return { type: 'FeatureCollection', features: featureArray };
|
|
195
|
-
}
|
|
197
|
+
}
|
|
198
|
+
;
|
|
199
|
+
module.exports = osm2geojson;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Feature } from 'geojson';
|
|
2
|
+
import { RefElements } from './utils';
|
|
3
|
+
declare class OsmObject {
|
|
4
|
+
refCount: number;
|
|
5
|
+
protected refElems: RefElements;
|
|
6
|
+
private type;
|
|
7
|
+
private id;
|
|
8
|
+
private tags;
|
|
9
|
+
private props;
|
|
10
|
+
private hasTag;
|
|
11
|
+
constructor(type: string, id: string, refElems: RefElements);
|
|
12
|
+
addTags(tags: {
|
|
13
|
+
[k: string]: string;
|
|
14
|
+
}): void;
|
|
15
|
+
addTag(k: string, v: string): void;
|
|
16
|
+
addProp(k: string, v: any): void;
|
|
17
|
+
addProps(props: {
|
|
18
|
+
[k: string]: string;
|
|
19
|
+
}): void;
|
|
20
|
+
getCompositeId(): string;
|
|
21
|
+
getProps(): {
|
|
22
|
+
[k: string]: string;
|
|
23
|
+
};
|
|
24
|
+
toFeatureArray(): Array<Feature<any, any>>;
|
|
25
|
+
}
|
|
26
|
+
export declare class Node extends OsmObject {
|
|
27
|
+
private latLng;
|
|
28
|
+
constructor(id: string, refElems: RefElements);
|
|
29
|
+
setLatLng(latLng: {
|
|
30
|
+
lat: string;
|
|
31
|
+
lon: string;
|
|
32
|
+
}): void;
|
|
33
|
+
toFeatureArray(): Array<Feature<any, any>>;
|
|
34
|
+
getLatLng(): {
|
|
35
|
+
lat: string;
|
|
36
|
+
lon: string;
|
|
37
|
+
} | null;
|
|
38
|
+
}
|
|
39
|
+
export declare class Way extends OsmObject {
|
|
40
|
+
private latLngArray;
|
|
41
|
+
private isPolygon;
|
|
42
|
+
constructor(id: string, refElems: RefElements);
|
|
43
|
+
addLatLng(latLng: {
|
|
44
|
+
lat: string;
|
|
45
|
+
lon: string;
|
|
46
|
+
}): void;
|
|
47
|
+
setLatLngArray(latLngArray: Array<{
|
|
48
|
+
lat: string;
|
|
49
|
+
lon: string;
|
|
50
|
+
[k: string]: any;
|
|
51
|
+
}>): void;
|
|
52
|
+
addNodeRef(ref: string): void;
|
|
53
|
+
addTags(tags: {
|
|
54
|
+
[k: string]: string;
|
|
55
|
+
}): void;
|
|
56
|
+
addTag(k: string, v: string): void;
|
|
57
|
+
toCoordsArray(): string[][];
|
|
58
|
+
toFeatureArray(): Array<Feature<any, any>>;
|
|
59
|
+
private analyzeTag;
|
|
60
|
+
}
|
|
61
|
+
export declare class Relation extends OsmObject {
|
|
62
|
+
private relations;
|
|
63
|
+
private nodes;
|
|
64
|
+
private bounds;
|
|
65
|
+
[k: string]: any;
|
|
66
|
+
constructor(id: string, refElems: RefElements);
|
|
67
|
+
setBounds(bounds: any[]): void;
|
|
68
|
+
addMember(member: {
|
|
69
|
+
[k: string]: any;
|
|
70
|
+
}): void;
|
|
71
|
+
toFeatureArray(): Array<Feature<any, any>>;
|
|
72
|
+
}
|
|
73
|
+
export {};
|
package/ts/release/osmobjs.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Relation = exports.Way = exports.Node = void 0;
|
|
3
7
|
const utils_1 = require("./utils");
|
|
4
8
|
const utils_2 = require("./utils");
|
|
5
|
-
const polytags_json_1 = require("./polytags.json");
|
|
9
|
+
const polytags_json_1 = __importDefault(require("./polytags.json"));
|
|
6
10
|
class OsmObject {
|
|
7
11
|
constructor(type, id, refElems) {
|
|
8
12
|
this.type = type;
|
|
@@ -56,7 +60,7 @@ class Node extends OsmObject {
|
|
|
56
60
|
properties: this.getProps(),
|
|
57
61
|
geometry: {
|
|
58
62
|
type: 'Point',
|
|
59
|
-
coordinates: utils_1.strToFloat([this.latLng.lon, this.latLng.lat]),
|
|
63
|
+
coordinates: (0, utils_1.strToFloat)([this.latLng.lon, this.latLng.lat]),
|
|
60
64
|
},
|
|
61
65
|
}];
|
|
62
66
|
}
|
|
@@ -80,7 +84,7 @@ class Way extends OsmObject {
|
|
|
80
84
|
this.latLngArray = latLngArray;
|
|
81
85
|
}
|
|
82
86
|
addNodeRef(ref) {
|
|
83
|
-
const binder = new utils_2.LateBinder(this.latLngArray,
|
|
87
|
+
const binder = new utils_2.LateBinder(this.latLngArray, (id) => {
|
|
84
88
|
const node = this.refElems.get(`node/${id}`);
|
|
85
89
|
if (node) {
|
|
86
90
|
node.refCount++;
|
|
@@ -106,7 +110,7 @@ class Way extends OsmObject {
|
|
|
106
110
|
toFeatureArray() {
|
|
107
111
|
let coordsArray = this.toCoordsArray();
|
|
108
112
|
if (coordsArray.length > 1) {
|
|
109
|
-
coordsArray = utils_1.strToFloat(coordsArray);
|
|
113
|
+
coordsArray = (0, utils_1.strToFloat)(coordsArray);
|
|
110
114
|
const feature = {
|
|
111
115
|
type: 'Feature',
|
|
112
116
|
id: this.getCompositeId(),
|
|
@@ -116,8 +120,8 @@ class Way extends OsmObject {
|
|
|
116
120
|
coordinates: coordsArray,
|
|
117
121
|
},
|
|
118
122
|
};
|
|
119
|
-
if (this.isPolygon && utils_1.isRing(coordsArray)) {
|
|
120
|
-
if (utils_1.ringDirection(coordsArray) !== 'counterclockwise') {
|
|
123
|
+
if (this.isPolygon && (0, utils_1.isRing)(coordsArray)) {
|
|
124
|
+
if ((0, utils_1.ringDirection)(coordsArray) !== 'counterclockwise') {
|
|
121
125
|
coordsArray.reverse();
|
|
122
126
|
}
|
|
123
127
|
feature.geometry = {
|
|
@@ -158,7 +162,7 @@ class Relation extends OsmObject {
|
|
|
158
162
|
switch (member.type) {
|
|
159
163
|
// super relation, need to do combination
|
|
160
164
|
case 'relation':
|
|
161
|
-
let binder = new utils_2.LateBinder(this.relations,
|
|
165
|
+
let binder = new utils_2.LateBinder(this.relations, (id) => {
|
|
162
166
|
const relation = this.refElems.get(`relation/${id}`);
|
|
163
167
|
if (relation) {
|
|
164
168
|
relation.refCount++;
|
|
@@ -191,7 +195,7 @@ class Relation extends OsmObject {
|
|
|
191
195
|
ways.push(way);
|
|
192
196
|
}
|
|
193
197
|
else {
|
|
194
|
-
binder = new utils_2.LateBinder(ways,
|
|
198
|
+
let binder = new utils_2.LateBinder(ways, (nid) => {
|
|
195
199
|
const way = this.refElems.get(`way/${nid}`);
|
|
196
200
|
if (way) {
|
|
197
201
|
way.refCount++;
|
|
@@ -219,7 +223,7 @@ class Relation extends OsmObject {
|
|
|
219
223
|
this.nodes.push(node);
|
|
220
224
|
}
|
|
221
225
|
else {
|
|
222
|
-
binder = new utils_2.LateBinder(this.nodes,
|
|
226
|
+
let binder = new utils_2.LateBinder(this.nodes, (id) => {
|
|
223
227
|
const nn = this.refElems.get(`node/${id}`);
|
|
224
228
|
if (nn) {
|
|
225
229
|
nn.refCount++;
|
|
@@ -263,7 +267,7 @@ class Relation extends OsmObject {
|
|
|
263
267
|
ring = innerRings.shift();
|
|
264
268
|
while (ring) {
|
|
265
269
|
for (const idx in outerRings) {
|
|
266
|
-
if (utils_1.ptInsidePolygon(utils_1.first(ring), outerRings[idx])) {
|
|
270
|
+
if ((0, utils_1.ptInsidePolygon)((0, utils_1.first)(ring), outerRings[idx])) {
|
|
267
271
|
compositPolyons[idx].push(ring);
|
|
268
272
|
break;
|
|
269
273
|
}
|
|
@@ -287,16 +291,17 @@ class Relation extends OsmObject {
|
|
|
287
291
|
const polygonFeatures = [];
|
|
288
292
|
const stringFeatures = [];
|
|
289
293
|
let pointFeatures = [];
|
|
290
|
-
const waysFieldNames = ['outer', 'inner', ''];
|
|
291
294
|
// need to do combination when there're nested relations
|
|
295
|
+
const notWayFields = ['type', 'id', 'refElems', 'tags', 'props', 'refCount', 'hasTag', 'relations', 'nodes', 'bounds'];
|
|
292
296
|
for (const relation of this.relations) {
|
|
293
297
|
if (relation) {
|
|
298
|
+
let waysFieldNames = Object.keys(relation).filter(fieldName => notWayFields.indexOf(fieldName) < 0);
|
|
294
299
|
for (const fieldName of waysFieldNames) {
|
|
295
300
|
const ways = relation[fieldName];
|
|
296
301
|
if (ways) {
|
|
297
302
|
const thisWays = this[fieldName];
|
|
298
303
|
if (thisWays) {
|
|
299
|
-
|
|
304
|
+
thisWays.push(...ways);
|
|
300
305
|
}
|
|
301
306
|
else {
|
|
302
307
|
this[fieldName] = ways;
|
|
@@ -305,6 +310,7 @@ class Relation extends OsmObject {
|
|
|
305
310
|
}
|
|
306
311
|
}
|
|
307
312
|
}
|
|
313
|
+
let waysFieldNames = Object.keys(this).filter(fieldName => notWayFields.indexOf(fieldName) < 0);
|
|
308
314
|
for (const fieldName of waysFieldNames) {
|
|
309
315
|
const ways = this[fieldName];
|
|
310
316
|
if (ways) {
|
|
@@ -315,31 +321,54 @@ class Relation extends OsmObject {
|
|
|
315
321
|
}
|
|
316
322
|
}
|
|
317
323
|
let geometry = null;
|
|
318
|
-
|
|
324
|
+
let templateFeature = {
|
|
319
325
|
type: 'Feature',
|
|
320
326
|
id: this.getCompositeId(),
|
|
321
327
|
bbox: this.bounds,
|
|
322
328
|
properties: this.getProps(),
|
|
323
|
-
geometry: null
|
|
329
|
+
geometry: null
|
|
324
330
|
};
|
|
325
331
|
if (!this.bounds) {
|
|
326
|
-
delete
|
|
332
|
+
delete templateFeature.bbox;
|
|
327
333
|
}
|
|
328
334
|
if (this.outer) {
|
|
329
|
-
|
|
335
|
+
let feature = Object.assign({}, templateFeature);
|
|
336
|
+
let geometry = constructPolygonGeometry(this.outer, this.inner);
|
|
330
337
|
if (geometry) {
|
|
331
338
|
feature.geometry = geometry;
|
|
332
339
|
polygonFeatures.push(feature);
|
|
333
340
|
}
|
|
334
341
|
}
|
|
335
|
-
else
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
342
|
+
else {
|
|
343
|
+
let multiLineGeometry = {
|
|
344
|
+
type: 'MultiLineString',
|
|
345
|
+
coordinates: []
|
|
346
|
+
};
|
|
347
|
+
for (let way of waysFieldNames) {
|
|
348
|
+
if (way != null && way !== 'inner') {
|
|
349
|
+
let ws = this[way];
|
|
350
|
+
if (ws) {
|
|
351
|
+
let geometry = constructStringGeometry(ws);
|
|
352
|
+
if (geometry) {
|
|
353
|
+
if (geometry.type === 'LineString') {
|
|
354
|
+
multiLineGeometry.coordinates.push(geometry.coordinates);
|
|
355
|
+
}
|
|
356
|
+
else if (geometry.type === 'MultiLineString') {
|
|
357
|
+
let feature = Object.assign({}, templateFeature);
|
|
358
|
+
feature.geometry = geometry;
|
|
359
|
+
stringFeatures.push(feature);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
if (multiLineGeometry.coordinates.length > 0) {
|
|
366
|
+
let feature = Object.assign({}, templateFeature);
|
|
367
|
+
feature.geometry = multiLineGeometry;
|
|
339
368
|
stringFeatures.push(feature);
|
|
340
369
|
}
|
|
341
370
|
}
|
|
342
|
-
for (
|
|
371
|
+
for (let node of this.nodes) {
|
|
343
372
|
pointFeatures = pointFeatures.concat(node.toFeatureArray());
|
|
344
373
|
}
|
|
345
374
|
return [...polygonFeatures, ...stringFeatures, ...pointFeatures];
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Way } from './osmobjs';
|
|
2
|
+
export declare function purgeProps(obj: {
|
|
3
|
+
[k: string]: any;
|
|
4
|
+
}, blacklist: string[]): {
|
|
5
|
+
[k: string]: any;
|
|
6
|
+
};
|
|
7
|
+
export declare function mergeProps(obj1: {
|
|
8
|
+
[k: string]: any;
|
|
9
|
+
}, obj2: {
|
|
10
|
+
[k: string]: any;
|
|
11
|
+
}): {
|
|
12
|
+
[k: string]: any;
|
|
13
|
+
};
|
|
14
|
+
export declare function addPropToFeature(f: {
|
|
15
|
+
[k: string]: any;
|
|
16
|
+
}, k: string, v: any): void;
|
|
17
|
+
export declare function addPropToFeatures(fs: Array<{
|
|
18
|
+
[k: string]: any;
|
|
19
|
+
}>, k: string, v: any): void;
|
|
20
|
+
export declare const first: <T>(a: T[]) => T;
|
|
21
|
+
export declare const last: <T>(a: T[]) => T;
|
|
22
|
+
export declare const coordsToKey: <T>(a: T[]) => string;
|
|
23
|
+
export declare function addToMap<T>(m: {
|
|
24
|
+
[k: string]: T[];
|
|
25
|
+
}, k: string, v: T): void;
|
|
26
|
+
export declare function removeFromMap<T>(m: {
|
|
27
|
+
[k: string]: T[];
|
|
28
|
+
}, k: string, v: T): void;
|
|
29
|
+
export declare function getFirstFromMap<T>(m: {
|
|
30
|
+
[k: string]: T[];
|
|
31
|
+
}, k: string): T | null;
|
|
32
|
+
export declare const isRing: (a: number[][]) => boolean;
|
|
33
|
+
export declare const ringDirection: (a: number[][], xIdx?: number, yIdx?: number) => string;
|
|
34
|
+
export declare const ptInsidePolygon: (pt: number[], polygon: number[][], xIdx?: number, yIdx?: number) => boolean;
|
|
35
|
+
export declare const strToFloat: (el: any[] | string) => any;
|
|
36
|
+
export declare class LateBinder {
|
|
37
|
+
private container;
|
|
38
|
+
private valueFunc;
|
|
39
|
+
private ctx;
|
|
40
|
+
private args;
|
|
41
|
+
constructor(container: any[] | {
|
|
42
|
+
[k: string]: any;
|
|
43
|
+
}, valueFunc: (...args: any[]) => any, ctx: any, args: any[]);
|
|
44
|
+
bind(): void;
|
|
45
|
+
}
|
|
46
|
+
export declare class RefElements extends Map {
|
|
47
|
+
private binders;
|
|
48
|
+
constructor();
|
|
49
|
+
add(k: string, v: any): void;
|
|
50
|
+
addBinder(binder: LateBinder): void;
|
|
51
|
+
bindAll(): void;
|
|
52
|
+
}
|
|
53
|
+
export declare class WayCollection extends Array {
|
|
54
|
+
private firstMap;
|
|
55
|
+
private lastMap;
|
|
56
|
+
constructor();
|
|
57
|
+
addWay(way: Way): void;
|
|
58
|
+
toStrings(): number[][][];
|
|
59
|
+
toRings(direction: string): number[][][];
|
|
60
|
+
}
|