mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Fix map zone focus issues (#22623)
This commit is contained in:
parent
5f58c183f4
commit
4ef944ea08
@ -86,6 +86,8 @@ export class HaMap extends ReactiveElement {
|
|||||||
|
|
||||||
private _mapZones: Array<Marker | Circle> = [];
|
private _mapZones: Array<Marker | Circle> = [];
|
||||||
|
|
||||||
|
private _mapFocusZones: Array<Marker | Circle> = [];
|
||||||
|
|
||||||
private _mapPaths: Array<Polyline | CircleMarker> = [];
|
private _mapPaths: Array<Polyline | CircleMarker> = [];
|
||||||
|
|
||||||
public connectedCallback(): void {
|
public connectedCallback(): void {
|
||||||
@ -201,7 +203,11 @@ export class HaMap extends ReactiveElement {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this._mapFocusItems.length && !this.layers?.length) {
|
if (
|
||||||
|
!this._mapFocusItems.length &&
|
||||||
|
!this._mapFocusZones.length &&
|
||||||
|
!this.layers?.length
|
||||||
|
) {
|
||||||
this.leafletMap.setView(
|
this.leafletMap.setView(
|
||||||
new this.Leaflet.LatLng(
|
new this.Leaflet.LatLng(
|
||||||
this.hass.config.latitude,
|
this.hass.config.latitude,
|
||||||
@ -218,13 +224,9 @@ export class HaMap extends ReactiveElement {
|
|||||||
: []
|
: []
|
||||||
);
|
);
|
||||||
|
|
||||||
if (this.fitZones) {
|
this._mapFocusZones?.forEach((zone) => {
|
||||||
this._mapZones?.forEach((zone) => {
|
bounds.extend("getBounds" in zone ? zone.getBounds() : zone.getLatLng());
|
||||||
bounds.extend(
|
});
|
||||||
"getBounds" in zone ? zone.getBounds() : zone.getLatLng()
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
this.layers?.forEach((layer: any) => {
|
this.layers?.forEach((layer: any) => {
|
||||||
bounds.extend(
|
bounds.extend(
|
||||||
@ -395,6 +397,7 @@ export class HaMap extends ReactiveElement {
|
|||||||
if (this._mapZones.length) {
|
if (this._mapZones.length) {
|
||||||
this._mapZones.forEach((marker) => marker.remove());
|
this._mapZones.forEach((marker) => marker.remove());
|
||||||
this._mapZones = [];
|
this._mapZones = [];
|
||||||
|
this._mapFocusZones = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.entities) {
|
if (!this.entities) {
|
||||||
@ -466,13 +469,18 @@ export class HaMap extends ReactiveElement {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// create circle around it
|
// create circle around it
|
||||||
this._mapZones.push(
|
const circle = Leaflet.circle([latitude, longitude], {
|
||||||
Leaflet.circle([latitude, longitude], {
|
interactive: false,
|
||||||
interactive: false,
|
color: passive ? passiveZoneColor : zoneColor,
|
||||||
color: passive ? passiveZoneColor : zoneColor,
|
radius,
|
||||||
radius,
|
});
|
||||||
})
|
this._mapZones.push(circle);
|
||||||
);
|
if (
|
||||||
|
this.fitZones &&
|
||||||
|
(typeof entity === "string" || entity.focus !== false)
|
||||||
|
) {
|
||||||
|
this._mapFocusZones.push(circle);
|
||||||
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,7 @@ const cardConfigStruct = assign(
|
|||||||
hours_to_show: optional(number()),
|
hours_to_show: optional(number()),
|
||||||
geo_location_sources: optional(array(geoSourcesConfigStruct)),
|
geo_location_sources: optional(array(geoSourcesConfigStruct)),
|
||||||
auto_fit: optional(boolean()),
|
auto_fit: optional(boolean()),
|
||||||
|
fit_zones: optional(boolean()),
|
||||||
theme_mode: optional(string()),
|
theme_mode: optional(string()),
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user