Skip to content

Commit 15434fb

Browse files
committed
Tooltip: refresh layer selector when activate and deactivate are called
1 parent cb567a0 commit 15434fb

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

assets/src/components/Tooltip.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ export default class Tooltip extends HTMLElement {
1212

1313
this._template = () => html`
1414
<select @change=${ event => { mainLizmap.tooltip.activate(event.target.value) }}>
15-
<option value="">---</option>
15+
<option value="" .selected=${mainLizmap.tooltip.activeLayerOrder === null}>---</option>
1616
${this._tooltipLayersCfgs.map(tooltipLayerCfg =>
17-
html`<option ?selected=${this._tooltipLayersCfgs.length === 1} value="${tooltipLayerCfg.order}">${mainLizmap.state.layersAndGroupsCollection.getLayerByName(tooltipLayerCfg.name).title}</option>`
17+
html`<option
18+
.selected=${tooltipLayerCfg.order === mainLizmap.tooltip.activeLayerOrder}
19+
value="${tooltipLayerCfg.order}">
20+
${mainLizmap.state.layersAndGroupsCollection.getLayerByName(tooltipLayerCfg.name).title}
21+
</option>`
1822
)}
1923
</select>
2024
`;
@@ -46,6 +50,13 @@ export default class Tooltip extends HTMLElement {
4650
['tooltip.loaded']
4751
);
4852

53+
mainEventDispatcher.addListener(
54+
() => {
55+
render(this._template(), this);
56+
},
57+
['tooltip.activated', 'tooltip.deactivated']
58+
);
59+
4960
render(this._template(), this);
5061
}
5162

assets/src/modules/Tooltip.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@ export default class Tooltip {
3131
this._lizmap3 = lizmap3;
3232
this._activeTooltipLayer;
3333
this._tooltipLayers = new Map();
34+
this.activeLayerOrder = null;
3435
}
3536

3637
/**
3738
* Activate tooltip for a layer order
3839
* @param {number} layerOrder a layer order
3940
*/
4041
activate(layerOrder) {
42+
// If the layer order is empty, deactivate the tooltip
4143
if (layerOrder === "") {
4244
this.deactivate();
4345
return;
@@ -246,6 +248,10 @@ export default class Tooltip {
246248
};
247249

248250
this._map.getTargetElement().addEventListener('pointerleave', this._onPointerLeave);
251+
252+
// Dispatch event to notify that the tooltip is activated
253+
this.activeLayerOrder = layerOrder;
254+
mainEventDispatcher.dispatch('tooltip.activated', { layerOrder: layerOrder });
249255
}
250256

251257
/**
@@ -259,5 +265,9 @@ export default class Tooltip {
259265
if (this._onPointerLeave) {
260266
this._map.getTargetElement().removeEventListener('pointerleave', this._onPointerLeave);
261267
}
268+
269+
// Dispatch event to notify that the tooltip is deactivated
270+
this.activeLayerOrder = null;
271+
mainEventDispatcher.dispatch('tooltip.deactivated');
262272
}
263273
}

0 commit comments

Comments
 (0)