diff --git a/contribs/gmf/src/layertree/common.scss b/contribs/gmf/src/layertree/common.scss
index 9605624b7c3..5074d62da99 100644
--- a/contribs/gmf/src/layertree/common.scss
+++ b/contribs/gmf/src/layertree/common.scss
@@ -194,6 +194,6 @@
}
}
.gmf-layer-being-swipe {
- margin: 0 15px;
+ margin-left: 0.25rem;
}
}
diff --git a/contribs/gmf/src/layertree/component.html b/contribs/gmf/src/layertree/component.html
index 41112b4705c..d81e374da0d 100644
--- a/contribs/gmf/src/layertree/component.html
+++ b/contribs/gmf/src/layertree/component.html
@@ -79,7 +79,7 @@
-
-
+
+
-
-
+
diff --git a/src/map/swipe.js b/src/map/swipe.js
index 03014b62551..be892337dd6 100644
--- a/src/map/swipe.js
+++ b/src/map/swipe.js
@@ -1,6 +1,11 @@
import angular from 'angular';
import {listen, unlistenByKey} from 'ol/events.js';
import RenderEvent from 'ol/render/Event.js';
+
+import ResizeObserver from 'resize-observer-polyfill';
+import 'jquery-ui/ui/widgets/draggable.js';
+
+
/**
* @type {angular.IModule}
* @hidden
@@ -77,25 +82,26 @@ class SwipeController {
/**
* @type {number}
*/
- this.swipeValue = 50;
+ this.swipeValue = 0.5;
/**
* @type {JQuery}
* @private
*/
- this.swipeInput_ = $element.find('.swipe-input');
+ this.draggableElement_ = $element.find('.ngeo-swipe-line-draggable');
/**
- * @type {JQuery}
+ * @type {import("ol/events.js").EventsKey[]}
* @private
*/
- this.swipeOutput_ = $element.find('.swipe-output');
+ this.layerKeys_ = [];
/**
- * @type {import("ol/events.js").EventsKey[]}
+ * @type {ResizeObserver}
* @private
*/
- this.layerKeys_ = [];
+ this.resizeObserver_;
+
}
/**
@@ -105,17 +111,27 @@ class SwipeController {
this.layerKeys_.push(listen(this.layer, 'prerender', this.handleLayerPrerender_, this));
this.layerKeys_.push(listen(this.layer, 'postrender', this.handleLayerPostrender_, this));
- this.swipeOutput_.css({
- 'left': `${this.swipeValue}%`
+ const halfDraggableWidth = this.draggableElement_.width() / 2;
+
+ this.draggableElement_.draggable({
+ axis: 'x',
+ containment: 'parent',
+ drag: () => {
+ const parentWidth = this.draggableElement_.parent().width();
+ const position = this.draggableElement_.position().left + halfDraggableWidth;
+
+ this.swipeValue = position / parentWidth;
+
+ this.map.render();
+ }
});
- this.swipeInput_.on('input change', event => {
- this.swipeValue = Number($(event.target).val());
- this.map.render();
- this.swipeOutput_.css({
- 'left': `${this.swipeValue}%`
- });
+ // keep the same percentage when the parent is resized
+ this.resizeObserver_ = new ResizeObserver(() => {
+ const parentWidth = this.draggableElement_.parent().width();
+ this.draggableElement_.css('left', (parentWidth * this.swipeValue) - halfDraggableWidth);
});
+ this.resizeObserver_.observe(this.draggableElement_.parent().get(0));
}
/**
@@ -130,7 +146,7 @@ class SwipeController {
if (!ctx) {
return;
}
- const width = ctx.canvas.width * (this.swipeValue / 100);
+ const width = ctx.canvas.width * this.swipeValue;
ctx.save();
ctx.beginPath();
ctx.rect(0, 0, width, ctx.canvas.height);
@@ -154,7 +170,8 @@ class SwipeController {
$onDestroy() {
this.layerKeys_.forEach(unlistenByKey);
this.layerKeys_.length = 0;
- this.swipeInput_.off();
+ this.draggableElement_.draggable('destroy');
+ this.resizeObserver_.disconnect();
}
}
diff --git a/tsconfig.json b/tsconfig.json
index 2d3df2e1ebe..c1c99728c01 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -23,6 +23,7 @@
"moment": ["node_modules/moment/moment.d.ts"],
"jsts/*": ["node_modules/@types/jsts/index.d.ts"],
"localforage/*": ["node_modules/localforage/*"],
+ "resize-observer-polyfill": ["node_modules/resize-observer-polyfill/src/index.d.ts"],
}
},
"include": [