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

Manage map view rotation and map swipe #5490

Merged
merged 1 commit into from
Feb 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 26 additions & 6 deletions src/map/swipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class SwipeController {
* @type {import("ol/events.js").EventsKey[]}
* @private
*/
this.layerKeys_ = [];
this.listenerKeys_ = [];

/**
* @type {ResizeObserver}
Expand All @@ -130,13 +130,22 @@ class SwipeController {
* Init the controller
*/
$onInit() {
const view = this.map.getView();

this.swipeValue = this.swipeValue !== undefined ? this.swipeValue : 0.5;
this.layerKeys_.push(listen(this.layer, 'prerender', this.handleLayerPrerender_, this));
this.layerKeys_.push(listen(this.layer, 'postrender', this.handleLayerPostrender_, this));
this.layerKeys_.push(listen(this.layer, 'change:visible', this.handleLayerVisibleChange_, this));
this.listenerKeys_.push(listen(this.layer, 'prerender', this.handleLayerPrerender_, this));
this.listenerKeys_.push(listen(this.layer, 'postrender', this.handleLayerPostrender_, this));
this.listenerKeys_.push(listen(this.layer, 'change:visible', this.handleLayerVisibleChange_, this));
this.listenerKeys_.push(listen(view, 'change:rotation', this.handleViewRotationChange_, this));

const halfDraggableWidth = this.draggableElement_.width() / 2;

// When beginning to swipe a layer, reset the view rotation
const rotation = view.getRotation();
if (rotation) {
view.setRotation(0);
}

this.draggableElement_.draggable({
axis: 'x',
containment: 'parent',
Expand Down Expand Up @@ -210,9 +219,20 @@ class SwipeController {
}
}

/**
* Called when the rotation of the view changes. If the view is
* rotated, deactivate the swipe component.
* @private
*/
handleViewRotationChange_() {
if (this.map.getView().getRotation()) {
this.deactivate();
}
}

$onDestroy() {
this.layerKeys_.forEach(unlistenByKey);
this.layerKeys_.length = 0;
this.listenerKeys_.forEach(unlistenByKey);
this.listenerKeys_.length = 0;
this.draggableElement_.draggable('destroy');
this.resizeObserver_.disconnect();
}
Expand Down