Skip to content

Commit

Permalink
Merge pull request #5914 from openstreetmap/squash-favorite-preset
Browse files Browse the repository at this point in the history
Favorite preset
  • Loading branch information
quincylvania committed Feb 27, 2019
2 parents d613714 + 6bdb59c commit 29dfdf8
Show file tree
Hide file tree
Showing 19 changed files with 293 additions and 46 deletions.
2 changes: 1 addition & 1 deletion css/55_cursors.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
cursor: url(img/cursor-select-remove.png), pointer; /* FF */
}

.mode-add-preset #map,
.mode-draw-line #map,
.mode-draw-area #map,
.mode-add-line #map,
Expand Down Expand Up @@ -104,4 +105,3 @@
.turn circle {
cursor: pointer;
}

53 changes: 51 additions & 2 deletions css/80_app.css
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,33 @@ button[disabled].action:hover {
padding: 0 10px;
min-width: 30px;
white-space: nowrap;
display: flex;
}
[dir='ltr'] .tool-group button.add-preset.add-point,
[dir='ltr'] .tool-group button.add-preset.add-point .label {
padding-left: 0px;
}
[dir='ltr'] .tool-group button.add-preset:not(.add-point) {
padding-left: 5px;
}
[dir='ltr'] .tool-group button.add-preset:not(.add-point) .label {
padding-left: 3px;
}
[dir='rtl'] .tool-group button.add-preset.add-point,
[dir='rtl'] .tool-group button.add-preset.add-point .label {
padding-right: 0px;
}
.tool-group button .icon {
[dir='rtl'] .tool-group button.add-preset:not(.add-point) {
padding-right: 5px;
}
[dir='rtl'] .tool-group button.add-preset:not(.add-point) .label {
padding-right: 3px;
}
.narrow .tool-group button.add-preset {
padding-right: 0 !important;
padding-left: 0 !important;
}
.tool-group button > .icon {
flex: 0 0 20px;
}
.tool-group button .label {
Expand Down Expand Up @@ -970,6 +995,10 @@ a.hide-toggle {
height: 60px;
text-align: center;
}
#bar .preset-icon-container {
width: 40px;
height: 40px;
}

.preset-icon-line {
margin: auto;
Expand Down Expand Up @@ -1111,28 +1140,47 @@ a.hide-toggle {
background-color: #ececec;
}

.preset-list-item button.preset-favorite-button,
.preset-list-item button.tag-reference-button {
height: 100%;
border: 1px solid #ccc;
flex: 32px;
background: #f6f6f6;
}
[dir='ltr'] .preset-list-item button.preset-favorite-button,
[dir='ltr'] .preset-list-item button.tag-reference-button {
border-left: none;
border-radius: 0 4px 4px 0;
border-radius: 0;
}
[dir='rtl'] .preset-list-item button.preset-favorite-button,
[dir='rtl'] .preset-list-item button.tag-reference-button {
border-right: none;
border-radius: 0;
}
[dir='ltr'] .preset-list-item button:last-child {
border-radius: 0 4px 4px 0;
}
[dir='rtl'] .preset-list-item button:last-child {
border-radius: 4px 0 0 4px;
}

.preset-list-item button.preset-favorite-button:hover,
.preset-list-item button.tag-reference-button:hover {
background: #f1f1f1;
}
.preset-list-item button.preset-favorite-button .icon,
.preset-list-item button.tag-reference-button .icon {
opacity: .5;
}

.preset-list-item button.preset-favorite-button .icon {
fill-opacity: 0;
stroke-width: 1.6;
}
.preset-list-item button.preset-favorite-button.active .icon {
fill-opacity: inherit;
}

img.tag-reference-wiki-image {
float: right;
width: 33.3333%;
Expand Down Expand Up @@ -2435,6 +2483,7 @@ input.key-trap {

/* hide and remove from layout */
.inspector-hidden,
.inspector-hover .preset-list-button-wrap .preset-favorite-button,
.inspector-hover .preset-list-button-wrap .tag-reference-button,
.inspector-hover label input[type="checkbox"],
.inspector-hover label input[type="radio"],
Expand Down
9 changes: 9 additions & 0 deletions data/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ en:
zoom_to: zoom to
copy: copy
open_wikidata: open on wikidata.org
favorite: favorite
modes:
add_area:
title: Area
Expand All @@ -24,6 +25,14 @@ en:
title: Note
description: "Spotted an issue? Let other mappers know."
tail: Click on the map to add a note.
add_preset:
title: "Add {feature}"
point:
title: "Add {feature} as a point"
line:
title: "Add {feature} as a line"
area:
title: "Add {feature} as an area"
browse:
title: Browse
description: Pan and zoom the map.
Expand Down
15 changes: 14 additions & 1 deletion dist/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"undo": "undo",
"zoom_to": "zoom to",
"copy": "copy",
"open_wikidata": "open on wikidata.org"
"open_wikidata": "open on wikidata.org",
"favorite": "favorite"
},
"modes": {
"add_area": {
Expand All @@ -30,6 +31,18 @@
"description": "Spotted an issue? Let other mappers know.",
"tail": "Click on the map to add a note."
},
"add_preset": {
"title": "Add {feature}",
"point": {
"title": "Add {feature} as a point"
},
"line": {
"title": "Add {feature} as a line"
},
"area": {
"title": "Add {feature} as an area"
}
},
"browse": {
"title": "Browse",
"description": "Pan and zoom the map."
Expand Down
2 changes: 1 addition & 1 deletion modules/behavior/draw_way.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export function behaviorDrawWay(context, wayID, index, mode, startGraph, baselin
window.setTimeout(function() {
context.map().dblclickEnable(true);
}, 1000);
var isNewFeature = !mode.isContinuing;
var isNewFeature = !mode.isContinuing && mode.button.indexOf('add-preset-') === -1;
context.enter(modeSelect(context, [wayID]).newFeature(isNewFeature));
if (isNewFeature) {
context.validator().validate();
Expand Down
34 changes: 33 additions & 1 deletion modules/core/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function coreContext() {
addTranslation('en', dataEn);
setLocale('en');

var dispatch = d3_dispatch('enter', 'exit', 'change');
var dispatch = d3_dispatch('enter', 'exit', 'change', 'favoritePreset');

// https://github.com/openstreetmap/iD/issues/772
// http://mathiasbynens.be/notes/localstorage-pattern#comment-9
Expand Down Expand Up @@ -312,7 +312,39 @@ export function coreContext() {
/* Presets */
var presets;
context.presets = function() { return presets; };
//get favorites from local storage
context.getFavoritePresets = function() {
return JSON.parse(context.storage('favorite_presets')) || [];
};
context.favoritePreset = function(preset, geom) {
var favs = context.getFavoritePresets();

//add/remove favorites from local storage
if (context.isFavoritePreset(preset, geom)) {
favs = favs.filter(function(d) {
return !(d.id === preset.id && d.geom === geom);
});
} else {
// only allow 3 favorites
if (favs.length === 3) {
// remove the last favorite (first in, first out)
favs.pop();
}
// prepend array
favs.unshift({id: preset.id, geom: geom});
}

context.storage('favorite_presets', JSON.stringify(favs));

//and call update on modes
dispatch.call('favoritePreset');
};
context.isFavoritePreset = function(preset, geom) {
var favs = context.getFavoritePresets();
return favs.some(function(d) {
return d.id === preset.id && d.geom === geom;
});
};

/* Map */
var map;
Expand Down
11 changes: 6 additions & 5 deletions modules/modes/add_area.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { modeDrawArea } from './index';
import { osmNode, osmWay } from '../osm';


export function modeAddArea(context) {
var mode = {
export function modeAddArea(context, customMode) {
var mode = customMode || {
id: 'add-area',
button: 'area',
title: t('modes.add_area.title'),
Expand All @@ -26,6 +26,7 @@ export function modeAddArea(context) {
.on('startFromNode', startFromNode);

var defaultTags = { area: 'yes' };
if (mode.preset) defaultTags = mode.preset.setTags(defaultTags, 'area');


function actionClose(wayId) {
Expand All @@ -47,7 +48,7 @@ export function modeAddArea(context) {
actionClose(way.id)
);

context.enter(modeDrawArea(context, way.id, startGraph, context.graph()));
context.enter(modeDrawArea(context, way.id, startGraph, context.graph(), mode.button));
}


Expand All @@ -64,7 +65,7 @@ export function modeAddArea(context) {
actionAddMidpoint({ loc: loc, edge: edge }, node)
);

context.enter(modeDrawArea(context, way.id, startGraph, context.graph()));
context.enter(modeDrawArea(context, way.id, startGraph, context.graph(), mode.button));
}


Expand All @@ -78,7 +79,7 @@ export function modeAddArea(context) {
actionClose(way.id)
);

context.enter(modeDrawArea(context, way.id, startGraph, context.graph()));
context.enter(modeDrawArea(context, way.id, startGraph, context.graph(), mode.button));
}


Expand Down
19 changes: 11 additions & 8 deletions modules/modes/add_line.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { modeDrawLine } from './index';
import { osmNode, osmWay } from '../osm';


export function modeAddLine(context) {
var mode = {
export function modeAddLine(context, customMode) {
var mode = customMode || {
id: 'add-line',
button: 'line',
title: t('modes.add_line.title'),
Expand All @@ -25,26 +25,29 @@ export function modeAddLine(context) {
.on('startFromWay', startFromWay)
.on('startFromNode', startFromNode);

var defaultTags = {};
if (mode.preset) defaultTags = mode.preset.setTags(defaultTags, 'line');


function start(loc) {
var startGraph = context.graph();
var node = osmNode({ loc: loc });
var way = osmWay();
var way = osmWay({ tags: defaultTags });

context.perform(
actionAddEntity(node),
actionAddEntity(way),
actionAddVertex(way.id, node.id)
);

context.enter(modeDrawLine(context, way.id, startGraph, context.graph()));
context.enter(modeDrawLine(context, way.id, startGraph, context.graph(), mode.button));
}


function startFromWay(loc, edge) {
var startGraph = context.graph();
var node = osmNode({ loc: loc });
var way = osmWay();
var way = osmWay({ tags: defaultTags });

context.perform(
actionAddEntity(node),
Expand All @@ -53,20 +56,20 @@ export function modeAddLine(context) {
actionAddMidpoint({ loc: loc, edge: edge }, node)
);

context.enter(modeDrawLine(context, way.id, startGraph, context.graph()));
context.enter(modeDrawLine(context, way.id, startGraph, context.graph(), mode.button));
}


function startFromNode(node) {
var startGraph = context.graph();
var way = osmWay();
var way = osmWay({ tags: defaultTags });

context.perform(
actionAddEntity(way),
actionAddVertex(way.id, node.id)
);

context.enter(modeDrawLine(context, way.id, startGraph, context.graph()));
context.enter(modeDrawLine(context, way.id, startGraph, context.graph(), mode.button));
}


Expand Down
15 changes: 9 additions & 6 deletions modules/modes/add_point.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { osmNode } from '../osm';
import { actionAddMidpoint } from '../actions';


export function modeAddPoint(context) {
var mode = {
export function modeAddPoint(context, customMode) {
var mode = customMode || {
id: 'add-point',
button: 'point',
title: t('modes.add_point.title'),
Expand All @@ -23,31 +23,34 @@ export function modeAddPoint(context) {
.on('cancel', cancel)
.on('finish', cancel);

var defaultTags = {};
if (mode.preset) defaultTags = mode.preset.setTags(defaultTags, 'point');


function add(loc) {
var node = osmNode({ loc: loc });
var node = osmNode({ loc: loc, tags: defaultTags });

context.perform(
actionAddEntity(node),
t('operations.add.annotation.point')
);

context.enter(
modeSelect(context, [node.id]).newFeature(true)
modeSelect(context, [node.id]).newFeature(!mode.preset)
);
}


function addWay(loc, edge) {
var node = osmNode();
var node = osmNode({ tags: defaultTags });

context.perform(
actionAddMidpoint({loc: loc, edge: edge}, node),
t('operations.add.annotation.vertex')
);

context.enter(
modeSelect(context, [node.id]).newFeature(true)
modeSelect(context, [node.id]).newFeature(!mode.preset)
);
}

Expand Down
Loading

0 comments on commit 29dfdf8

Please sign in to comment.