@@ -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 ( ) {
0 commit comments