Change features to disable_features querystring, add init()

This commit is contained in:
Bryan Housel
2017-10-22 12:00:51 -06:00
parent 3332847beb
commit 469df0b059
3 changed files with 18 additions and 16 deletions

10
API.md
View File

@@ -20,6 +20,10 @@ in the hash portion of the URL:
`{z}`/`{zoom}`, `{ty}` for flipped TMS-style Y coordinates, and `{switch:a,b,c}` for
DNS multiplexing.<br/>
_Example:_ `background=custom:https://{switch:a,b,c}.tile.openstreetmap.org/{zoom}/{x}/{y}.png`
* __`disable_features`__ - Disables features in the list.<br/>
_Example:_ `disable_features=water,service_roads,points,paths,boundaries`<br/>
_Available features:_ `points` `traffic_roads` `service_roads` `paths` `buildings` `landuse`
`boundaries` `water` `rail` `power` `past_future` `others`
* __`gpx`__ - A custom URL for loading a gpx track. Specifying a `gpx` parameter will
automatically enable the gpx layer for display.<br/>
_Example:_ `gpx=https://tasks.hotosm.org/project/592/task/16.gpx`
@@ -34,10 +38,6 @@ in the hash portion of the URL:
_Example:_ `hashtags=%23hotosm-task-592,%23MissingMaps`
* __`rtl=true`__ - Force iD into right-to-left mode (useful for testing).
* __`walkthrough=true`__ - Start the walkthrough automatically
* __`features`__ - Enables features in the list.<br/>
_Example:_ `features=water,service_roads,points,paths`<br/>
_Available features:_ `points` `traffic_roads` `service_roads` `paths` `buildings` `landuse`
`boundaries` `water` `rail` `power` `past_future` `others`
##### iD on openstreetmap.org (Rails Port)
@@ -49,12 +49,12 @@ are available as regular URL query parameters:
* __`lat`__, __`lon`__, __`zoom`__ - Self-explanatory.
* __`node`__, __`way`__, __`relation`__ - Select the specified entity.
* __`background`__ - same as standalone
* __`disable_features`__ - same as standalone
* __`gpx`__ - same as standalone
* __`offset`__ - same as standalone
* __`comment`__ - same as standalone
* __`hashtags`__ - same as standalone
* __`walkthrough`__ - same as standalone
* __`features`__ - same as standalone
## CSS selectors

View File

@@ -471,6 +471,7 @@ export function coreContext() {
});
background.init();
features.init();
presets.init();
areaKeys = presets.areaKeys();

View File

@@ -3,7 +3,6 @@ import _groupBy from 'lodash-es/groupBy';
import _reduce from 'lodash-es/reduce';
import _some from 'lodash-es/some';
import _union from 'lodash-es/union';
import _get from 'lodash-es/get';
import { dispatch as d3_dispatch } from 'd3-dispatch';
@@ -65,16 +64,13 @@ export function rendererFeatures(context) {
_features = {},
_stats = {},
_keys = [],
_hidden = [],
_initFeaturesStr = _get(utilStringQs(window.location.hash.substring(1)), 'features', '').trim();
_hidden = [];
function update() {
var q = utilStringQs(window.location.hash.substring(1));
q.features = context.features().enabledList();
if (!window.mocha) {
var q = utilStringQs(window.location.hash.substring(1));
q.disable_features = features.disabled().join(',');
window.location.replace('#' + utilQsString(q, true));
}
@@ -87,10 +83,6 @@ export function rendererFeatures(context) {
function defineFeature(k, filter, max) {
var isEnabled = true;
if (_initFeaturesStr.length) {
isEnabled = _initFeaturesStr.split(',').some(function(key){ return key === k; });
}
_keys.push(k);
_features[k] = {
filter: filter,
@@ -506,5 +498,14 @@ export function rendererFeatures(context) {
};
features.init = function() {
var q = utilStringQs(window.location.hash.substring(1));
if (q.disable_features) {
q.disable_features.replace(/;/g, ',').split(',').map(function(k) {
features.disable(k);
});
}
};
return utilRebind(features, dispatch, 'on');
}