-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathosm2obj.js
41 lines (37 loc) · 1.59 KB
/
osm2obj.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const osm2obj = require('osm2obj')
const through = require('through2')
const pumpify = require('pumpify')
module.exports = function (api, opts) {
var stream = pumpify.obj()
var original = osm2obj(opts)
var out = through.obj(function (doc, _, cb) {
if (!doc.version) return cb(null, doc)
api.getElement(null, {version: doc.version}, function (err, old) {
// if there's an error here, dont do anything, just fall back on osm2obj's default behavior
if (err) return cb(null, doc)
// If there's an existing element that's an observation, Use that
// observation, and then patch the changes from iD editor to it. This is
// necessary because incoming OSM changesets are not required to maintain
// these non-OSM Mapeo attributes through the entire lifecycle, so we
// patch these from the back end. Lat & Lon are ignored, because
// observation location should be immutable. We have not yet implemented a
// way in iD Editor to prevent moving observations, so we ignore any
// location edits on save
// If you want to make any other items editable from the Territory
// view, you'd need to add lines for each property that should be edited.
if (old && old.type === 'observation') {
var obs = Object.assign({}, old)
obs.action = doc.action
obs.changeset = doc.changeset
obs.version = doc.version
// obs.lat = doc.lat
// obs.lon = doc.lon
obs.tags = doc.tags
return cb(null, obs)
}
return cb(null, doc)
})
})
stream.setPipeline(original, out)
return stream
}