mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 01:02:58 +00:00
Create osmChangeset object, inherit from osmEntity
This commit is contained in:
53
modules/osm/changeset.js
Normal file
53
modules/osm/changeset.js
Normal file
@@ -0,0 +1,53 @@
|
||||
import _ from 'lodash';
|
||||
import { osmEntity } from './entity';
|
||||
import { geoExtent } from '../geo';
|
||||
|
||||
|
||||
export function osmChangeset() {
|
||||
if (!(this instanceof osmChangeset)) {
|
||||
return (new osmChangeset()).initialize(arguments);
|
||||
} else if (arguments.length) {
|
||||
this.initialize(arguments);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
osmEntity.changeset = osmChangeset;
|
||||
|
||||
osmChangeset.prototype = Object.create(osmEntity.prototype);
|
||||
|
||||
_.extend(osmChangeset.prototype, {
|
||||
|
||||
type: 'changeset',
|
||||
|
||||
|
||||
extent: function() {
|
||||
return new geoExtent();
|
||||
},
|
||||
|
||||
|
||||
geometry: function() {
|
||||
return 'changeset';
|
||||
},
|
||||
|
||||
|
||||
asJXON: function() {
|
||||
return {
|
||||
osm: {
|
||||
changeset: {
|
||||
tag: _.map(this.tags, function(value, key) {
|
||||
return { '@k': key, '@v': value };
|
||||
}),
|
||||
'@version': 0.6,
|
||||
'@generator': 'iD'
|
||||
}
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
|
||||
asGeoJSON: function() {
|
||||
return {};
|
||||
}
|
||||
|
||||
});
|
||||
@@ -26,7 +26,7 @@ osmEntity.id = function(type) {
|
||||
|
||||
|
||||
osmEntity.id.next = {
|
||||
node: -1, way: -1, relation: -1
|
||||
changeset: -1, node: -1, way: -1, relation: -1
|
||||
};
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ osmEntity.id.toOSM = function(id) {
|
||||
|
||||
|
||||
osmEntity.id.type = function(id) {
|
||||
return { 'n': 'node', 'w': 'way', 'r': 'relation' }[id[0]];
|
||||
return { 'c': 'changeset', 'n': 'node', 'w': 'way', 'r': 'relation' }[id[0]];
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export { osmChangeset } from './changeset';
|
||||
export { osmEntity } from './entity';
|
||||
export { osmNode } from './node';
|
||||
export { osmRelation } from './relation';
|
||||
|
||||
@@ -81,6 +81,7 @@
|
||||
|
||||
<script src='spec/modes/add_point.js'></script>
|
||||
|
||||
<script src='spec/osm/changeset.js'></script>
|
||||
<script src='spec/osm/entity.js'></script>
|
||||
<script src='spec/osm/intersection.js'></script>
|
||||
<script src='spec/osm/multipolygon.js'></script>
|
||||
|
||||
29
test/spec/osm/changeset.js
Normal file
29
test/spec/osm/changeset.js
Normal file
@@ -0,0 +1,29 @@
|
||||
describe('iD.osmChangeset', function () {
|
||||
it('returns a changeset', function () {
|
||||
expect(iD.osmChangeset()).to.be.an.instanceOf(iD.osmChangeset);
|
||||
expect(iD.osmChangeset().type).to.equal('changeset');
|
||||
});
|
||||
|
||||
it('defaults tags to an empty object', function () {
|
||||
expect(iD.osmChangeset().tags).to.eql({});
|
||||
});
|
||||
|
||||
it('sets tags as specified', function () {
|
||||
expect(iD.osmChangeset({tags: {foo: 'bar'}}).tags).to.eql({foo: 'bar'});
|
||||
});
|
||||
|
||||
describe('#asJXON', function () {
|
||||
it('converts a node to jxon', function() {
|
||||
var node = iD.osmChangeset({tags: {'comment': 'hello'}});
|
||||
expect(node.asJXON()).to.eql({
|
||||
osm: {
|
||||
changeset: {
|
||||
tag: [{ '@k': 'comment', '@v': 'hello' }],
|
||||
'@version': 0.6,
|
||||
'@generator': 'iD'
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user