Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit annotations #769

Merged
merged 4 commits into from
Feb 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions examples/annotations/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ block append mainContent
.annotation.point Left click to create a point.
.annotation.line Left-click points in the line. Double click, right click, or click the starting point to end the line.
.form-group(title='If enabled, left-click to add another annotation, and right-click to switch annotation type. Otherwise, you must click a button above.')
label(for='clickadd') Click to add annotation
input#clickadd(param-name='clickadd', type='checkbox', placeholder='true', checked='checked')
label(for='clickmode') Click mode
select#clickmode(param-name='clickmode', placeholder='edit')
option(value='edit') Select and Edit
option(value='add') Add New
option(value='none') None
.form-group(title='If enabled, immediately after adding one annotation, you can add another without either left-clicking or selecting a button.')
label(for='keepadding') Keep adding annotations
input#keepadding(param-name='keepadding', type='checkbox', placeholder='false')
Expand All @@ -31,6 +34,7 @@ block append mainContent
#annotationlist
.entry#sample
span.entry-name Sample
a.entry-adjust(action='adjust', title='Modify geometry') ✜
a.entry-edit(action='edit', title='Edit name and properties') ✎
a.entry-remove(action='remove', title='Delete this annotation') ✖
.form-group
Expand Down
12 changes: 5 additions & 7 deletions examples/annotations/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,14 @@
display: inline-block;
}
.entry .entry-name {
width: 86%;
width: 82%;
}
.entry .entry-edit {
width: 7%;
.entry a {
width: 6%;
text-align: right;
font-weight: bold;
}
.entry .entry-remove {
width: 7%;
text-align: right;
.entry .entry-edit {
font-weight: bold;
}
.entry-remove-all {
float: right;
Expand Down
15 changes: 12 additions & 3 deletions examples/annotations/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ $(function () {

// get the query parameters and set controls appropriately
var query = utils.getQuery();
$('#clickadd').prop('checked', query.clickadd !== 'false');
$('#clickmode').val(query.clickmode || 'edit');
$('#keepadding').prop('checked', query.keepadding === 'true');
$('#showLabels').prop('checked', query.labels !== 'false');
if (query.lastannotation) {
Expand Down Expand Up @@ -54,7 +54,8 @@ $(function () {
layer = map.createLayer('annotation', {
renderer: query.renderer ? (query.renderer === 'html' ? null : query.renderer) : undefined,
annotations: query.renderer ? undefined : geo.listAnnotations(),
showLabels: query.labels !== 'false'
showLabels: query.labels !== 'false',
clickToEdit: !query.clickmode || query.clickmode === 'edit'
});
// bind to the mouse click and annotation mode events
layer.geoOn(geo.event.mouseclick, mouseClickToStart);
Expand Down Expand Up @@ -92,7 +93,7 @@ $(function () {
* @param {geo.event} evt geojs event.
*/
function mouseClickToStart(evt) {
if (evt.handled || query.clickadd === 'false') {
if (evt.handled || query.clickmode !== 'add') {
return;
}
if (evt.buttonsDown.left) {
Expand Down Expand Up @@ -129,6 +130,10 @@ $(function () {
layer.options('showLabels', '' + value !== 'false');
layer.draw();
break;
case 'clickmode':
layer.options('clickToEdit', value === 'edit');
layer.draw();
break;
}
query[param] = value;
if (value === '' || (ctl.attr('placeholder') &&
Expand Down Expand Up @@ -274,6 +279,10 @@ $(function () {
id = ctl.closest('.entry').attr('annotation-id'),
annotation = layer.annotationById(id);
switch (action) {
case 'adjust':
layer.mode(layer.modes.edit, annotation);
layer.draw();
break;
case 'edit':
show_edit_dialog(id, annotation);
break;
Expand Down
3 changes: 2 additions & 1 deletion src/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ var geo_action = {
// annotation actions
annotation_line: 'geo_annotation_line',
annotation_polygon: 'geo_annotation_polygon',
annotation_rectangle: 'geo_annotation_rectangle'
annotation_rectangle: 'geo_annotation_rectangle',
annotation_edit_handle: 'geo_annotation_edit_handle'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we just call it annotation_edit? or would that be confusing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may eventually want other edit actions. For instance, suppose we supported an action on selecting the annotation in edit mode, then it might be edit_select to differentiate it.

};

module.exports = geo_action;
Loading