mirror of
https://github.com/FoggedLens/iD.git
synced 2026-06-05 14:38:05 +02:00
re-add preset category support
This commit is contained in:
+4
-2
@@ -159,6 +159,7 @@
|
||||
|
||||
<script src='js/id/presets.js'></script>
|
||||
<script src='js/id/presets/preset.js'></script>
|
||||
<script src='js/id/presets/category.js'></script>
|
||||
<script src='js/id/presets/presets.js'></script>
|
||||
|
||||
<script src='js/id/connection.js'></script>
|
||||
@@ -189,14 +190,15 @@
|
||||
|
||||
var id = iD();
|
||||
|
||||
iD.util.asyncMap(['keys.json', 'presets/presets.json', 'presets/defaults.json'], d3.json, function(err, data) {
|
||||
iD.util.asyncMap(['keys.json', 'presets/presets.json', 'presets/defaults.json', 'presets/categories.json'], d3.json, function(err, data) {
|
||||
id.connection()
|
||||
.keys(data[0]);
|
||||
|
||||
id.presets()
|
||||
.load({
|
||||
presets: data[1],
|
||||
defaults: data[2]
|
||||
defaults: data[2],
|
||||
categories: data[3]
|
||||
});
|
||||
|
||||
d3.select("#iD")
|
||||
|
||||
+11
-5
@@ -1,5 +1,8 @@
|
||||
iD.presets = function(context) {
|
||||
|
||||
// an iD.presets.Collection with methods for
|
||||
// loading new data and returning defaults
|
||||
|
||||
var other = {
|
||||
name: 'other',
|
||||
title: 'Other',
|
||||
@@ -10,27 +13,30 @@ iD.presets = function(context) {
|
||||
},
|
||||
form: []
|
||||
},
|
||||
all = iD.presets.Collection(context, [iD.presets.Preset(other)]),
|
||||
all = iD.presets.Collection([iD.presets.Preset(other)]),
|
||||
defaults = {};
|
||||
|
||||
all.load = function(d) {
|
||||
|
||||
if (d.presets) {
|
||||
d.presets.forEach(function(d) {
|
||||
all.collection.push(iD.presets.Preset(d));
|
||||
});
|
||||
}
|
||||
|
||||
if (d.categories) {
|
||||
d.categories.forEach(function(d) {
|
||||
all.collection.push(iD.presets.Category(d, all));
|
||||
});
|
||||
}
|
||||
|
||||
if (d.defaults) {
|
||||
var getItem = _.bind(all.item, all);
|
||||
defaults = {
|
||||
area: iD.presets.Collection(context, d.defaults.area.map(getItem)),
|
||||
line: iD.presets.Collection(context, d.defaults.line.map(getItem)),
|
||||
point: iD.presets.Collection(context, d.defaults.point.map(getItem)),
|
||||
vertex: iD.presets.Collection(context, d.defaults.vertex.map(getItem))
|
||||
area: iD.presets.Collection(d.defaults.area.map(getItem)),
|
||||
line: iD.presets.Collection(d.defaults.line.map(getItem)),
|
||||
point: iD.presets.Collection(d.defaults.point.map(getItem)),
|
||||
vertex: iD.presets.Collection(d.defaults.vertex.map(getItem))
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
iD.presets.Category = function(category, all) {
|
||||
|
||||
category.members = iD.presets.Collection(category.members.map(function(name) {
|
||||
return all.item(name);
|
||||
}));
|
||||
|
||||
category.matchType = function(entity, resolver) {
|
||||
return category.match.type.indexOf(entity.geometry(resolver)) >= 0;
|
||||
};
|
||||
|
||||
category.matchTags = function() { return false; };
|
||||
|
||||
return category;
|
||||
};
|
||||
@@ -1,34 +1,21 @@
|
||||
iD.presets.Collection = function(context, collection) {
|
||||
iD.presets.Collection = function(collection) {
|
||||
|
||||
var presets = {
|
||||
|
||||
collection: collection,
|
||||
|
||||
load: function(_) {
|
||||
if (_.presets) {
|
||||
_.presets.forEach(function(d) {
|
||||
collection.push(iD.presets.Preset(d));
|
||||
});
|
||||
}
|
||||
if (_.categories) {
|
||||
_.categories.forEach(function(d) {
|
||||
collection.push(iD.presets.Category(d, presets));
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
item: function(id) {
|
||||
return _.find(collection, function(d) {
|
||||
return d.name === id;
|
||||
});
|
||||
},
|
||||
|
||||
matchType: function(entity) {
|
||||
matchType: function(entity, resolver) {
|
||||
var newcollection = collection.filter(function(d) {
|
||||
return d.matchType(entity, context.graph());
|
||||
return d.matchType(entity, resolver);
|
||||
});
|
||||
|
||||
return iD.presets.Collection(context, newcollection);
|
||||
return iD.presets.Collection(newcollection);
|
||||
|
||||
},
|
||||
|
||||
@@ -55,7 +42,7 @@ iD.presets.Collection = function(context, collection) {
|
||||
|
||||
// Uses levenshtein distance, with a couple of hacks
|
||||
// to prioritize exact substring matches
|
||||
return iD.presets.Collection(context, collection.sort(function(a, b) {
|
||||
return iD.presets.Collection(collection.sort(function(a, b) {
|
||||
var ia = a.name.indexOf(value) >= 0,
|
||||
ib = b.name.indexOf(value) >= 0;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ iD.ui.PresetGrid = function(context) {
|
||||
|
||||
selection.html('');
|
||||
|
||||
presets = presets.matchType(entity);
|
||||
presets = presets.matchType(entity, context.graph());
|
||||
|
||||
var messagewrap = selection.append('div')
|
||||
.attr('class', 'message inspector-inner fillL');
|
||||
@@ -54,8 +54,8 @@ iD.ui.PresetGrid = function(context) {
|
||||
// Category
|
||||
if (d.members) {
|
||||
search.property('value', '');
|
||||
viable = presetData.categories(d.name);
|
||||
drawGrid(selection, viable);
|
||||
presets = d.members;
|
||||
drawGrid(selection, presets);
|
||||
|
||||
// Preset
|
||||
} else {
|
||||
|
||||
@@ -44,7 +44,7 @@ iD.ui.TagEditor = function(context) {
|
||||
}
|
||||
}
|
||||
|
||||
presetMatch = preset || presetMatch || presets.matchType(entity).matchTags(entity);
|
||||
presetMatch = preset || presetMatch || presets.matchType(entity, context.graph()).matchTags(entity);
|
||||
|
||||
selection.html('');
|
||||
|
||||
@@ -163,7 +163,7 @@ iD.ui.TagEditor = function(context) {
|
||||
if (presetUI && tagList) {
|
||||
|
||||
// change preset if necessary (undos/redos)
|
||||
var newmatch = presets.matchType(entity).matchTags(entity.update({ tags: tags }));
|
||||
var newmatch = presets.matchType(entity, context.graph()).matchTags(entity.update({ tags: tags }));
|
||||
if (newmatch !== presetMatch) {
|
||||
return tageditor(selection_, newmatch);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
[
|
||||
{
|
||||
"match": {
|
||||
"type": "line"
|
||||
},
|
||||
"icon": "road",
|
||||
"name": "roads",
|
||||
"members": [
|
||||
"residential road",
|
||||
"primary road"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user