osm2geojson-ultra
Version:
a faster & more complete OSM & Overpass (either in xml or in json formats) to geojson convertor - 4x faster than xmldom + osmtogeojson in most situations - implemented in TypeScript with txml for XML parsing
43 lines (42 loc) • 1.1 kB
JavaScript
export class OsmObject {
constructor(type, id, refElems) {
this.type = type;
this.id = id;
this.refElems = refElems;
this.tags = {};
this.meta = {};
this.refCount = 0;
this.hasTag = false;
if (refElems) {
refElems.add(this.getCompositeId(), this);
}
}
addTags(tags) {
this.tags = Object.assign(this.tags, tags);
this.hasTag = true;
}
addTag(k, v) {
this.tags[k] = v;
this.hasTag = true;
}
addMeta(k, v) {
this.meta[k] = v;
}
addMetas(meta) {
this.meta = Object.assign(this.meta, meta);
}
getCompositeId() {
return `${this.type}/${this.id}`;
}
getProps() {
return {
"@id": this.id,
"@type": this.type,
...Object.fromEntries(Object.entries(this.meta).map(([k, v]) => ["@" + k, v])),
...Object.fromEntries(Object.entries(this.tags).map(([k, v]) => [
k.startsWith("@") ? "@" + k : k,
v,
])),
};
}
}