Skip to content

Commit 96a9c17

Browse files
authored
Merge pull request #3 from BrianHepler/Better-Popups
Better popups. More landscape than portrait. CSS used more heavily, rather than config parameters.
2 parents 2dd6673 + ce37afc commit 96a9c17

5 files changed

Lines changed: 88 additions & 58 deletions

File tree

MMM-BirdNET.css

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,38 @@
11
.BirdNETmap {
2-
width: 500px;
3-
height: 500px;
2+
width: 400px;
3+
height: 400px;
44
border-radius: 10px;
55
}
6+
7+
.popup {
8+
height: 85px;
9+
width: auto;
10+
padding: 0px 0px 0px 0px;
11+
background-color:lightslategray;
12+
}
13+
14+
table, tr, th, td {
15+
/* border: 1px solid; */
16+
}
17+
18+
.popup-image {
19+
border-radius: 2px;
20+
padding: 3px;
21+
}
22+
23+
.name-label {
24+
font-size: 20px;
25+
}
26+
27+
.species-label {
28+
font-size: 12px;
29+
}
30+
31+
.confidence {
32+
font-size: 14px;
33+
}
34+
35+
/* Override Leaflet defaults */
36+
.leaflet-popup-content {
37+
margin: 3px 3px;
38+
}

MMM-BirdNET.js

