mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-12 16:52:50 +00:00
Limit addable presets via comma-separated IDs in the presets URL parameter (close #6553)
This commit is contained in:
3
API.md
3
API.md
@@ -43,8 +43,9 @@ of iD (e.g. `http://preview.ideditor.com/release/`), the following parameters ar
|
||||
* __`photo_overlay`__ - The street-level photo overlay layers to enable.<br/>
|
||||
_Example:_ `photo_overlay=streetside,mapillary,openstreetcam`<br/>
|
||||
_Available values:_ `streetside` (Microsoft Bing), `mapillary`, `mapillary-signs`, `openstreetcam`
|
||||
* __`presets`__ - A path to an external presets file.<br/>
|
||||
* __`presets`__ - A path to an external presets file or a comma-separated list of preset IDs. These will be the only presets the user may select.<br/>
|
||||
_Example:_ `presets=https://path/to/presets.json`
|
||||
_Example 2:_ `presets=building,highway/residential,highway/unclassified`
|
||||
* __`rtl=true`__ - Force iD into right-to-left mode (useful for testing).
|
||||
* __`source`__ - Prefills the changeset source. Pass a url encoded string.<br/>
|
||||
_Example:_ `source=Bing%3BMapillary`
|
||||
|
||||
@@ -558,8 +558,10 @@ export function coreContext() {
|
||||
features.init();
|
||||
photos.init();
|
||||
|
||||
if (utilStringQs(window.location.hash).presets) {
|
||||
var external = utilStringQs(window.location.hash).presets;
|
||||
var presetsParameter = utilStringQs(window.location.hash).presets;
|
||||
if (presetsParameter && presetsParameter.indexOf('://') !== -1) {
|
||||
// assume URL of external presets file
|
||||
|
||||
presets.fromExternal(external, function(externalPresets) {
|
||||
context.presets = function() { return externalPresets; }; // default + external presets...
|
||||
osmSetAreaKeys(presets.areaKeys());
|
||||
@@ -567,7 +569,15 @@ export function coreContext() {
|
||||
osmSetVertexTags(presets.vertexTags());
|
||||
});
|
||||
} else {
|
||||
presets.init();
|
||||
var isVisible;
|
||||
if (presetsParameter) {
|
||||
// assume list of allowed preset IDs
|
||||
var visiblePresetIDs = new Set(presetsParameter.split(','));
|
||||
isVisible = function(presetID) {
|
||||
return visiblePresetIDs.has(presetID);
|
||||
};
|
||||
}
|
||||
presets.init(isVisible);
|
||||
osmSetAreaKeys(presets.areaKeys());
|
||||
osmSetPointTags(presets.pointTags());
|
||||
osmSetVertexTags(presets.vertexTags());
|
||||
|
||||
@@ -199,10 +199,11 @@ export function presetIndex(context) {
|
||||
Object.keys(d.presets).forEach(function(id) {
|
||||
var p = d.presets[id];
|
||||
var existing = all.index(id);
|
||||
var isVisible = typeof visible === 'function' ? visible(id, p) : visible;
|
||||
if (existing !== -1) {
|
||||
all.collection[existing] = presetPreset(id, p, _fields, visible, rawPresets);
|
||||
all.collection[existing] = presetPreset(id, p, _fields, isVisible, rawPresets);
|
||||
} else {
|
||||
all.collection.push(presetPreset(id, p, _fields, visible, rawPresets));
|
||||
all.collection.push(presetPreset(id, p, _fields, isVisible, rawPresets));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -244,7 +245,7 @@ export function presetIndex(context) {
|
||||
return all;
|
||||
};
|
||||
|
||||
all.init = function() {
|
||||
all.init = function(shouldShow) {
|
||||
all.collection = [];
|
||||
_favorites = null;
|
||||
_recents = null;
|
||||
@@ -252,7 +253,7 @@ export function presetIndex(context) {
|
||||
_universal = [];
|
||||
_index = { point: {}, vertex: {}, line: {}, area: {}, relation: {} };
|
||||
|
||||
return all.build(data.presets, true);
|
||||
return all.build(data.presets, shouldShow || true);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -167,7 +167,11 @@ export function uiPresetList(context) {
|
||||
function drawList(list, presets) {
|
||||
var collection = presets.collection.reduce(function(collection, preset) {
|
||||
if (preset.members) {
|
||||
collection.push(CategoryItem(preset));
|
||||
if (preset.members.collection.filter(function(preset) {
|
||||
return preset.visible();
|
||||
}).length > 1) {
|
||||
collection.push(CategoryItem(preset));
|
||||
}
|
||||
} else if (preset.visible()) {
|
||||
collection.push(PresetItem(preset));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user