Fix map auto-fit (#18801)

This commit is contained in:
Amit Finkelstein 2023-11-29 11:16:34 +02:00 committed by GitHub
parent 2acd1ff5e8
commit 44157a5df3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 12 deletions

View File

@ -107,10 +107,12 @@ export class HaMap extends ReactiveElement {
if (!this._loaded) { if (!this._loaded) {
return; return;
} }
let autoFitRequired = false;
const oldHass = changedProps.get("hass") as HomeAssistant | undefined; const oldHass = changedProps.get("hass") as HomeAssistant | undefined;
if (changedProps.has("_loaded") || changedProps.has("entities")) { if (changedProps.has("_loaded") || changedProps.has("entities")) {
this._drawEntities(); this._drawEntities();
autoFitRequired = true;
} else if (this._loaded && oldHass && this.entities) { } else if (this._loaded && oldHass && this.entities) {
// Check if any state has changed // Check if any state has changed
for (const entity of this.entities) { for (const entity of this.entities) {
@ -119,6 +121,7 @@ export class HaMap extends ReactiveElement {
this.hass!.states[getEntityId(entity)] this.hass!.states[getEntityId(entity)]
) { ) {
this._drawEntities(); this._drawEntities();
autoFitRequired = true;
break; break;
} }
} }
@ -130,13 +133,10 @@ export class HaMap extends ReactiveElement {
if (changedProps.has("_loaded") || changedProps.has("layers")) { if (changedProps.has("_loaded") || changedProps.has("layers")) {
this._drawLayers(changedProps.get("layers") as Layer[] | undefined); this._drawLayers(changedProps.get("layers") as Layer[] | undefined);
autoFitRequired = true;
} }
if ( if (this.autoFit && autoFitRequired) {
changedProps.has("_loaded") ||
((changedProps.has("entities") || changedProps.has("layers")) &&
this.autoFit)
) {
this.fitMap(); this.fitMap();
} }

View File

@ -216,13 +216,12 @@ class HuiMapCard extends LitElement implements LovelaceCard {
protected willUpdate(changedProps: PropertyValues): void { protected willUpdate(changedProps: PropertyValues): void {
super.willUpdate(changedProps); super.willUpdate(changedProps);
if ( if (
(changedProps.has("hass") && changedProps.has("hass") &&
this._config?.geo_location_sources && this._config?.geo_location_sources &&
!deepEqual( !deepEqual(
this._getSourceEntities(changedProps.get("hass")?.states), this._getSourceEntities(changedProps.get("hass")?.states),
this._getSourceEntities(this.hass.states) this._getSourceEntities(this.hass.states)
)) || )
(this._config?.entities && hasConfigOrEntitiesChanged(this, changedProps))
) { ) {
this._mapEntities = this._getMapEntities(); this._mapEntities = this._getMapEntities();
} }