Skip to content

Commit

Permalink
Add home marker.
Browse files Browse the repository at this point in the history
  • Loading branch information
Makin-Things committed Dec 28, 2023
1 parent 7c210b7 commit 6767f8b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
23 changes: 17 additions & 6 deletions dist/bom-radar-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -13054,8 +13054,6 @@ let BomRadarCard = class BomRadarCard extends s$1 {
this.barsize = 0;
this.center_lon = 133.75;
this.center_lat = -27.85;
this.marker_lon = 149.08013;
this.marker_lat = -35.361996;
this.mapLoaded = false;
this.currentTime = '';
this.getRadarCapabilities().then(async (t) => {
Expand Down Expand Up @@ -13102,9 +13100,11 @@ let BomRadarCard = class BomRadarCard extends s$1 {
el.style.width = `15px`;
el.style.height = `15px`;
el.style.backgroundSize = '100%';
new mapboxGlExports.Marker(el)
.setLngLat([this.marker_lon, this.marker_lat])
.addTo(this.map);
this.marker = new mapboxGlExports.Marker(el);
if ((this._config.show_marker) && (this._config.marker_latitude !== undefined) && (this._config.marker_longitude !== undefined)) {
this.marker.setLngLat([Number(this._config.marker_longitude), Number(this._config.marker_latitude)]);
this.marker.addTo(this.map);
}
// This is the timestamp in UTC time to show radar images for.
// There are between 6-7 hours worth of data (for each 5 minutes).
// Shortly after 5 minutes past the hour the data for hour -7 is removed up to an including the :00 data.
Expand Down Expand Up @@ -13254,7 +13254,7 @@ let BomRadarCard = class BomRadarCard extends s$1 {
clearInterval(this.frameTimer);
this.frameTimer = setInterval(() => this.changeRadarFrame(), this.restart_delay);
}
else if (next == 0) {
else {
clearInterval(this.frameTimer);
this.frameTimer = setInterval(() => this.changeRadarFrame(), this.frame_delay);
}
Expand Down Expand Up @@ -13289,6 +13289,17 @@ let BomRadarCard = class BomRadarCard extends s$1 {
if (this._config.restart_delay !== changedProps.get('_config').restart_delay) {
this.restart_delay = (this._config.restart_delay === undefined) || isNaN(this._config.restart_delay) ? 1000 : this._config.restart_delay;
}
if ((this._config.show_marker !== changedProps.get('_config').show_marker) || (this._config.marker_latitude !== changedProps.get('_config').marker_latitude) || (this._config.marker_longitude !== changedProps.get('_config').marker_longitude)) {
if (this.marker !== undefined) {
if ((this._config.show_marker) && (this._config.marker_latitude !== undefined) && (this._config.marker_longitude !== undefined)) {
this.marker.setLngLat([Number(this._config.marker_longitude), Number(this._config.marker_latitude)]);
this.marker.addTo(this.map);
}
else {
this.marker.remove();
}
}
}
return true;
}
if ((changedProps.has('currentTime')) && (this.currentTime !== '')) {
Expand Down
26 changes: 20 additions & 6 deletions src/bom-radar-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ export class BomRadarCard extends LitElement implements LovelaceCard {
private barsize = 0;
private center_lon = 133.75;
private center_lat = -27.85;
private marker_lon = 149.08013;
private marker_lat = -35.361996;
private marker?: mapboxgl.Marker;

// TODO Add any properities that should cause your element to re-render here
@property({ attribute: false }) public hass!: HomeAssistant;
Expand Down Expand Up @@ -175,9 +174,12 @@ export class BomRadarCard extends LitElement implements LovelaceCard {
el.style.height = `15px`;
el.style.backgroundSize = '100%';

new mapboxgl.Marker(el)
.setLngLat([this.marker_lon, this.marker_lat])
.addTo(this.map);
this.marker = new mapboxgl.Marker(el);

if ((this._config.show_marker) && (this._config.marker_latitude !== undefined) && (this._config.marker_longitude !== undefined)) {
this.marker.setLngLat([Number(this._config.marker_longitude), Number(this._config.marker_latitude)]);
this.marker.addTo(this.map);
}

// This is the timestamp in UTC time to show radar images for.
// There are between 6-7 hours worth of data (for each 5 minutes).
Expand Down Expand Up @@ -336,7 +338,7 @@ export class BomRadarCard extends LitElement implements LovelaceCard {
clearInterval(this.frameTimer);
this.frameTimer = setInterval(() => this.changeRadarFrame(), this.restart_delay);
}
else if (next == 0) {
else {
clearInterval(this.frameTimer);
this.frameTimer = setInterval(() => this.changeRadarFrame(), this.frame_delay);
}
Expand Down Expand Up @@ -380,6 +382,18 @@ export class BomRadarCard extends LitElement implements LovelaceCard {
this.restart_delay = (this._config.restart_delay === undefined) || isNaN(this._config.restart_delay) ? 1000 : this._config.restart_delay;
}

if ((this._config.show_marker !== changedProps.get('_config').show_marker) || (this._config.marker_latitude !== changedProps.get('_config').marker_latitude) || (this._config.marker_longitude !== changedProps.get('_config').marker_longitude)) {
if (this.marker !== undefined) {
if ((this._config.show_marker) && (this._config.marker_latitude !== undefined) && (this._config.marker_longitude !== undefined)) {
this.marker.setLngLat([Number(this._config.marker_longitude), Number(this._config.marker_latitude)]);
this.marker.addTo(this.map);
}
else {
this.marker.remove();
}
}
}

return true;
}

Expand Down

0 comments on commit 6767f8b

Please sign in to comment.