Combine vertex and point geometries into a single Point fallback preset

This commit is contained in:
Quincy Morgan
2019-03-18 12:36:20 -04:00
parent f55434acbf
commit 7e92f6aa89
16 changed files with 56 additions and 55 deletions
+7 -2
View File
@@ -42,6 +42,11 @@ export function presetCollection(collection) {
}));
},
fallback: function(geometry) {
var id = geometry;
if (id === 'vertex') id = 'point';
return this.item(id);
},
search: function(value, geometry) {
if (!value) return this;
@@ -153,10 +158,10 @@ export function presetCollection(collection) {
if (geometry) {
if (typeof geometry === 'string') {
results.push(presets.item(geometry));
results.push(presets.fallback(geometry));
} else {
geometry.forEach(function(geom) {
results.push(presets.item(geom));
results.push(presets.fallback(geom));
});
}
}
+15 -4
View File
@@ -84,7 +84,7 @@ export function presetIndex(context) {
if (address && (!match || match.isFallback())) {
match = address;
}
return match || all.item(geometry);
return match || all.fallback(geometry);
};
all.allowsVertex = function(entity, resolver) {
@@ -271,7 +271,7 @@ export function presetIndex(context) {
all.defaults = function(geometry, n) {
var rec = all.recent().matchGeometry(geometry).collection.slice(0, 4);
var def = _uniq(rec.concat(_defaults[geometry].collection)).slice(0, n - 1);
return presetCollection(_uniq(rec.concat(def).concat(all.item(geometry))));
return presetCollection(_uniq(rec.concat(def).concat(all.fallback(geometry))));
};
all.recent = function() {
@@ -307,10 +307,16 @@ export function presetIndex(context) {
function ribbonItemForMinified(d, source) {
if (d && d.pID && d.geom) {
var preset = all.item(d.pID);
if (!preset) return null;
var geom = d.geom;
// treat point and vertex features as one geometry
if (geom === 'vertex') geom = 'point';
// iD's presets could have changed since this was saved,
// so make sure it's still valid.
if (preset && preset.matchGeometry(d.geom)) {
return RibbonItem(preset, d.geom, source);
if (preset.matchGeometry(geom) || (geom === 'point' && preset.matchGeometry('vertex'))) {
return RibbonItem(preset, geom, source);
}
}
return null;
@@ -364,6 +370,7 @@ export function presetIndex(context) {
};
all.toggleFavorite = function(preset, geometry) {
geometry = all.fallback(geometry).id;
var favs = all.getFavorites();
var favorite = all.favoriteMatching(preset, geometry);
if (favorite) {
@@ -381,6 +388,7 @@ export function presetIndex(context) {
};
all.removeFavorite = function(preset, geometry) {
geometry = all.fallback(geometry).id;
var item = all.favoriteMatching(preset, geometry);
if (item) {
var items = all.getFavorites();
@@ -399,6 +407,7 @@ export function presetIndex(context) {
};
all.favoriteMatching = function(preset, geometry) {
geometry = all.fallback(geometry).id;
var favs = all.getFavorites();
for (var index in favs) {
if (favs[index].matches(preset, geometry)) {
@@ -408,6 +417,7 @@ export function presetIndex(context) {
return null;
};
all.recentMatching = function(preset, geometry) {
geometry = all.fallback(geometry).id;
var items = all.getRecents();
for (var index in items) {
if (items[index].matches(preset, geometry)) {
@@ -439,6 +449,7 @@ export function presetIndex(context) {
};
all.setMostRecent = function(preset, geometry) {
geometry = all.fallback(geometry).id;
if (preset.searchable === false) return;
var items = all.getRecents();
+2 -2
View File
@@ -121,7 +121,7 @@ export function uiModes(context) {
if (d.preset.setTags({}, d.geometry).building) {
tooltipTitleID = 'modes.add_preset.building.title';
} else {
tooltipTitleID = 'modes.add_preset.' + d.geometry + '.title';
tooltipTitleID = 'modes.add_preset.' + context.presets().fallback(d.geometry).id + '.title';
}
}
var protoMode = _clone(d);
@@ -209,7 +209,7 @@ export function uiModes(context) {
} else {
d3_select(this)
.call(uiPresetIcon()
.geometry(d.geometry)
.geometry((d.geometry === 'point' && !d.preset.matchGeometry(d.geometry)) ? 'vertex' : d.geometry)
.preset(d.preset)
.sizeClass('small')
);
+2
View File
@@ -8,6 +8,8 @@ import { svgIcon } from '../svg';
export function uiPresetFavorite(preset, geom, context, klass) {
geom = context.presets().fallback(geom).id;
var presetFavorite = {};
var _button = d3_select(null);
+1 -1
View File
@@ -361,7 +361,7 @@ export function uiSearchAdd(context) {
if (d.preset.setTags({}, d.geometry).building) {
return t('presets.presets.building.name');
}
return t('modes.add_' + d.geometry + '.title');
return t('modes.add_' + context.presets().fallback(d.geometry).id + '.title');
}
return d.preset.name();
});