Skip to content

Commit f795280

Browse files
authored
Merge pull request #1397 from OpenGeoscience/annotation-mode-event-data
perf: Add more information to annotation mode change events
2 parents ecd1e3c + 8367575 commit f795280

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/annotationLayer.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -678,10 +678,12 @@ var annotationLayer = function (arg) {
678678
* edited or used.
679679
* @param {object} [options] Additional options to pass when creating an
680680
* annotation.
681+
* @param {string} [reason] An optional reason to pass to the
682+
* `geo.event.annotation.mode` event.
681683
* @returns {string|null|this} The current mode or the layer.
682684
* @fires geo.event.annotation.mode
683685
*/
684-
this.mode = function (arg, editAnnotation, options) {
686+
this.mode = function (arg, editAnnotation, options, reason) {
685687
if (arg === undefined) {
686688
return m_mode;
687689
}
@@ -701,11 +703,13 @@ var annotationLayer = function (arg) {
701703
m_keyHandler = Mousetrap(mapNode[0]);
702704
}
703705
if (m_mode) {
704-
m_keyHandler.bind('esc', function () { m_this.mode(null); });
706+
m_keyHandler.bind('esc', function () { m_this.mode(null, undefined, undefined, 'escape'); });
705707
} else {
706708
m_keyHandler.unbind('esc');
707709
}
710+
let oldState;
708711
if (m_this.currentAnnotation) {
712+
oldState = m_this.currentAnnotation.state();
709713
switch (m_this.currentAnnotation.state()) {
710714
case geo_annotation.state.create:
711715
m_this.removeAnnotation(m_this.currentAnnotation);
@@ -754,7 +758,7 @@ var annotationLayer = function (arg) {
754758
});
755759
}
756760
m_this.geoTrigger(geo_event.annotation.mode, {
757-
mode: m_mode, oldMode: oldMode});
761+
mode: m_mode, oldMode: oldMode, oldState: oldState, reason: reason});
758762
if (oldMode === m_this.modes.edit || oldMode === m_this.modes.cursor) {
759763
m_this.modified();
760764
}

src/event.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,9 +746,15 @@ geo_event.annotation.state = 'geo_annotation_state';
746746
* @event geo.event.annotation.mode
747747
* @type {geo.event.base}
748748
* @property {string?} mode The new annotation mode. This is one of the values
749-
* from {@link geo.annotation.state}.
749+
* from {@link geo.annotationLayer.mode} or an annotation name.
750750
* @property {string?} oldMode The annotation mode before this change. This is
751+
* one of the values from {@link geo.annotationLayer.mode} or an
752+
* annotation name.
753+
* @property {string?} oldState If there was an active annotation before the
754+
* mode change, this is the annotation state before the change. This is
751755
* one of the values from {@link geo.annotation.state}.
756+
* @property {string?} reason An optional string that was passed to the mode
757+
* change method.
752758
*/
753759
geo_event.annotation.mode = 'geo_annotation_mode';
754760

0 commit comments

Comments
 (0)