mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 09:12:52 +00:00
Also stringify the note id (because existing notes from OSM are this way) Also make sure comments is initialized as an Array not an Object Also clarify some of the tests
65 lines
1.3 KiB
JavaScript
65 lines
1.3 KiB
JavaScript
import _extend from 'lodash-es/extend';
|
|
|
|
import { geoExtent } from '../geo';
|
|
|
|
|
|
export function osmNote() {
|
|
if (!(this instanceof osmNote)) {
|
|
return (new osmNote()).initialize(arguments);
|
|
} else if (arguments.length) {
|
|
this.initialize(arguments);
|
|
}
|
|
}
|
|
|
|
|
|
osmNote.id = function() {
|
|
return osmNote.id.next--;
|
|
};
|
|
|
|
|
|
osmNote.id.next = -1;
|
|
|
|
|
|
_extend(osmNote.prototype, {
|
|
|
|
type: 'note',
|
|
|
|
initialize: function(sources) {
|
|
for (var i = 0; i < sources.length; ++i) {
|
|
var source = sources[i];
|
|
for (var prop in source) {
|
|
if (Object.prototype.hasOwnProperty.call(source, prop)) {
|
|
if (source[prop] === undefined) {
|
|
delete this[prop];
|
|
} else {
|
|
this[prop] = source[prop];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!this.id) {
|
|
this.id = osmNote.id() + ''; // as string
|
|
}
|
|
|
|
return this;
|
|
},
|
|
|
|
extent: function() {
|
|
return new geoExtent(this.loc);
|
|
},
|
|
|
|
update: function(attrs) {
|
|
return osmNote(this, attrs); // {v: 1 + (this.v || 0)}
|
|
},
|
|
|
|
isNew: function() {
|
|
return this.id < 0;
|
|
},
|
|
|
|
move: function(loc) {
|
|
return this.update({ loc: loc });
|
|
}
|
|
|
|
});
|