Skip to content

Commit 0f2c9f9

Browse files
jesmakclaude
andauthored
Move the map buttons up when the zoom control is off (#238)
The Reset focus and Toggle grouping buttons had fixed offsets that leave room for Leaflet's zoom control. With map_options.zoomControl set to false they now move up into its place. Co-authored-by: Jesse Mäkinen <jesse.j.makinen@gmail.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
1 parent 8ec4576 commit 0f2c9f9

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

‎src/components/MapCard.js‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export default class MapCard extends LitElement {
133133
<div id="map" style="min-height: ${this._config.mapHeight}px">
134134
<ha-icon-button
135135
label='Reset focus'
136-
style='${this._isDarkMode() ? "color:#ffffff;" : "color:#000000;"} position: absolute; top: 75px; left: 3px; z-index: 1;'
136+
style='${this._isDarkMode() ? "color:#ffffff;" : "color:#000000;"} position: absolute; top: ${this._hasZoomControl() ? 75 : 11}px; left: 3px; z-index: 1;'
137137
@click=${this._fitMap}
138138
tabindex="0"
139139
>
@@ -142,7 +142,7 @@ export default class MapCard extends LitElement {
142142
${this._config.clusterMarkers ? html`
143143
<ha-icon-button
144144
label='Toggle grouping'
145-
style='${this._isDarkMode() ? "color:#ffffff;" : "color:#000000;"} position: absolute; top: 115px; left: 3px; z-index: 1;'
145+
style='${this._isDarkMode() ? "color:#ffffff;" : "color:#000000;"} position: absolute; top: ${this._hasZoomControl() ? 115 : 51}px; left: 3px; z-index: 1;'
146146
@click=${this._toggleClustering}
147147
tabindex="0"
148148
>
@@ -155,6 +155,12 @@ export default class MapCard extends LitElement {
155155
`;
156156
}
157157

158+
// Leaflet shows its zoom control unless map_options.zoomControl turns it off.
159+
// The card's buttons sit below it, or move up into its place.
160+
_hasZoomControl() {
161+
return this._config.mapOptions?.zoomControl ?? true;
162+
}
163+
158164
_fitMap() {
159165
this.initialViewRenderService.setup();
160166
}

‎src/components/MapCard.test.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,18 @@ describe('MapCard', () => {
110110
expect(card.requestUpdate).not.toHaveBeenCalled();
111111
});
112112
});
113+
114+
describe('_hasZoomControl', () => {
115+
it('is on by default', () => {
116+
card._config = { mapOptions: {} };
117+
118+
expect(card._hasZoomControl()).toBe(true);
119+
});
120+
121+
it('is off when map_options turns it off', () => {
122+
card._config = { mapOptions: { zoomControl: false } };
123+
124+
expect(card._hasZoomControl()).toBe(false);
125+
});
126+
});
113127
});

0 commit comments

Comments
 (0)