Skip to content

Commit 3b8f030

Browse files
authored
Merge pull request #4 from BrianHepler/popup_reposition
Popup delay between popups
2 parents 96a9c17 + d549f4c commit 3b8f030

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

MMM-BirdNET.js

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Module.register("MMM-BirdNET", {
22
defaults: {
33
updateInterval: 60 * 60 * 1000, // one hour
44
popInterval: 30 * 1000, // thirty seconds
5+
popDelay: 0, // Off
56
dataUrl: 'https://birdnet.cornell.edu/map/requeststats', // where to pull data
67
mapUrl: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', // where to pull map tiles
78
mapMode: 'dark', // map tile appearance
@@ -26,6 +27,9 @@ Module.register("MMM-BirdNET", {
2627
this.birdData = {};
2728
this.birdMap = null;
2829
this.markersLayer = new L.layerGroup();
30+
this.popupIndex = -1;
31+
this.popTimer = null;
32+
this.resetTime = null;
2933
this.locations = [];
3034

3135
this.popupOptions = {
@@ -44,7 +48,7 @@ Module.register("MMM-BirdNET", {
4448

4549
getHeader: function() { return this.name;},
4650

47-
suspend: function() { clearInterval(this.updateTimer); clearInterval(this.updateTimer);},
51+
suspend: function() { clearInterval(this.updateTimer); clearInterval(this.updateTimer); clearInterval(this.resetTimer)},
4852

4953
resume: function() {
5054
this.updateTimer = setInterval(()=> {
@@ -78,7 +82,7 @@ Module.register("MMM-BirdNET", {
7882
},
7983

8084
updateData: function() {
81-
Log.info("Downloading bird hit data.");
85+
Log.info(this.name + " - Downloading bird hit data.");
8286
var self = this;
8387
var url = this.config.dataUrl;
8488

@@ -99,7 +103,7 @@ Module.register("MMM-BirdNET", {
99103
},
100104

101105
processBirdData: function(birdData) {
102-
Log.info("Processing bird hits");
106+
// Log.info(this.name + " - Processing bird hits");
103107

104108
this.birdData = JSON.parse(birdData);
105109
var markers = this.markersLayer;
@@ -142,7 +146,7 @@ Module.register("MMM-BirdNET", {
142146
markers.addLayer(circle);
143147
} else { skipped++;}
144148
}
145-
Log.info("Processed " + observations.length + " bird hits. (skipped " + skipped +")");
149+
Log.info(this.name + "- Processed " + observations.length + " bird hits. (skipped " + skipped +")");
146150
},
147151

148152
createPopup: function(name, species, percent, ts) {
@@ -192,26 +196,39 @@ Module.register("MMM-BirdNET", {
192196
},
193197

194198
randomPopup: function() {
199+
// Log.info(this.name + " - Pop goes the birdie and the birdie goes pop.");
195200
var markers = this.markersLayer;
196201
var markerArray = markers.getLayers();
202+
if (this.resetTimer != null) clearInterval(this.resetTimer);
203+
197204
var index = Math.floor(Math.random() * markerArray.length);
198-
205+
this.popupIndex = index;
199206
markerArray[index].openPopup();
207+
208+
// implement pan to origin & delay between popups (if configured)
209+
if (this.config.popDelay > 0) {
210+
this.resetTimer = setInterval(()=> {
211+
if (markerArray[this.popupIndex] != null) {markerArray[this.popupIndex].closePopup()};
212+
this.birdMap.flyTo([this.config.lat, this.config.lon]);
213+
}, this.config.popInterval);
214+
}
200215
},
201216

202217
/**
203-
* Schedule popups
218+
* Schedule popups & delay between popups.
204219
*/
205220
schedulePopInterval: function () {
206221
this.updateDom(this.config.animationSpeed);
222+
var markerArray = this.markersLayer.getLayers();
207223

208-
// #2638 Clear timer if it already exists
209-
if (this.popTimer != null) clearInterval(this.timer);
224+
// Clear timers if they already exist
225+
if (this.popTimer != null) clearInterval(this.popTimer);
226+
if (this.resetTimer != null) clearInterval(this.resetTimer);
210227

228+
// implement popup with optional delay
211229
this.timer = setInterval(() => {
212-
this.activeBird++;
213230
this.randomPopup();
214-
}, this.config.popInterval);
231+
}, this.config.popInterval + this.config.popDelay);
215232
},
216233

217234
buildMap: function() {

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This is a module for the [MagicMirror<sup>2</sup>](https://github.com/MichMich/M
44
![MMM-BirdNET interface](display.png)
55

66
## Features
7-
* Plots the uses of BirdNET mobile app in the nearby area
7+
* Plots the uses of BirdNET service in the nearby area
88
* Displays the name, species, photo, and confidence of a random submission via popup
99
* Several included map options
1010
* Custom map option available
@@ -33,7 +33,8 @@ All configuration options are optional. There are no mandatory parameters.
3333
| Option | Default | Description |
3434
|:------:| ------- | ----------- |
3535
| updateInterval | 3600000 (one hour) | How often the BirdNET data is pulled from the website.|
36-
| popInterval | 30000 (30 seconds)| How often the popup switches to a new entry |
36+
| popInterval | 30000 (30 seconds)| How often (in milliseconds) the popup switches to a new entry |
37+
| popDelay | 0 (off) | How long (in milliseconds) between the closing of one popup and the opening of the next, with a pan to origin lat/long in between |
3738
| mapMode | 'dark' | Which map to use. Supported values are: `dark`, `light`, `atlas`, `stark`, `terrain`, `satellite`, `custom` and `metal`.
3839
| lat | 42.453583743 | Latitude for the center of the map display. |
3940
| lon | -76.47363144 | Longitude for the center of the map display. |
@@ -46,11 +47,14 @@ All configuration options are optional. There are no mandatory parameters.
4647
Note: Width & height of the map are controlled via the `BirdNETmap` classname. Override via your `custom.css`. Default is 400px x 400px. See the `MMM-BirdNET.css` file for examples.
4748

4849
## Upcoming Features
49-
* Better CSS for the popups.
5050
* Enable notification broadcasts
5151
* Translations for common names of birds
5252

5353
## Version History
54+
### v0.1.2
55+
* Added the ability to pan back to origin coords between popups. Controlled by `popDelay` parameter.
56+
* Popup colors & fonts accessible via `name-label`, `species-label`, `confidence` CSS values.
57+
5458
### v0.1.1
5559
* Fixed issue with popups double-tapping after an hour
5660
* Fixed issue with displaying submissions in exceptionally high-density areas

0 commit comments

Comments
 (0)