-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
8,320 additions
and
18 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
<html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>Bird Locations Map</title> | ||
<title>Wildlife Locations Map</title> | ||
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" /> | ||
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script> | ||
<style> | ||
|
@@ -29,6 +29,14 @@ | |
integrity="sha256-o9qZ8HaJPsNxb0EXC5t1c1fLWPZ+bHXC1r2aC1TXqvU=" crossorigin=""></script> | ||
|
||
<script> | ||
// Parse URL parameters | ||
const params = new URLSearchParams(window.location.search); | ||
const group = params.get('group') || 'birds'; | ||
|
||
// Construct filename based on group parameter | ||
const randomString = Math.random().toString(36).substring(7); | ||
const dataFile = `data_${group}.csv?cache_bust=${randomString}`; | ||
|
||
// Initialize the map centered roughly on the world | ||
var map = L.map('map').setView([10,0], 2); | ||
|
||
|
@@ -53,35 +61,37 @@ | |
const columns = line.split(','); | ||
const obj = {}; | ||
headers.forEach((h, i) => { | ||
obj[h.trim()] = columns[i].trim(); | ||
obj[h.trim()] = columns[i]?.trim() || ''; | ||
}); | ||
return obj; | ||
}); | ||
} | ||
|
||
// Fetch and process the CSV | ||
fetch('birddata.csv?212') | ||
fetch(dataFile) | ||
.then(response => response.text()) | ||
.then(csvText => { | ||
const data = parseCSV(csvText); | ||
|
||
data.forEach(bird => { | ||
const name = bird['Unobserved Bird']; | ||
const lat = parseFloat(bird['Latitude']); | ||
const lng = parseFloat(bird['Longitude']); | ||
const taxonId = bird['taxon_id']; | ||
const commonName = bird['Common name']; | ||
data.forEach(item => { | ||
const name = item['Unobserved Bird'] || item['Unobserved Reptile'] || 'Unknown species'; | ||
const lat = parseFloat(item['Latitude']); | ||
const lng = parseFloat(item['Longitude']); | ||
const taxonId = item['taxon_id']; | ||
const commonName = item['Common name'] || name; | ||
|
||
// Construct the popup HTML | ||
const taxaLink = `https://www.inaturalist.org/taxa/${taxonId}`; | ||
const obsLink = `https://www.inaturalist.org/observations?lat=${lat}&lng=${lng}&verifiable=true&radius=10`; | ||
|
||
const popupContent = ` | ||
<div> | ||
<a href="${taxaLink}" target="_blank"><b>${commonName}</a><br> | ||
<a href="${obsLink}" target="_blank"><i>(nearby observations)</i></a> | ||
</div> | ||
`; | ||
let popupContent = `<div><b>${commonName}</b></div>`; | ||
if (taxonId) { | ||
const taxaLink = `https://www.inaturalist.org/taxa/${taxonId}`; | ||
const obsLink = `https://www.inaturalist.org/observations?lat=${lat}&lng=${lng}&verifiable=true&radius=10`; | ||
popupContent = ` | ||
<div> | ||
<a href="${taxaLink}" target="_blank"><b>${commonName}</b></a><br> | ||
<a href="${obsLink}" target="_blank"><i>(nearby observations)</i></a> | ||
</div> | ||
`; | ||
} | ||
|
||
// Add a marker | ||
if (!isNaN(lat) && !isNaN(lng)) { | ||
|