Skip to content

Commit

Permalink
addfeature + clear
Browse files Browse the repository at this point in the history
  • Loading branch information
mstenta committed May 6, 2023
1 parent 67b8332 commit ea2d5e1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/behavior/measure.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ export default {
// If the instance has an Edit control, attach listeners to the map
// interactions so that we can apply measurements to the features.
if (instance.edit) {
instance.edit.addInteractionListener('addfeature', (geojson, event) => {
createMeasure(event.feature);
});
instance.edit.addInteractionListener('drawstart', (geojson, event) => {
startMeasure(event.feature);
});
Expand Down Expand Up @@ -165,6 +168,9 @@ export default {
instance.edit.addInteractionListener('disable', () => {
stopMeasure();
});
instance.edit.addInteractionListener('clear', () => {
stopMeasure();
});
}
},
};
4 changes: 4 additions & 0 deletions src/control/Edit/Edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class Edit extends Control {
// user via addInteractionListener(). Each event type will be an array of
// objects, each with a callback and a format.
this.eventListeners = {
addfeature: [],
drawstart: [],
drawend: [],
modifystart: [],
Expand All @@ -132,6 +133,7 @@ class Edit extends Control {
select: [],
delete: [],
disable: [],
clear: [],
};
}

Expand Down Expand Up @@ -484,6 +486,7 @@ class Edit extends Control {
*/
addInteractionListener(type, cb, format = new GeoJSON()) {
const validTypes = [
'addfeature',
'drawstart',
'drawend',
'modifystart',
Expand All @@ -494,6 +497,7 @@ class Edit extends Control {
'select',
'delete',
'disable',
'clear',
];
if (!validTypes.includes(type)) {
throw new Error(`Invalid event type. Valid options include: ${validTypes.join(', ')}`);
Expand Down

0 comments on commit ea2d5e1

Please sign in to comment.