osmlab/changeset-map

Changesets without closed_at property throw `Cannot read property 'toString' of null` error

jguddas opened this issue · 1 comments

  • I'm submitting a Bug
  • bug report
  • feature request
  • support / question

Brief Description

Loading of some changesets fails.

What is the current behaviour, (attach relevant screenshots) ?

TypeError: Cannot read property 'toString' of null

What is the expected behaviour ?

A better error message or maybe no error at all.

When does this occur ?

When the changeset has no closed_at property.

How do we replicate the issue ?

Example changeset: https://www.openstreetmap.org/api/0.6/changeset/109618303.json?include_discussion=true

Other Information / context:

c.to can be null

to: cs.closed_at || null,

(null).toString() does not work
c.to.toString() +

Possible solutions:

  1. Better error message
var data = getDataParam(changeset);
+ if (!data.to) {
+   new Error('Changeset has no closed_at property!')
+ }
  1. Not returning null.
- to: cs.closed_at || null,
+ to: cs.closed_at || …,

A way to provide a map for an open changeset is using an appropriate Overpass query with the one-timestamp variant of the adiff statement, e.g.,

[adiff:"2012-09-14T15:00:00Z"]

This can be done by

     '[out:xml][adiff:%22' +
     c.from.toString() +
-    ',%22,%22' +
-    c.to.toString() +
+    (c.to ? '%22,%22' + c.to.toString() : '') +
     '%22];(node(bbox)(changed);way(bbox)(changed);relation(bbox)(changed););out%20meta%20geom(bbox);'

at

function getDataParam(c) {
return (
'[out:xml][adiff:%22' +
c.from.toString() +
',%22,%22' +
c.to.toString() +
'%22];(node(bbox)(changed);way(bbox)(changed);relation(bbox)(changed););out%20meta%20geom(bbox);'
);
}