Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
19 changes: 15 additions & 4 deletions src/panels/lovelace/cards/hui-map-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,16 @@ class HuiMapCard extends LitElement implements LovelaceCard {
return;
}
const zoom = this._config.default_zoom;
if (this._mapItems.length === 0) {

const devices = new Array();
this._mapItems.forEach((item) => {
// @ts-ignore
Comment thread
bramkragten marked this conversation as resolved.
Outdated
if (!item.options.zone) {
devices.push(item.getLatLng());
}
});

if (devices.length === 0) {
this._leafletMap.setView(
new this.Leaflet.LatLng(
this.hass.config.latitude,
Expand All @@ -259,9 +268,7 @@ class HuiMapCard extends LitElement implements LovelaceCard {
return;
}

const bounds = this.Leaflet.latLngBounds(
this._mapItems ? this._mapItems.map((item) => item.getLatLng()) : []
);
const bounds = this.Leaflet.latLngBounds(devices);
this._leafletMap.fitBounds(bounds.pad(0.5));

if (zoom && this._leafletMap.getZoom() > zoom) {
Expand Down Expand Up @@ -349,15 +356,19 @@ class HuiMapCard extends LitElement implements LovelaceCard {
}),
interactive: false,
title,
// @ts-ignore
zone: true,
})
);

// create circle around it
mapItems.push(
// @ts-ignore
Leaflet.circle([latitude, longitude], {
interactive: false,
color: "#FF9800",
radius,
zone: true,
})
);

Expand Down
13 changes: 9 additions & 4 deletions src/panels/map/ha-panel-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ class HaPanelMap extends LocalizeMixin(PolymerElement) {

fitMap() {
var bounds;
var devices = [];

if (this._mapItems.length === 0) {
this._mapItems.forEach((item) => {
if (!item.options.zone) devices.push(item.getLatLng());
Comment thread
bramkragten marked this conversation as resolved.
Outdated
});

if (devices.length === 0) {
this._map.setView(
new this.Leaflet.LatLng(
this.hass.config.latitude,
Expand All @@ -79,9 +84,7 @@ class HaPanelMap extends LocalizeMixin(PolymerElement) {
14
);
} else {
bounds = new this.Leaflet.latLngBounds(
this._mapItems.map((item) => item.getLatLng())
);
bounds = new this.Leaflet.latLngBounds(devices);
this._map.fitBounds(bounds.pad(0.5));
}
}
Expand Down Expand Up @@ -143,6 +146,7 @@ class HaPanelMap extends LocalizeMixin(PolymerElement) {
icon: icon,
interactive: false,
title: title,
zone: true,
}
).addTo(map)
);
Expand All @@ -155,6 +159,7 @@ class HaPanelMap extends LocalizeMixin(PolymerElement) {
interactive: false,
color: "#FF9800",
radius: entity.attributes.radius,
zone: true,
}
).addTo(map)
);
Expand Down