mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-22 08:46:35 +00:00
parent
b25fff9852
commit
f008f8f41a
@ -4,8 +4,11 @@ import { Map } from "leaflet";
|
|||||||
export type LeafletModuleType = typeof import("leaflet");
|
export type LeafletModuleType = typeof import("leaflet");
|
||||||
|
|
||||||
export const setupLeafletMap = async (
|
export const setupLeafletMap = async (
|
||||||
mapElement
|
mapElement: HTMLElement
|
||||||
): Promise<[Map, LeafletModuleType]> => {
|
): Promise<[Map, LeafletModuleType]> => {
|
||||||
|
if (!mapElement.parentNode) {
|
||||||
|
throw new Error("Cannot setup Leaflet map on disconnected element");
|
||||||
|
}
|
||||||
// tslint:disable-next-line
|
// tslint:disable-next-line
|
||||||
const Leaflet = (await import(/* webpackChunkName: "leaflet" */ "leaflet")) as LeafletModuleType;
|
const Leaflet = (await import(/* webpackChunkName: "leaflet" */ "leaflet")) as LeafletModuleType;
|
||||||
Leaflet.Icon.Default.imagePath = "/static/images/leaflet";
|
Leaflet.Icon.Default.imagePath = "/static/images/leaflet";
|
||||||
|
@ -115,15 +115,19 @@ class HuiMapCard extends LitElement implements LovelaceCard {
|
|||||||
super.connectedCallback();
|
super.connectedCallback();
|
||||||
this._connected = true;
|
this._connected = true;
|
||||||
if (this.hasUpdated) {
|
if (this.hasUpdated) {
|
||||||
|
this.loadMap();
|
||||||
this._attachObserver();
|
this._attachObserver();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public disconnectedCallback(): void {
|
public disconnectedCallback(): void {
|
||||||
super.disconnectedCallback();
|
super.disconnectedCallback();
|
||||||
|
this._connected = false;
|
||||||
|
|
||||||
if (this._leafletMap) {
|
if (this._leafletMap) {
|
||||||
this._leafletMap.remove();
|
this._leafletMap.remove();
|
||||||
|
this._leafletMap = undefined;
|
||||||
|
this.Leaflet = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._resizeObserver) {
|
if (this._resizeObserver) {
|
||||||
@ -283,7 +287,7 @@ class HuiMapCard extends LitElement implements LovelaceCard {
|
|||||||
}),
|
}),
|
||||||
interactive: false,
|
interactive: false,
|
||||||
title,
|
title,
|
||||||
}).addTo(map)
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
// create circle around it
|
// create circle around it
|
||||||
@ -292,7 +296,7 @@ class HuiMapCard extends LitElement implements LovelaceCard {
|
|||||||
interactive: false,
|
interactive: false,
|
||||||
color: "#FF9800",
|
color: "#FF9800",
|
||||||
radius,
|
radius,
|
||||||
}).addTo(map)
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
@ -316,14 +320,14 @@ class HuiMapCard extends LitElement implements LovelaceCard {
|
|||||||
<ha-entity-marker
|
<ha-entity-marker
|
||||||
entity-id="${entityId}"
|
entity-id="${entityId}"
|
||||||
entity-name="${entityName}"
|
entity-name="${entityName}"
|
||||||
entity-picture="${entityPicture || ""}
|
entity-picture="${entityPicture || ""}"
|
||||||
></ha-entity-marker>
|
></ha-entity-marker>
|
||||||
`,
|
`,
|
||||||
iconSize: [48, 48],
|
iconSize: [48, 48],
|
||||||
className: "",
|
className: "",
|
||||||
}),
|
}),
|
||||||
title: computeStateName(stateObj),
|
title: computeStateName(stateObj),
|
||||||
}).addTo(map)
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
// create circle around if entity has accuracy
|
// create circle around if entity has accuracy
|
||||||
@ -333,10 +337,12 @@ class HuiMapCard extends LitElement implements LovelaceCard {
|
|||||||
interactive: false,
|
interactive: false,
|
||||||
color: "#0288D1",
|
color: "#0288D1",
|
||||||
radius: gpsAccuracy,
|
radius: gpsAccuracy,
|
||||||
}).addTo(map)
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._mapItems.forEach((marker) => map.addLayer(marker));
|
||||||
}
|
}
|
||||||
|
|
||||||
private _attachObserver(): void {
|
private _attachObserver(): void {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user