diff --git a/src/components/map/ha-map.ts b/src/components/map/ha-map.ts index a6540ca7fa..2afafbb56c 100644 --- a/src/components/map/ha-map.ts +++ b/src/components/map/ha-map.ts @@ -107,10 +107,12 @@ export class HaMap extends ReactiveElement { if (!this._loaded) { return; } + let autoFitRequired = false; const oldHass = changedProps.get("hass") as HomeAssistant | undefined; if (changedProps.has("_loaded") || changedProps.has("entities")) { this._drawEntities(); + autoFitRequired = true; } else if (this._loaded && oldHass && this.entities) { // Check if any state has changed for (const entity of this.entities) { @@ -119,6 +121,7 @@ export class HaMap extends ReactiveElement { this.hass!.states[getEntityId(entity)] ) { this._drawEntities(); + autoFitRequired = true; break; } } @@ -130,13 +133,10 @@ export class HaMap extends ReactiveElement { if (changedProps.has("_loaded") || changedProps.has("layers")) { this._drawLayers(changedProps.get("layers") as Layer[] | undefined); + autoFitRequired = true; } - if ( - changedProps.has("_loaded") || - ((changedProps.has("entities") || changedProps.has("layers")) && - this.autoFit) - ) { + if (this.autoFit && autoFitRequired) { this.fitMap(); } diff --git a/src/panels/lovelace/cards/hui-map-card.ts b/src/panels/lovelace/cards/hui-map-card.ts index f2938140b6..c3076985f4 100644 --- a/src/panels/lovelace/cards/hui-map-card.ts +++ b/src/panels/lovelace/cards/hui-map-card.ts @@ -216,13 +216,12 @@ class HuiMapCard extends LitElement implements LovelaceCard { protected willUpdate(changedProps: PropertyValues): void { super.willUpdate(changedProps); if ( - (changedProps.has("hass") && - this._config?.geo_location_sources && - !deepEqual( - this._getSourceEntities(changedProps.get("hass")?.states), - this._getSourceEntities(this.hass.states) - )) || - (this._config?.entities && hasConfigOrEntitiesChanged(this, changedProps)) + changedProps.has("hass") && + this._config?.geo_location_sources && + !deepEqual( + this._getSourceEntities(changedProps.get("hass")?.states), + this._getSourceEntities(this.hass.states) + ) ) { this._mapEntities = this._getMapEntities(); }