Skip to content

Commit b053b3d

Browse files
committed
Tooltip: refresh layer selector when activate and deactivate are called
1 parent 216b6f3 commit b053b3d

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;
@@ -232,6 +234,10 @@ export default class Tooltip {
232234
};
233235

234236
this._map.getTargetElement().addEventListener('pointerleave', this._onPointerLeave);
237+
238+
// Dispatch event to notify that the tooltip is activated
239+
this.activeLayerOrder = layerOrder;
240+
mainEventDispatcher.dispatch('tooltip.activated', { layerOrder: layerOrder });
235241
}
236242

237243
/**
@@ -245,5 +251,9 @@ export default class Tooltip {
245251
if (this._onPointerLeave) {
246252
this._map.getTargetElement().removeEventListener('pointerleave', this._onPointerLeave);
247253
}
254+
255+
// Dispatch event to notify that the tooltip is deactivated
256+
this.activeLayerOrder = null;
257+
mainEventDispatcher.dispatch('tooltip.deactivated');
248258
}
249259
}

0 commit comments

Comments
 (0)