add core overwrite for external preset source

ref #remote-presets
This commit is contained in:
Max Grossman
2018-07-17 16:43:00 -04:00
parent 4c9ef45448
commit 659a291e89
3 changed files with 52 additions and 6 deletions
+1 -1
View File
@@ -306,7 +306,7 @@ export function coreContext() {
/* Presets */
var presets;
context.presets = function() { return presets; };
context.overwritePresets = function(newPresets) { presets.overwrite(newPresets); };
/* Map */
var map;
+10 -4
View File
@@ -118,10 +118,7 @@ export function presetIndex() {
return areaKeys;
};
all.init = function() {
var d = data.presets;
all.build = function (d) {
all.collection = [];
_recent.collection = [];
_fields = {};
@@ -172,6 +169,15 @@ export function presetIndex() {
}
}
};
all.overwrite = function (d) {
all.build(d);
return all;
};
all.init = function() {
all.build(data.presets);
return all;
};
+41 -1
View File
@@ -156,7 +156,47 @@ describe('iD.presetIndex', function() {
});
});
describe('#overwrite', function() {
it('overwrites iD presets with provided list of presets', function() {
var testPresets = {
presets: {
'amenity/fuel/shell': {
tags: { 'amenity': 'fuel' },
geometry: ['point','area'],
suggestion: true
},
'highway/foo': {
tags: { 'highway': 'foo' },
geometry: ['area']
},
'leisure/track': {
tags: { 'leisure': 'track' },
geometry: ['line', 'area']
},
'natural': {
tags: { 'natural': '*' },
geometry: ['point', 'vertex', 'area']
},
'natural/peak': {
tags: { 'natural': 'peak' },
geometry: ['point', 'vertex']
},
'natural/tree_row': {
tags: { 'natural': 'tree_row' },
geometry: ['line']
},
'natural/wood': {
tags: { 'natural': 'wood' },
geometry: ['point', 'area']
}
}
};
var currentPresets = iD.Context().presets();
var overwrittenPresets = iD.Context().overwritePresets(testPresets);
expect(currentPresets).to.not.eql(overwrittenPresets);
});
});
describe('expected matches', function() {
it('prefers building to multipolygon', function() {