@@ -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 }
0 commit comments