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

LayerSwipe feature #2804

Draft
wants to merge 63 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
25a72e6
add new constraint "swipeAlignment"
taulinger Jan 9, 2025
157149d
add new tool "compare"
taulinger Jan 9, 2025
92e1a8c
add new tool "compare" (2)
taulinger Jan 9, 2025
7d13058
allow modification of constraint "swipeAlignment"
taulinger Jan 9, 2025
0582e0a
add getLayerGroup()
taulinger Jan 9, 2025
5e67a52
add s-o-s "layerSwipe"
taulinger Jan 9, 2025
cd93b84
register layerSwipeReducer
taulinger Jan 9, 2025
88459b5
make doc:check happy
taulinger Jan 10, 2025
dff47ea
add an OlMapHandler that realizes a layer swipe feature
taulinger Jan 10, 2025
4aaf2bc
register OlLayerSwipeHandler
taulinger Jan 10, 2025
024d06d
register OlLayerSwipeHandler
taulinger Jan 10, 2025
e8c1268
adjust test
taulinger Jan 10, 2025
55ecdb4
allow modification of constraints "hidden" and "alwaysTop"
taulinger Jan 10, 2025
dfaba25
adjust to layers.action change
taulinger Jan 10, 2025
879c611
remove SwipeAlignment.BOTH
taulinger Jan 10, 2025
836c092
add test for enum SwipeAlignment
taulinger Jan 10, 2025
03494c5
adjust enum values
taulinger Jan 10, 2025
6c62ce1
handle placeholder layers
taulinger Jan 14, 2025
12646e2
add plugin to handle tool "COMPARE"
taulinger Jan 14, 2025
9c418a3
register ComparePlugin
taulinger Jan 14, 2025
13d44c1
register ComparePlugin
taulinger Jan 14, 2025
59efec0
make doc:check happy
taulinger Jan 14, 2025
8dca3d2
check if WebGL is supported
taulinger Jan 14, 2025
3069c96
Add compare button
alsturm Jan 15, 2025
c2ab057
observe also the layerSwipe ratio property
taulinger Jan 15, 2025
3941810
add layer swipe related params
taulinger Jan 15, 2025
96962fe
handle layer swipe related params
taulinger Jan 15, 2025
59caf5f
handle layer swipeAlignment param
taulinger Jan 15, 2025
c7bfd2a
handle SWIPE_RATIO query param
taulinger Jan 15, 2025
8ceaf42
AtomicallyAddLayerOptions: allow constraints
taulinger Jan 15, 2025
1946254
fix broken test
taulinger Jan 15, 2025
7dfe6f0
Merge branch 'master' into feat_layer-swipe
taulinger Jan 16, 2025
6af7faa
Add LayerSwipeSlider component
alsturm Jan 16, 2025
0714b6c
Add layer side buttons
alsturm Jan 16, 2025
93f0535
add button mode
alsturm Jan 16, 2025
563e754
Merge branch 'feat_layer-swipe' of https://github.com/ldbv-by/bav4 in…
alsturm Jan 16, 2025
ed8d4ea
handle possible undefined alignment
taulinger Jan 16, 2025
4b12121
Merge branch 'feat_layer-swipe' of https://github.com/ldbv-by/bav4-no…
taulinger Jan 16, 2025
4abe635
use swipeAlignment
alsturm Jan 16, 2025
99be8d0
style buttons
alsturm Jan 16, 2025
0fe1fb2
add toggle
alsturm Jan 16, 2025
c2b89a9
update tests
alsturm Jan 16, 2025
a9765b4
Merge branch 'feat_layer-swipe' of https://github.com/ldbv-by/bav4 in…
alsturm Jan 16, 2025
e096576
fix lint
alsturm Jan 16, 2025
76210b2
when a oLayer is added to the olMap check first if layersSwipe is active
taulinger Jan 16, 2025
75f6ab5
update e2e test
alsturm Jan 16, 2025
56abae5
when the COMPARE tool is activated always update the active property …
taulinger Jan 16, 2025
81992ca
Merge branch 'feat_layer-swipe' of https://github.com/ldbv-by/bav4-no…
taulinger Jan 16, 2025
80c7f5e
mark toggle() as deprecated
taulinger Jan 16, 2025
4be0240
cleanup
taulinger Jan 16, 2025
0fa3647
add toggleCurrentTool()
taulinger Jan 16, 2025
d7974e2
make prettier happy
taulinger Jan 16, 2025
f0cc4ef
add style and tests
alsturm Jan 21, 2025
69e55ff
add toggleCurrentTool
alsturm Jan 21, 2025
14243fc
add test for layerItem
alsturm Jan 21, 2025
7c0edcb
add i18n and tests
alsturm Jan 21, 2025
dce0ee3
add complete compare button
alsturm Jan 21, 2025
9af12b1
fix z-index
alsturm Jan 21, 2025
dd450d0
fix test
taulinger Jan 22, 2025
35481c9
cleanup
taulinger Jan 22, 2025
8f74288
prettier
alsturm Jan 22, 2025
1cac42c
update test
alsturm Jan 22, 2025
dcffe8b
lint
alsturm Jan 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/domain/queryParameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ export const QueryParameters = Object.freeze({
* The timestamp of a layer (`string`)
*/
LAYER_TIMESTAMP: 'l_t',
/**
* The swipe alignment of a layer (`string`)
*/
LAYER_SWIPE_ALIGNMENT: 'l_sa',
/**
* The swipe ratio of the map (`number`, 0-1)
*/
SWIPE_RATIO: 'sr',
/**
* Currently not supported. The active topic (`string`)
*/
Expand Down
3 changes: 2 additions & 1 deletion src/domain/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export const Tools = Object.freeze({
SHARE: 'share',
IMPORT: 'import',
EXPORT: 'export',
ROUTING: 'routing'
ROUTING: 'routing',
COMPARE: 'compare'
});

/**
Expand Down
1 change: 1 addition & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@
<ba-notification-panel></ba-notification-panel>
<ba-modal></ba-modal>
<ba-map-context-menu></ba-map-context-menu>
<ba-layer-swipe></ba-layer-swipe>
</body>
</html>
2 changes: 2 additions & 0 deletions src/injection/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import { fileStorageServiceFactory } from './factories';
import { FileStoragePlugin } from '../plugins/FileStoragePlugin';
import { TimeTravelPlugin } from '../plugins/TimeTravelPlugin';
import { BvvPredefinedConfigurationService } from '../services/PredefinedConfigurationService';
import { ComparePlugin } from '../plugins/ComparePlugin';

$injector
.registerSingleton('ProjectionService', new Proj4JsService())
Expand Down Expand Up @@ -133,6 +134,7 @@ $injector
.registerSingleton('ObserveWcAttributesPlugin', new ObserveWcAttributesPlugin())
.registerSingleton('EncodeStatePlugin', new EncodeStatePlugin())
.registerSingleton('TimeTravelPlugin', new TimeTravelPlugin())
.registerSingleton('ComparePlugin', new ComparePlugin())
.registerSingleton('ObserveStateForEncodingPlugin', new ObserveStateForEncodingPlugin())
.registerModule(mapModule)
.registerModule(topicsModule)
Expand Down
58 changes: 56 additions & 2 deletions src/modules/layerManager/components/LayerItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ import { fitLayer } from '../../../store/position/position.action';
import { GeoResourceFuture, RtVectorGeoResource, VectorGeoResource } from '../../../domain/geoResources';
import { MenuTypes } from '../../commons/components/overflowMenu/OverflowMenu';
import { openSlider } from '../../../store/timeTravel/timeTravel.action';
import { SwipeAlignment } from '../../../store/layers/layers.action';

const Update_Layer = 'update_layer';
const Update_Layer_Collapsed = 'update_layer_collapsed';
const Update_Layer_Swipe = 'update_layer_swipe';
const Default_Extra_Property_Values = {
collapsed: true,
opacity: 1,
Expand All @@ -47,7 +49,8 @@ const Default_Extra_Property_Values = {
export class LayerItem extends AbstractMvuContentPanel {
constructor() {
super({
layer: null
layer: null,
isLayerSwipeActive: null
});
const { TranslationService, GeoResourceService } = $injector.inject('TranslationService', 'GeoResourceService');
this._translationService = TranslationService;
Expand Down Expand Up @@ -75,9 +78,21 @@ export class LayerItem extends AbstractMvuContentPanel {
};
case Update_Layer_Collapsed:
return { ...model, layer: { ...model.layer, collapsed: data } };
case Update_Layer_Swipe:
return { ...model, ...data };
}
}

/**
* @override
*/
onInitialize() {
this.observe(
(state) => state.layerSwipe,
(layerSwipe) => this.signal(Update_Layer_Swipe, { isLayerSwipeActive: layerSwipe.active })
);
}

/**
* @override
*/
Expand Down Expand Up @@ -110,7 +125,7 @@ export class LayerItem extends AbstractMvuContentPanel {
*/
createView(model) {
const translate = (key) => this._translationService.translate(key);
const { layer } = model;
const { layer, isLayerSwipeActive } = model;

if (!layer) {
return nothing;
Expand Down Expand Up @@ -253,6 +268,44 @@ export class LayerItem extends AbstractMvuContentPanel {
];
};

const leftSide = () => {
modifyLayer(layer.id, { swipeAlignment: SwipeAlignment.LEFT });
};
const bothSide = () => {
modifyLayer(layer.id, { swipeAlignment: SwipeAlignment.NOT_SET });
};
const rightSide = () => {
modifyLayer(layer.id, { swipeAlignment: SwipeAlignment.RIGHT });
};

const getLayerSwipe = () => {
const direction = layer.constraints.swipeAlignment;
return isLayerSwipeActive
? html`
<div class="compare">
<ba-button
id="left"
.type=${direction === SwipeAlignment.LEFT ? 'primary' : 'secondary'}
.label=${translate('layerManager_compare_left')}
@click=${leftSide}
></ba-button>
<ba-button
id="both"
.type=${direction === SwipeAlignment.NOT_SET ? 'primary' : 'secondary'}
.label=${translate('layerManager_compare_both')}
@click=${bothSide}
></ba-button>
<ba-button
id="right"
.type=${direction === SwipeAlignment.RIGHT ? 'primary' : 'secondary'}
.label=${translate('layerManager_compare_right')}
@click=${rightSide}
></ba-button>
</div>
`
: nothing;
};

return html` <style>
${css}
</style>
Expand Down Expand Up @@ -305,6 +358,7 @@ export class LayerItem extends AbstractMvuContentPanel {
<ba-overflow-menu .type=${MenuTypes.MEATBALL} .items=${getMenuItems()}></ba-overflow-menu>
</div>
</div>
${getLayerSwipe()}
</div>`;
}

Expand Down
17 changes: 16 additions & 1 deletion src/modules/layerManager/components/LayerManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import { html, nothing } from 'lit-html';
import { $injector } from '../../../injection';
import { repeat } from 'lit-html/directives/repeat.js';
import { modifyLayer, removeLayer } from './../../../store/layers/layers.action';
import { toggleCurrentTool } from './../../../store/tools/tools.action';
import { Tools } from '../../../domain/tools';
import css from './layerManager.css';
import { MvuElement } from '../../MvuElement';

const Update_Draggable_Items = 'update_draggable_items';
const Update_Collapse_Change = 'update_collapse_change';
const Update_Dragged_Item = 'update_dragged_item';
const Update_Layer_Swipe = 'update_layer_swipe';
/**
* Renders a list of layers representing their order on a map and provides
* actions like reordering, removing and changing visibility and opacity
Expand Down Expand Up @@ -44,6 +47,8 @@ export class LayerManager extends MvuElement {
return { ...model, draggableItems: model.draggableItems.map((i) => (i.id === data.id ? data : i)) };
case Update_Dragged_Item:
return { ...model, draggedItem: data };
case Update_Layer_Swipe:
return { ...model, ...data };
}
}

Expand All @@ -52,6 +57,10 @@ export class LayerManager extends MvuElement {
(store) => store.layers.active,
(active) => this._buildDraggableItems(active.filter((l) => !l.constraints.hidden))
);
this.observe(
(state) => state.layerSwipe,
(layerSwipe) => this.signal(Update_Layer_Swipe, { isLayerSwipeActive: layerSwipe.active })
);
}

/**
Expand Down Expand Up @@ -207,7 +216,7 @@ export class LayerManager extends MvuElement {

_getButtons(model) {
const translate = (key) => this._translationService.translate(key);
const { draggableItems } = model;
const { draggableItems, isLayerSwipeActive } = model;
const expandAll = () => {
this.signal(
Update_Draggable_Items,
Expand Down Expand Up @@ -241,6 +250,12 @@ export class LayerManager extends MvuElement {
style="border-right: 1px dotted var(--header-background-color);"
></ba-button>
<ba-button id="button_remove_all" .label=${translate('layerManager_remove_all')} .type=${'secondary'} @click=${removeAll}></ba-button>
<ba-button
id="button_layer_swipe"
.label=${translate(isLayerSwipeActive ? 'layerManager_compare_stop' : 'layerManager_compare')}
.type=${'secondary'}
@click=${() => toggleCurrentTool(Tools.COMPARE)}
></ba-button>
<div></div>
</div>`
: nothing;
Expand Down
19 changes: 19 additions & 0 deletions src/modules/layerManager/components/layerItem.css
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,22 @@
.time-travel-icon {
margin-right: 0.5em;
}
.compare {
display: flex;
border: 1px solid var(--header-background-color);
align-items: stretch;
border-radius: 0em;
margin: 0.5em 1em 1em 1em;
overflow: hidden;
}
.compare ba-button {
display: flex;
width: 100%;
border-right: 1px dotted var(--primary-color);
}
.compare ba-button:last-child {
border-right: none;
}
.compare ba-button::part(button) {
font-size: 0.7rem !important;
}
4 changes: 4 additions & 0 deletions src/modules/layerManager/components/layerManager.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ li {
justify-content: flex-start;
}

.layermanager__actions ba-button::part(button) {
font-size: 0.95rem;
}

.layermanager__expandOrCollapse {
padding-left: 0.8em;
}
14 changes: 12 additions & 2 deletions src/modules/layerManager/i18n/layerManager.provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ export const provide = (lang) => {
layerManager_expand_all: 'expand all',
layerManager_collapse_all: 'collapse all',
layerManager_remove_all: 'remove all',
layerManager_compare: 'compare',
layerManager_compare_stop: 'compare stop',
layerManager_loading_hint: 'Loading',
layerManager_time_travel_hint: 'Choose a year',
layerManager_time_travel_slider: 'Open slider'
layerManager_time_travel_slider: 'Open slider',
layerManager_compare_left: 'Left',
layerManager_compare_both: 'Both',
layerManager_compare_right: 'Right'
};

case 'de':
Expand All @@ -39,9 +44,14 @@ export const provide = (lang) => {
layerManager_expand_all: 'Alle ausklappen',
layerManager_collapse_all: 'Alle einklappen',
layerManager_remove_all: 'Alle entfernen',
layerManager_compare: 'Vergleichen',
layerManager_compare_stop: 'Vergleichen beenden',
layerManager_loading_hint: 'Wird geladen',
layerManager_time_travel_hint: 'Bitte ein Jahr auswählen',
layerManager_time_travel_slider: 'Schieberegler öffnen'
layerManager_time_travel_slider: 'Schieberegler öffnen',
layerManager_compare_left: 'Links',
layerManager_compare_both: 'Beide',
layerManager_compare_right: 'Rechts'
};

default:
Expand Down
76 changes: 76 additions & 0 deletions src/modules/map/components/layerSwipeSlider/LayerSwipeSlider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* @module modules/map/components/layerSwipeSlider/LayerSwipeSlider
*/
import { html } from 'lit-html';

import { $injector } from '../../../../injection';
import css from './layerSwipeSlider.css';
import { MvuElement } from '../../../MvuElement';
import { updateRatio } from '../../../../store/layerSwipe/layerSwipe.action';
import { nothing } from '../../../../../node_modules/ol/pixel';

const Update_Layer_Swipe = 'update_layer_swipe';

/**
* Component to swipe map layers
* @class
* @author alsturm
*/

export class LayerSwipeSlider extends MvuElement {
constructor() {
super({ active: false, ratio: null });
const { TranslationService } = $injector.inject('TranslationService');
this._translationService = TranslationService;
}

update(type, data, model) {
switch (type) {
case Update_Layer_Swipe:
return { ...model, ...data };
}
}

onInitialize() {
this.observe(
(state) => state.layerSwipe,
(layerSwipe) => this.signal(Update_Layer_Swipe, { active: layerSwipe.active, ratio: layerSwipe.ratio })
);
}

createView(model) {
const { active, ratio } = model;
const translate = (key) => this._translationService.translate(key);

const onChangeSlider = (event) => {
const line = this.shadowRoot.getElementById('line');
line.style.left = parseInt(event.target.value) + '%';

updateRatio(parseInt(event.target.value));
};

return active
? html`
<style>
${css}
</style>
<div id="line" class="line" style="left:${ratio}%"></div>
<div class="layer-swipe">
<input
id="rangeslider"
type="range"
min="0"
max="100"
step="1"
title="${translate('map_layerSwipeSlider')}"
value="${ratio}"
@input=${onChangeSlider}
/>
</div>
`
: nothing;
}
static get tag() {
return 'ba-layer-swipe';
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/modules/map/components/layerSwipeSlider/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { LayerSwipeSlider } from './LayerSwipeSlider';
if (!window.customElements.get(LayerSwipeSlider.tag)) {
window.customElements.define(LayerSwipeSlider.tag, LayerSwipeSlider);
}
Loading
Loading