Skip to content

Commit

Permalink
Permalink have the map swipe value. (#5263)
Browse files Browse the repository at this point in the history
 Permalink get map swipe value
  • Loading branch information
RBcote committed Oct 30, 2019
1 parent 5b783d7 commit 9721abb
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 5 deletions.
3 changes: 2 additions & 1 deletion contribs/gmf/apps/desktop/index.html.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@
<ngeo-mapswipe
ng-if="mainCtrl.gmfLayerBeingSwipe.layer != null"
map="::mainCtrl.map"
layer="::mainCtrl.gmfLayerBeingSwipe.layer">
layer="::mainCtrl.gmfLayerBeingSwipe.layer"
swipe-value="mainCtrl.gmfLayerBeingSwipe.swipeValue">
</ngeo-mapswipe>
<ngeo-displaywindow
content="mainCtrl.displaywindowContent"
Expand Down
3 changes: 2 additions & 1 deletion contribs/gmf/apps/desktop_alt/index.html.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@
<ngeo-mapswipe
ng-if="mainCtrl.gmfLayerBeingSwipe.layer != null"
map="::mainCtrl.map"
layer="::mainCtrl.gmfLayerBeingSwipe.layer">
layer="::mainCtrl.gmfLayerBeingSwipe.layer"
swipe-value="mainCtrl.gmfLayerBeingSwipe.swipeValue">
</ngeo-mapswipe>
<ngeo-displaywindow
content="mainCtrl.displaywindowContent"
Expand Down
4 changes: 3 additions & 1 deletion contribs/gmf/src/datasource/LayerBeingSwipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import angular from 'angular';
* @property {import('ol/Map.js').default} map
* @property {?import("ol/layer/Layer.js").default<import('ol/source/Source.js').default>
* |import("ol/layer/Group.js").default} layer;
* @property {number} swipeValue;
*/

/**
Expand All @@ -14,7 +15,8 @@ import angular from 'angular';
*/
const module = angular.module('gmfLayerBeingSwipe', []);
module.value('gmfLayerBeingSwipe', {
layer: null
layer: null,
swipeValue: null
});

export default module;
1 change: 1 addition & 0 deletions contribs/gmf/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const PermalinkParam = {
FEATURES: 'rl_features',
MAP_CROSSHAIR: 'map_crosshair',
MAP_SWIPE: 'map_swipe',
MAP_SWIPE_VALUE: 'map_swipe_value',
MAP_TOOLTIP: 'map_tooltip',
MAP_X: 'map_x',
MAP_Y: 'map_y',
Expand Down
32 changes: 32 additions & 0 deletions contribs/gmf/src/permalink/Permalink.js
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,11 @@ export function PermalinkService(
() => this.gmfLayerBeingSwipe_.layer,
this.handleLayerBeingSwipeChange_.bind(this));

// Watch map swipe value.
this.rootScope_.$watch(
() => this.gmfLayerBeingSwipe_.swipeValue,
this.handleMapSwipeValue_.bind(this));

// External DataSources

/**
Expand Down Expand Up @@ -709,11 +714,31 @@ PermalinkService.prototype.handleLayerBeingSwipeChange_ = function(layer, oldLay
if (layer) {
/** @type {Object<string, object>} */
const object = {};
const mapSwipeValue = this.gmfLayerBeingSwipe_.swipeValue;
if (mapSwipeValue === null) {
this.gmfLayerBeingSwipe_.swipeValue = 0.5;
}
const dataSourceId = layer.get('dataSourceId');
object[PermalinkParam.MAP_SWIPE] = dataSourceId;
object[PermalinkParam.MAP_SWIPE_VALUE] = mapSwipeValue;
this.ngeoStateManager_.updateState(object);
} else {
this.ngeoStateManager_.deleteParam(PermalinkParam.MAP_SWIPE);
this.ngeoStateManager_.deleteParam(PermalinkParam.MAP_SWIPE_VALUE);
}
};

/**
* Called when map swipe value change.
* @private
*/
PermalinkService.prototype.handleMapSwipeValue_ = function() {
const mapSwipeValue = this.gmfLayerBeingSwipe_.swipeValue;
/** @type {Object<string, object>} */
const object = {};
if (mapSwipeValue && mapSwipeValue !== null && mapSwipeValue !== undefined) {
object[PermalinkParam.MAP_SWIPE_VALUE] = mapSwipeValue;
this.ngeoStateManager_.updateState(object);
}
};

Expand Down Expand Up @@ -1284,6 +1309,10 @@ PermalinkService.prototype.initLayers_ = function() {
// Get the layerBeingSwipe value from Permalink.
const layerBeingSwipeValue = this.ngeoStateManager_.getInitialNumberValue(
PermalinkParam.MAP_SWIPE);
// Get the map swipe value from Permalink.
const mapSwipeValue = this.ngeoStateManager_.getInitialNumberValue(
PermalinkParam.MAP_SWIPE_VALUE
);
/**
* Enable the layers and set the opacity
* @param {import('ngeo/layertree/Controller.js').LayertreeController} treeCtrl Controller
Expand All @@ -1308,6 +1337,9 @@ PermalinkService.prototype.initLayers_ = function() {
// === Set the gmfLayerBeingSwipe layer ===
if (layerBeingSwipeValue !== null && layerBeingSwipeValue !== undefined
&& treeCtrl.layer.get('dataSourceId') === layerBeingSwipeValue) {
if (mapSwipeValue !== null && mapSwipeValue !== undefined) {
this.gmfLayerBeingSwipe_.swipeValue = mapSwipeValue;
}
this.gmfLayerBeingSwipe_.layer = treeCtrl.layer;
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/map/swipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class SwipeController {
/**
* @type {number}
*/
this.swipeValue = 0.5;
this.swipeValue;

/**
* @type {JQuery}
Expand All @@ -108,6 +108,7 @@ class SwipeController {
* Init the controller
*/
$onInit() {
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));

Expand Down Expand Up @@ -179,7 +180,8 @@ module.component('ngeoMapswipe', {
controller: SwipeController,
bindings: {
map: '<',
layer: '<'
layer: '<',
swipeValue: '='
},
templateUrl: ngeoMapswipeTemplateUrl
});
Expand Down

0 comments on commit 9721abb

Please sign in to comment.