Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add the features api parameter which enables the list of features #4439

Merged
merged 6 commits into from
Oct 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ 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)

Expand All @@ -50,6 +54,7 @@ are available as regular URL query parameters:
* __`comment`__ - same as standalone
* __`hashtags`__ - same as standalone
* __`walkthrough`__ - same as standalone
* __`features`__ - same as standalone


## CSS selectors
Expand Down
50 changes: 48 additions & 2 deletions modules/renderer/features.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ 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';

import { osmEntity } from '../osm';
import { utilRebind } from '../util/rebind';
import {
utilQsString,
utilStringQs
} from '../util';


export function rendererFeatures(context) {
Expand Down Expand Up @@ -60,21 +65,36 @@ export function rendererFeatures(context) {
_features = {},
_stats = {},
_keys = [],
_hidden = [];
_hidden = [],
_initFeaturesStr = _get(utilStringQs(window.location.hash.substring(1)), 'features', '').trim();


function update() {
var q = utilStringQs(window.location.hash.substring(1));

q.features = context.features().enabledList();

if (!window.mocha) {
window.location.replace('#' + utilQsString(q, true));
}

_hidden = features.hidden();
dispatch.call('change');
dispatch.call('redraw');
}


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,
enabled: true, // whether the user wants it enabled..
enabled: isEnabled, // whether the user wants it enabled..
count: 0,
currentMax: (max || Infinity),
defaultMax: (max || Infinity),
Expand Down Expand Up @@ -197,6 +217,10 @@ export function rendererFeatures(context) {
return _features[k] && _features[k].enabled;
};

features.enabledList = function () {
return _keys.filter(function(k) { return _features[k].enabled; });
};


features.disabled = function(k) {
if (!arguments.length) {
Expand Down Expand Up @@ -229,6 +253,28 @@ export function rendererFeatures(context) {
}
};

features.enableList = function (enabledKeys) {
var keysForToggle = {};

for (var i = 0; i < _keys.length; i++) {
keysForToggle[_keys[i]] = false;
}

for (i = 0; i < enabledKeys.length; i++) {
if (_features[enabledKeys[i]]) {
keysForToggle[enabledKeys[i]] = true;
}
}

for (i = 0; i < _keys.length; i++) {
if (keysForToggle[_keys[i]]) {
_features[_keys[i]].enable();
} else {
_features[_keys[i]].disable();
}
}
};


features.disable = function(k) {
if (_features[k] && _features[k].enabled) {
Expand Down