-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix 667 - Allow multiple selection in query
- Loading branch information
Showing
7 changed files
with
251 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default { | ||
ADD: 'add', | ||
REMOVE: 'remove', | ||
REPLACE: 'replace' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import ngeoQueryAction from 'ngeo/query/Action.js'; | ||
|
||
import {listen as olEventsListen} from 'ol/events.js'; | ||
|
||
/** | ||
* @module ngeo.query.Keyboard | ||
*/ | ||
class Keyboard { | ||
|
||
/** | ||
* Listens to the keyboard `keydown` and `keyup` events to keep | ||
* track of the query action to do depending on the key being | ||
* pressed. | ||
*/ | ||
constructor() { | ||
|
||
// Constants | ||
|
||
/** | ||
* The key to press for "ADD" action | ||
* @type {string} | ||
* @private | ||
*/ | ||
this.keyAdd_ = 'a'; | ||
|
||
/** | ||
* The key to press for "REMOVE" action | ||
* @type {string} | ||
* @private | ||
*/ | ||
this.keyRemove_ = 'x'; | ||
|
||
/** | ||
* @type {Array.<string>} | ||
* @private | ||
*/ | ||
this.keys_ = [this.keyAdd_, this.keyRemove_]; | ||
|
||
// Variables | ||
|
||
/** | ||
* The key currently being pressed. Only those registered in | ||
* `this.keys_` can be active. | ||
* @type {?string} | ||
* @private | ||
*/ | ||
this.activeKey_ = null; | ||
|
||
// Event listeners | ||
olEventsListen(document, 'keydown', this.handleKeyDown_, this); | ||
olEventsListen(document, 'keyup', this.handleKeyUp_, this); | ||
} | ||
|
||
// Getters | ||
|
||
/** | ||
* @return {string} The query action depending on the key currently | ||
* being pressed. | ||
*/ | ||
get action() { | ||
let action = ngeoQueryAction.REPLACE; | ||
if (this.activeKey_) { | ||
if (this.activeKey_ === this.keyAdd_) { | ||
action = ngeoQueryAction.ADD; | ||
} else if (this.activeKey_ === this.keyRemove_) { | ||
action = ngeoQueryAction.REMOVE; | ||
} | ||
} | ||
return action; | ||
} | ||
|
||
// Handlers | ||
|
||
/** | ||
* @param {KeyboardEvent} evt Event. | ||
* @private | ||
*/ | ||
handleKeyDown_(evt) { | ||
if (!this.activeKey_ && this.keys_.includes(evt.key)) { | ||
this.activeKey_ = evt.key; | ||
} | ||
} | ||
|
||
/** | ||
* @param {KeyboardEvent} evt Event. | ||
* @private | ||
*/ | ||
handleKeyUp_(evt) { | ||
if (this.activeKey_ && this.activeKey_ === evt.key) { | ||
this.activeKey_ = null; | ||
} | ||
} | ||
} | ||
|
||
export default new Keyboard(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.