mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-22 16:19:48 +02:00
working on preset visibility
This commit is contained in:
Vendored
+14
@@ -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"
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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; });
|
||||
|
||||
+5
-5
@@ -30,7 +30,7 @@
|
||||
<script src='spec/spec_helpers.js'></script>
|
||||
|
||||
<!-- include spec files below... -->
|
||||
<script src='spec/actions/add_entity.js'></script>
|
||||
<!-- <script src='spec/actions/add_entity.js'></script>
|
||||
<script src='spec/actions/add_member.js'></script>
|
||||
<script src='spec/actions/add_midpoint.js'></script>
|
||||
<script src='spec/actions/change_member.js'></script>
|
||||
@@ -99,10 +99,10 @@
|
||||
|
||||
<script src='spec/presets/category.js'></script>
|
||||
<script src='spec/presets/collection.js'></script>
|
||||
<script src='spec/presets/index.js'></script>
|
||||
<script src='spec/presets/index.js'></script> -->
|
||||
<script src='spec/presets/preset.js'></script>
|
||||
|
||||
<script src='spec/renderer/background_source.js'></script>
|
||||
<!-- <script src='spec/renderer/background_source.js'></script>
|
||||
<script src='spec/renderer/features.js'></script>
|
||||
<script src='spec/renderer/map.js'></script>
|
||||
<script src='spec/renderer/tile_layer.js'></script>
|
||||
@@ -112,7 +112,7 @@
|
||||
<script src='spec/services/openstreetcam.js'></script>
|
||||
<script src='spec/services/osm.js'></script>
|
||||
<script src='spec/services/streetside.js'></script>
|
||||
<script src='spec/services/taginfo.js'></script> -->
|
||||
<script src='spec/services/taginfo.js'></script>
|
||||
|
||||
<script src='spec/services/maprules.js'></script>
|
||||
|
||||
@@ -145,7 +145,7 @@
|
||||
<script src='spec/util/suggest_names.js'></script>
|
||||
<script src='spec/util/util.js'></script>
|
||||
|
||||
<script src='spec/operations/detach_node.js'></script>
|
||||
<script src='spec/operations/detach_node.js'></script> -->
|
||||
<script>
|
||||
window.mocha.run();
|
||||
</script>
|
||||
|
||||
@@ -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() {
|
||||
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user