mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-12 16:52:50 +00:00
This makes the osmNote work a bit more like other osm objects in iD.
- When working with the osm objects, we'll treat them as immutable.
So all modifications will be through the update method:
e.g. can do this in a repl, like chrome devtools console:
> n = iD.osmNote()
osmNote { id: -1 }
> n = n.update({ foo: 'bar' });
osmNote { foo: "bar", id: -1, v: 1 }
- none of the other osm objects have getters, and in JavaScript all the
properties are public anyway
56 lines
1.1 KiB
JavaScript
56 lines
1.1 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();
|
|
}
|
|
|
|
return this;
|
|
},
|
|
|
|
extent: function() {
|
|
return new geoExtent(this.loc);
|
|
},
|
|
|
|
update: function(attrs) {
|
|
return osmNote(this, attrs, {v: 1 + (this.v || 0)});
|
|
}
|
|
});
|