Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/panels/lovelace/cards/hui-map-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class HuiMapCard extends LitElement implements LovelaceCard {
false
);
private _mapItems: Array<Marker | Circle> = [];
private _mapZones: Array<Marker | Circle> = [];
private _connected = false;

public setConfig(config: MapCardConfig): void {
Expand Down Expand Up @@ -283,6 +284,11 @@ class HuiMapCard extends LitElement implements LovelaceCard {
}
const mapItems: Layer[] = (this._mapItems = []);

if (this._mapZones) {
this._mapZones.forEach((marker) => marker.remove());
}
const mapZones: Layer[] = (this._mapZones = []);

const allEntities = this._configEntities!.concat();

// Calculate visible geo location sources
Expand Down Expand Up @@ -340,7 +346,7 @@ class HuiMapCard extends LitElement implements LovelaceCard {
}

// create marker with the icon
mapItems.push(
mapZones.push(
Leaflet.marker([latitude, longitude], {
icon: Leaflet.divIcon({
html: iconHTML,
Expand All @@ -353,7 +359,7 @@ class HuiMapCard extends LitElement implements LovelaceCard {
);

// create circle around it
mapItems.push(
mapZones.push(
Leaflet.circle([latitude, longitude], {
interactive: false,
color: "#FF9800",
Expand Down Expand Up @@ -405,6 +411,7 @@ class HuiMapCard extends LitElement implements LovelaceCard {
}

this._mapItems.forEach((marker) => map.addLayer(marker));
this._mapZones.forEach((marker) => map.addLayer(marker));
}

private _attachObserver(): void {
Expand Down
11 changes: 9 additions & 2 deletions src/panels/map/ha-panel-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ class HaPanelMap extends LocalizeMixin(PolymerElement) {
}
var mapItems = (this._mapItems = []);

if (this._mapZones) {
this._mapZones.forEach(function(marker) {
marker.remove();
});
}
var mapZones = (this._mapZones = []);

Object.keys(hass.states).forEach((entityId) => {
var entity = hass.states[entityId];
var title = computeStateName(entity);
Expand Down Expand Up @@ -136,7 +143,7 @@ class HaPanelMap extends LocalizeMixin(PolymerElement) {
});

// create marker with the icon
mapItems.push(
mapZones.push(
this.Leaflet.marker(
[entity.attributes.latitude, entity.attributes.longitude],
{
Expand All @@ -148,7 +155,7 @@ class HaPanelMap extends LocalizeMixin(PolymerElement) {
);

// create circle around it
mapItems.push(
mapZones.push(
this.Leaflet.circle(
[entity.attributes.latitude, entity.attributes.longitude],
{
Expand Down