Lines changed: 48 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@ Module.register("MMM-BirdNET", {
22
defaults: {
33
updateInterval: 60 * 60 * 1000, // one hour
44
popInterval: 30 * 1000, // thirty seconds
5-
dataUrl: 'https://birdnet.cornell.edu/map/requeststats',
6-
mapUrl: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
7-
mapMode: 'dark',
8-
lat: 42.453583743,
9-
lon: -76.47363144,
10-
width: '400px',
11-
height: '400px',
12-
zoomLevel: 7,
13-
markerDistance: 300,
14-
markerColor: 'LightGreen' // distance from map center to put markers
5+
dataUrl: 'https://birdnet.cornell.edu/map/requeststats', // where to pull data
6+
mapUrl: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', // where to pull map tiles
7+
mapMode: 'dark', // map tile appearance
8+
lat: 42.453583743, // latitude
9+
lon: -76.47363144, // longitude
10+
zoomLevel: 7, // Zoom level of map
11+
markerDistance: 300, // maximum distance from map center to plot markers
12+
markerColor: 'LightGreen' // color of plotted BirdNET submissions
1513
},
1614

1715
start: function () {
@@ -32,34 +30,27 @@ Module.register("MMM-BirdNET", {
3230

3331
this.popupOptions = {
3432
closeButton: false,
35-
closeOnClick: true
33+
closeOnClick: true,
3634
};
3735
this.mapOptions = {
3836
zoomControl: false,
3937
boxZoom: false,
40-
doubleClickZoom: false
41-
}
42-
43-
this.mapSelector = "Jawg.Dark";
44-
45-
46-
47-
if (this.config.mapMode == 'dark') {
48-
} else {
49-
50-
}
38+
doubleClickZoom: false,
39+
attributionControl: false
40+
};
5141

5242
this.loaded = false;
5343
},
5444

5545
getHeader: function() { return this.name;},
5646

57-
suspend: function() { clearInterval(this.updateTimer);},
47+
suspend: function() { clearInterval(this.updateTimer); clearInterval(this.updateTimer);},
5848

5949
resume: function() {
6050
this.updateTimer = setInterval(()=> {
6151
this.updateData();
6252
}, this.config.updateInterval);
53+
this.schedulePopInterval();
6354
},
6455

6556
getDom: function() {
@@ -70,6 +61,8 @@ Module.register("MMM-BirdNET", {
7061
wrapper = document.createElement("div");
7162
wrapper.className = "BirdNETmap";
7263
wrapper.id = "BirdNET-map";
64+
wrapper.width = this.config.width;
65+
wrapper.height = this.config.height;
7366
this.mapWrapper = wrapper;
7467
}
7568

@@ -92,16 +85,12 @@ Module.register("MMM-BirdNET", {
9285
var dataRequest = new XMLHttpRequest();
9386
dataRequest.open("GET", url, true);
9487
dataRequest.send();
95-
// dataRequest.onprogress = function(event) {
96-
// Log.info("Downloading bird data: " + event.total);
97-
// }
9888
dataRequest.onerror = function() {
9989
Log.error("Unable to download bird data");
10090
this.birdData = {};
10191
}
10292
dataRequest.onload = function() {
103-
Log.info(self.name + " - Bird observation data loaded.");
104-
// remove markers
93+
// Log.info(self.name + " - Bird observation data loaded.");
10594
if (dataRequest.status >= 200 && dataRequest.status < 300) {
10695
self.processBirdData(dataRequest.responseText);
10796
}
@@ -158,7 +147,7 @@ Module.register("MMM-BirdNET", {
158147

159148
createPopup: function(name, species, percent, ts) {
160149
var wrapper = document.createElement("div");
161-
wrapper.className = "BirdNET-popUp";
150+
wrapper.className = "popup";
162151
wrapper.id = "BirdNET-popup-" + ts;
163152

164153
var labelEntry = labeldata[species + "_" + name];
@@ -167,29 +156,37 @@ Module.register("MMM-BirdNET", {
167156
imageSource = encodeURIComponent(labelEntry.icon);
168157
}
169158

159+
var table = document.createElement("table");
160+
var tr = document.createElement("tr");
161+
var tdI = document.createElement("td");
162+
var tdT = document.createElement("td");
163+
170164
var image = document.createElement("img");
171-
image.className = "rounded mr-3";
165+
image.className = "popup-image";
172166
image.setAttribute("width", "75px");
173167
image.setAttribute("height", "75px");
174168
image.setAttribute("src", this.imageUrl + imageSource);
175-
wrapper.appendChild(image);
176-
177-
var bodyWrapper = document.createElement("div");
178-
bodyWrapper.className = "media-body";
179-
wrapper.appendChild(bodyWrapper);
180-
181-
var nameLabel = document.createElement("h6");
182-
nameLabel.innerHTML = name + "<br>";
183-
bodyWrapper.appendChild(nameLabel);
184-
185-
var speciesLabel = document.createElement("small");
186-
speciesLabel.className = "text-muted";
187-
speciesLabel.innerHTML = species + "<br>";
188-
nameLabel.appendChild(speciesLabel);
189-
190-
var scoreLabel = document.createElement("small");
191-
scoreLabel.innerHTML = "Confidence: " + (Number(percent) * 100).toFixed(2) + "%";
192-
nameLabel.appendChild(scoreLabel);
169+
tdI.append(image);
170+
171+
// var stack = document.createElement("div");
172+
var nameLabel = document.createElement("div");
173+
nameLabel.className = "name-label"
174+
nameLabel.innerHTML = name
175+
var specLabel = document.createElement("div");
176+
specLabel.className = "species-label";
177+
specLabel.innerHTML = species;
178+
var ciLabel = document.createElement("div");
179+
ciLabel.className = "confidence";
180+
ciLabel.innerHTML = "Confidence: " + (Number(percent) * 100).toFixed(2) + "%";
181+
182+
tdT.append(nameLabel);
183+
tdT.append(specLabel);
184+
tdT.append(ciLabel);
185+
186+
tr.appendChild(tdI);
187+
tr.appendChild(tdT);
188+
table.appendChild(tr);
189+
wrapper.append(table);
193190

194191
return wrapper;
195192
},
@@ -219,7 +216,7 @@ Module.register("MMM-BirdNET", {
219216

220217
buildMap: function() {
221218
if (this.birdMap != null) {
222-
Log.info("map already exists");
219+
// Log.info("map already exists");
223220
} else {
224221
var map = L.map('BirdNET-map', this.mapOptions);
225222
map.setView([this.config.lat, this.config.lon],this.config.zoomLevel); // create the map
@@ -247,14 +244,13 @@ Module.register("MMM-BirdNET", {
247244
L.tileLayer.provider('USGS.USImageryTopo',{maxZoom: 19}).addTo(map);
248245
break;
249246
case 'custom':
250-
L.tileLayer(this.config.mapUrl, {maxZoom: 19, attribution: 'Unknown'}).addTo(map); // add map tiles
247+
L.tileLayer(this.config.mapUrl, {maxZoom: 19, attribution: 'Unknown'}).addTo(map);
251248
} // end case statement
252-
249+
L.control.attribution(this.attributionOptions);
253250
this.birdMap = map;
254251
}
255252

256253
if (this.markersLayer == null) {
257-
Log.info("Creating markers layer.");
258254
this.markersLayer = L.layerGroup().addTo(this.birdMap);
259255
} else {
260256
this.markersLayer.addTo(this.birdMap);

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This is a module for the [MagicMirror<sup>2</sup>](https://github.com/MichMich/M
88
* Displays the name, species, photo, and confidence of a random submission via popup
99
* Several included map options
1010
* Custom map option available
11-
* Configurable speed of popups
11+
* Configurable speed of popups, marker color
1212

1313
## Dependencies
1414
* An installation of MagicMirror<sup>2</sup>
@@ -37,17 +37,18 @@ All configuration options are optional. There are no mandatory parameters.
3737
| mapMode | 'dark' | Which map to use. Supported values are: `dark`, `light`, `atlas`, `stark`, `terrain`, `satellite`, `custom` and `metal`.
3838
| lat | 42.453583743 | Latitude for the center of the map display. |
3939
| lon | -76.47363144 | Longitude for the center of the map display. |
40-
| width | 400px | Width of the map box. |
41-
| height | 400px | Height of the map box |
4240
| markerColor | 'LightGreen' | Sets the color of the markers on the map representing submissions. Accepts [HTML standard color names](https://www.w3schools.com/cssref/css_colors.php) or hex format.|
4341
| markerDistance | 300 | Distance in kilometers from the center of the map to display BirdNET submissions. If you encounter performance issues, try reducing this number. BirdNET regularly receives 30-50K submissions daily and we can _maybe_ display 10K. |
4442
| zoomLevel | 7 | How far in the map is zoomed. See [Leaflet](https://leafletjs.com/examples/zoom-levels/) documentation for more details. |
4543
| mapUrl | null | If you set the mapMode parameter to `custom`, this parameter will activate. You can supply your own [Leaflet](https://leafletjs.com/reference.html#map-example)-supported map URL here. |
4644
| dataUrl | https://birdnet.cornell.edu/map/requeststats| Where to pull the data |
4745

46+
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.
47+
4848
## Upcoming Features
4949
* Better CSS for the popups.
5050
* Enable notification broadcasts
51+
* Translations for common names of birds
5152

5253
## Version History
5354
### v0.1.1

display.png

-46.5 KB
Loading

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mmm-birdnet",
3-
"version": "0.1.1",
3+
"version": "1.1",
44
"description": "A display of local hits for the BirdNET mobile app. https://birdnet.cornell.edu",
55
"main": "MMM-BirdNET.js",
66
"repository": {

0 commit comments

Comments
 (0)