mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 21:48:20 +02:00
Add tests and documentation for custom presets
This commit is contained in:
committed by
John Firebaugh
parent
dffeedffc9
commit
c8d4b73b15
@@ -91,3 +91,61 @@ To build presets, all you need to do is run `make`.
|
||||
This command will take care of running the build script, which packages all presets
|
||||
together with imagery data, and deprecated or discarded tags into one file, `data/data.js`,
|
||||
which is included in the packaged iD.js file.
|
||||
|
||||
## Custom Presets
|
||||
|
||||
iD supports deployments which use a custom set of presets. You can supply presets via
|
||||
the `presets` accessor:
|
||||
|
||||
```js
|
||||
var id = iD().presets({
|
||||
presets: { ... },
|
||||
fields: { ... },
|
||||
defaults: { ... },
|
||||
categories: { ... }
|
||||
});
|
||||
```
|
||||
|
||||
All four parts (presets, fields, defaults, and categories) must be supplied. In addition,
|
||||
several base presets and fields must be included.
|
||||
|
||||
Basic geometric presets must be included so that every feature matches at least one preset.
|
||||
For example:
|
||||
|
||||
```js
|
||||
"area": {
|
||||
"name": "Area",
|
||||
"tags": {},
|
||||
"geometry": ["area"],
|
||||
"matchScore": 0.1
|
||||
},
|
||||
"line": {
|
||||
"name": "Line",
|
||||
"tags": {},
|
||||
"geometry": ["line"],
|
||||
"matchScore": 0.1
|
||||
},
|
||||
"point": {
|
||||
"name": "Point",
|
||||
"tags": {},
|
||||
"geometry": ["point"],
|
||||
"matchScore": 0.1
|
||||
},
|
||||
"vertex": {
|
||||
"name": "Other",
|
||||
"tags": {},
|
||||
"geometry": ["vertex"],
|
||||
"matchScore": 0.1
|
||||
}
|
||||
```
|
||||
|
||||
A "name" field must be included:
|
||||
|
||||
```js
|
||||
"name": {
|
||||
"key": "name",
|
||||
"type": "localized",
|
||||
"label": "Name",
|
||||
"placeholder": "Common name (if any)"
|
||||
}
|
||||
```
|
||||
|
||||
@@ -296,6 +296,7 @@
|
||||
<script src="spec/presets/preset.js"></script>
|
||||
<script src="spec/presets/collection.js"></script>
|
||||
<script src="spec/presets/category.js"></script>
|
||||
<script src="spec/id.js"></script>
|
||||
|
||||
<script>
|
||||
iD.data.load('../', function() {
|
||||
|
||||
@@ -107,6 +107,7 @@
|
||||
<script src="spec/presets/preset.js"></script>
|
||||
<script src="spec/presets/collection.js"></script>
|
||||
<script src="spec/presets/category.js"></script>
|
||||
<script src="spec/id.js"></script>
|
||||
|
||||
<script>
|
||||
(window.mochaPhantomJS || window.mocha).run();
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
describe('iD', function() {
|
||||
describe("#presets", function() {
|
||||
it("supports custom presets", function() {
|
||||
var presetsCollection = {
|
||||
presets: {
|
||||
'mines': {
|
||||
geometry: ['point', 'area'],
|
||||
name: 'Mining Concession',
|
||||
tags: {
|
||||
'concession': 'mining'
|
||||
}
|
||||
},
|
||||
'area': {
|
||||
'name': 'Area',
|
||||
'tags': {},
|
||||
'geometry': ['area']
|
||||
},
|
||||
'point': {
|
||||
'name': 'Point',
|
||||
'tags': {},
|
||||
'geometry': ['point']
|
||||
},
|
||||
'line': {
|
||||
'name': 'Line',
|
||||
'tags': {},
|
||||
'geometry': ['line']
|
||||
},
|
||||
'vertex': {
|
||||
'name': 'Other',
|
||||
'tags': {},
|
||||
'geometry': ['vertex']
|
||||
}
|
||||
},
|
||||
fields: {
|
||||
'name': {
|
||||
'key': 'name',
|
||||
'type': 'localized',
|
||||
'label': 'Name',
|
||||
'placeholder': 'Common name (if any)'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var context = iD().presets(presetsCollection),
|
||||
way = iD.Way({tags: {concession: 'mining', area: 'yes'}}),
|
||||
graph = iD.Graph([way]);
|
||||
|
||||
expect(context.presets().match(way, graph).id).to.eql('mines');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user