Skip to content

Instantly share code, notes, and snippets.

@bhousel
Last active August 29, 2015 14:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhousel/0af881a621a2efb83719 to your computer and use it in GitHub Desktop.
Save bhousel/0af881a621a2efb83719 to your computer and use it in GitHub Desktop.
Hotkey to change some tags on all selected entities in #iD
context = id;
addTags = { building: 'yes' };
removeTags = ['area','natural','landuse'];
function changeTags() {
var actions = [],
entities = _.filter(_.map(context.selectedIDs(), context.entity),
function(entity) { return entity.geometry(context.graph()) === 'area'; });
_.each(entities, function(entity) {
var newTags = _.omit(_.merge(_.clone(entity.tags), addTags), removeTags);
actions.push(iD.actions.ChangeTags(entity.id, newTags));
});
if (actions.length) {
actions.push(t('operations.change_tags.annotation'));
context.perform.apply(context, actions);
}
}
myKeybinding = d3.keybinding('changeTags')
.on(iD.ui.cmd('⌘B'), changeTags);
d3.select(document).call(myKeybinding);
@davidshumway
Copy link

So it is coming along quite nicely. In fact it is close to road-testing. However, there is a caveat, which is the autofocus for "Search features". How would you add to the list of keybindings that are ignored by the search field when it is autofocused? Basically to be able to add dynamically create the list of ignored keybindings based on which hotkeys the user currently has selected. Is this correct?

This feels related to iD.ui.PresetList = function(context) {}. Specifically: https://gist.github.com/their/9827eac41f19b44bd5de. Is this in the context id on the page? Is it modifiable? Everything else looks great thus far.

@davidshumway
Copy link

Progress at https://github.com/their/OSM-iD-Browser-Tools. After autofocus it is pretty much down to features "add new area" and "orthogonalize".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment