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) {
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();
}

View File

@ -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();
}