diff --git a/dist/locales/en.json b/dist/locales/en.json index 52bafa357..6945836cb 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -7182,6 +7182,13 @@ "description": "Japan GSI Standard Map. Widely covered.", "name": "Japan GSI Standard Map" }, + "helsingborg-orto": { + "attribution": { + "text": "© Helsingborg municipality" + }, + "description": "Orthophotos from the municipality of Helsingborg 2016, public domain", + "name": "Helsingborg Orthophoto" + }, "hike_n_bike": { "attribution": { "text": "© OpenStreetMap contributors" @@ -7273,6 +7280,13 @@ }, "name": "Stamen Terrain" }, + "stockholm-orto": { + "attribution": { + "text": "© Stockholm municipality, CC0" + }, + "description": "Orthophotos from the municipality of Stockholm 2015, CC0 license", + "name": "Stockholm Orthophoto" + }, "tf-cycle": { "attribution": { "text": "Maps © Thunderforest, Data © OpenStreetMap contributors" diff --git a/modules/presets/index.js b/modules/presets/index.js index aa1924032..b038890a9 100644 --- a/modules/presets/index.js +++ b/modules/presets/index.js @@ -124,14 +124,7 @@ export function presetIndex() { return areaKeys; }; - all.build = function () { - var d = data.presets; - all.collection = []; - _recent.collection = []; - _fields = {}; - _universal = []; - _index = { point: {}, vertex: {}, line: {}, area: {}, relation: {} }; - + all.build = function (d, visible) { if (d.fields) { _forEach(d.fields, function(d, id) { _fields[id] = presetField(id, d); @@ -143,7 +136,7 @@ export function presetIndex() { if (d.presets) { _forEach(d.presets, function(d, id) { - all.collection.push(presetPreset(id, d, _fields)); + all.collection.push(presetPreset(id, d, _fields, visible)); }); } @@ -185,20 +178,15 @@ export function presetIndex() { var presetsUrl = utilStringQs(window.location.hash).presets; d3_json(presetsUrl, function(err, presets) { if (err) all.init(); - all.overwrite(presets); + all.build(presets, true); + all.build(data.presets, false); all.areaKeys(); }); return all; }; - all.overwrite = function (d) { - data.presets = d; - all.build(); - return all; - }; - all.init = function() { - all.build(); + all.build(data.presets, true); return all; }; @@ -213,7 +201,7 @@ export function presetIndex() { all.defaults = function(geometry, n) { var rec = _recent.matchGeometry(geometry).collection.slice(0, 4); var def = _uniq(rec.concat(_defaults[geometry].collection)).slice(0, n - 1); - var fin = _uniq(rec.concat(def).concat(all.item(geometry))).filter(function(d) { return d !== undefined; }); + var fin = _uniq(rec.concat(def).concat(all.item(geometry))).filter(function(d) { return d.visible(); }); return presetCollection(fin); }; diff --git a/modules/presets/preset.js b/modules/presets/preset.js index f4e4db27d..f3734177a 100644 --- a/modules/presets/preset.js +++ b/modules/presets/preset.js @@ -6,13 +6,14 @@ import { t } from '../util/locale'; import { areaKeys } from '../core/context'; -export function presetPreset(id, preset, fields) { +export function presetPreset(id, preset, fields, visible) { preset = _clone(preset); preset.id = id; preset.fields = (preset.fields || []).map(getFields); preset.geometry = (preset.geometry || []); + visible = visible || false; function getFields(f) { return fields[f]; @@ -71,6 +72,12 @@ export function presetPreset(id, preset, fields) { return tagCount === 0 || (tagCount === 1 && preset.tags.hasOwnProperty('area')); }; + preset.visible = function(_) { + if (!arguments.length) return visible; + visible = _; + return visible; + }; + var reference = preset.reference || {}; preset.reference = function(geometry) { diff --git a/modules/ui/preset_list.js b/modules/ui/preset_list.js index 3360aeb8c..eb92d944e 100644 --- a/modules/ui/preset_list.js +++ b/modules/ui/preset_list.js @@ -137,9 +137,12 @@ export function uiPresetList(context) { function drawList(list, presets) { - var collection = presets.collection.map(function(preset) { - return preset.members ? CategoryItem(preset) : PresetItem(preset); - }); + var collection = presets.collection.reduce(function(collection, preset) { + if (preset.visible()) { + collection.push(preset.members ? CategoryItem(preset) : PresetItem(preset)); + } + return collection; + }, []); var items = list.selectAll('.preset-list-item') .data(collection, function(d) { return d.preset.id; }); diff --git a/test/index.html b/test/index.html index caf87bc2e..fa6fc48e1 100644 --- a/test/index.html +++ b/test/index.html @@ -30,7 +30,7 @@ - + - + + @@ -145,7 +145,7 @@ - + --> diff --git a/test/spec/presets/index.js b/test/spec/presets/index.js index 742a0a6b7..51a2613ed 100644 --- a/test/spec/presets/index.js +++ b/test/spec/presets/index.js @@ -196,6 +196,12 @@ describe('iD.presetIndex', function() { expect(currentPresets).to.not.eql(overwrittenPresets); }); }); + + describe('#build', function () { + it('builds presets from provided', function() { + + }); + }); describe('expected matches', function() { diff --git a/test/spec/presets/preset.js b/test/spec/presets/preset.js index 1feff1082..8bed21ff5 100644 --- a/test/spec/presets/preset.js +++ b/test/spec/presets/preset.js @@ -149,4 +149,13 @@ describe('iD.presetPreset', function() { expect(preset.removeTags({a: 'b'}, 'area')).to.eql({a: 'b'}); }); }); + + describe('#visible', function() { + it('sets/gets visibility of preset', function() { + var preset = iD.presetPreset('test', {}, false); + expect(preset.visible()).to.be.false; + preset.visible(true); + expect(preset.visible()).to.be.true; + }); + }); });