Skip to content

Commit

Permalink
Use live bound object for presets object, change context.presets() ge…
Browse files Browse the repository at this point in the history
…tter
  • Loading branch information
bhousel committed Nov 14, 2016
1 parent 93d50b4 commit 9b7d79a
Show file tree
Hide file tree
Showing 24 changed files with 393 additions and 331 deletions.
59 changes: 52 additions & 7 deletions API.md
Expand Up @@ -145,7 +145,7 @@ certain parts of the iD code to be replaced at runtime by custom code or data.

iD is written in a modular style and bundled with [rollup.js](http://rollupjs.org/),
which makes hot code replacement tricky. (ES6 module exports are
[immutable bindings](http://www.2ality.com/2015/07/es6-module-exports.html)).
[immutable live bindings](http://www.2ality.com/2015/07/es6-module-exports.html)).
Because of this, the parts of iD which are designed for customization are exported
as live bound objects that can be overriden at runtime _before initializing the iD context_.

Expand All @@ -169,7 +169,9 @@ delete iD.services.mapillary;
### Background Imagery

iD's background imagery database is stored in the `iD.data.imagery` array and can be
overridden. (Note that the "None" and "Custom" options will always be shown in the list)
overridden or modified prior to creating the iD context.

Note that the "None" and "Custom" options will always be shown in the list.

To remove all imagery from iD:
```js
Expand Down Expand Up @@ -213,16 +215,59 @@ For more details about the `iD.data.imagery` structure, see

### Presets

iD can use external presets exclusively or along with the default OpenStreetMap presets. This is configured using the `context.presets` accessor. To use external presets alone, initialize the iD context with a custom `Presets` object:
iD's preset database is stored in the `iD.data.presets` object and can be overridden
or modified prior to creating the iD context.

```js
The format of the `presets` object is
[documented here](https://github.com/openstreetmap/iD/tree/master/data/presets#custom-presets).

var id = iD.Context()
.presets(customPresets);
To add a new preset to iD's existing preset database.
```js
iD.data.presets.presets["aerialway/zipline"] = {
geometry: ["line"],
fields: ["incline"],
tags: { "aerialway": "zip_line" },
name: "Zipline"
};
```

To completely replace iD's default presets with your own:
```js
iD.data.presets = myPresets;
```

The format of the Preset object is [documented here](https://github.com/openstreetmap/iD/tree/master/data/presets#custom-presets).
To run iD with the minimal set of presets that only match basic geometry types:
```js
iD.data.presets = {
presets: {
"area": {
"name": "Area",
"tags": {},
"geometry": ["area"]
},
"line": {
"name": "Line",
"tags": {},
"geometry": ["line"]
},
"point": {
"name": "Point",
"tags": {},
"geometry": ["point"]
},
"vertex": {
"name": "Vertex",
"tags": {},
"geometry": ["vertex"]
},
"relation": {
"name": "Relation",
"tags": {},
"geometry": ["relation"]
}
}
};
```


### Minimum Editable Zoom
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,9 @@
* :warning: Flattened namespace means that all functions have changed names (#3479)
* e.g. `iD.actions.Move` -> `iD.actionMove`, `iD.geo.Extent` -> `iD.geoExtent`
* Many deprecated names are still exported as symbols, e.g. `iD.Context` - we will remove these eventually
* :warning: Customized iD deployments can manipulate live objects, rather than iD.Context accessors
* No longer need to call things like `presets()`, `imagery()`, `taginfo()` when creating `iD.Context`
* See [API.md](https://github.com/openstreetmap/iD/blob/master/API.md#customized-deployments) for details on customized deployments
* :warning: iD has upgraded to the latest released versions of d3, lodash, rbush, etc.
* d3 no longer adds itself to the global namespace, but can now be accessed via `iD.d3`
* :warning: iD now uses `npm` scripts for all build processes
Expand Down
17 changes: 8 additions & 9 deletions data/index.js
Expand Up @@ -12,19 +12,18 @@ export { default as dataImperial } from './imperial.json';
export { default as dataDriveLeft } from './drive-left.json';
export { en as dataEn } from '../dist/locales/en.json';

import { dataImagery } from './imagery.json';
import { presets } from './presets/presets.json';
import { defaults } from './presets/defaults.json';
import { categories } from './presets/categories.json';
import { fields } from './presets/fields.json';

export var dataPresets = {
presets: presets,
defaults: defaults,
categories: categories,
fields: fields
};

import { dataImagery } from './imagery.json';
export var data = {
imagery: dataImagery
imagery: dataImagery,
presets: {
presets: presets,
defaults: defaults,
categories: categories,
fields: fields
}
};
6 changes: 6 additions & 0 deletions data/presets/README.md
Expand Up @@ -274,6 +274,12 @@ For example:
"tags": {},
"geometry": ["vertex"],
"matchScore": 0.1
},
"relation": {
"name": "Relation",
"tags": {},
"geometry": ["relation"],
"matchScore": 0.1
}
```

Expand Down
4 changes: 1 addition & 3 deletions dist/index.html
Expand Up @@ -37,9 +37,7 @@
document.getElementById('id-container').innerHTML = 'Sorry, your browser is not currently supported. Please use Potlatch 2 to edit the map.';
document.getElementById('id-container').className = 'unsupported';
} else {
var id = iD.Context()
.presets(iD.dataPresets);

var id = iD.Context();
id.ui()(document.getElementById('id-container'));
}
</script>
Expand Down
1 change: 0 additions & 1 deletion index.html
Expand Up @@ -19,7 +19,6 @@
<script>

id = iD.Context()
.presets(iD.dataPresets)
.assetPath('dist/');

id.ui()(document.getElementById('id-container'), function() {
Expand Down
21 changes: 9 additions & 12 deletions modules/core/context.js
Expand Up @@ -5,7 +5,7 @@ import { coreHistory } from './history';
import { dataLocales, dataEn } from '../../data/index';
import { geoRawMercator } from '../geo/raw_mercator';
import { modeSelect } from '../modes/select';
import { presetInit } from '../presets/init';
import { presetIndex } from '../presets/index';
import { rendererBackground } from '../renderer/background';
import { rendererFeatures } from '../renderer/features';
import { rendererMap } from '../renderer/map';
Expand Down Expand Up @@ -212,6 +212,11 @@ export function coreContext() {
};


/* Presets */
var presets;
context.presets = function() { return presets; };


/* Map */
var map;
context.map = function() { return map; };
Expand Down Expand Up @@ -249,16 +254,6 @@ export function coreContext() {
};


/* Presets */
var presets;
context.presets = function(_) {
if (!arguments.length) return presets;
presets.load(_);
areaKeys = presets.areaKeys();
return context;
};


/* Container */
var container, embed;
context.container = function(_) {
Expand Down Expand Up @@ -389,6 +384,7 @@ export function coreContext() {

background = rendererBackground(context);
features = rendererFeatures(context);
presets = presetIndex();

map = rendererMap(context);
context.mouse = map.mouse;
Expand All @@ -401,7 +397,8 @@ export function coreContext() {
context.redrawEnable = map.redrawEnable;

background.init();
presets = presetInit();
presets.init();
areaKeys = presets.areaKeys();

_.each(services, function(service) {
if (service && typeof service.init === 'function') {
Expand Down
16 changes: 10 additions & 6 deletions modules/modes/select.js
Expand Up @@ -244,10 +244,11 @@ export function modeSelect(context, selectedIDs) {
return;
}

var parent = singularParent();
if (parent) {
surface.selectAll('.related')
.classed('related', false);
surface.selectAll('.related')
.classed('related', false);

singularParent();
if (relatedParent) {
surface.selectAll(utilEntitySelector([relatedParent]))
.classed('related', true);
}
Expand Down Expand Up @@ -363,8 +364,11 @@ export function modeSelect(context, selectedIDs) {
var surface = context.surface();
surface.selectAll('.related')
.classed('related', false);
surface.selectAll(utilEntitySelector([relatedParent]))
.classed('related', true);

if (relatedParent) {
surface.selectAll(utilEntitySelector([relatedParent]))
.classed('related', true);
}
}


Expand Down

0 comments on commit 9b7d79a

Please sign in to comment.