Skip to content

Commit

Permalink
added other groups
Browse files Browse the repository at this point in the history
  • Loading branch information
loarie committed Dec 18, 2024
1 parent afd25b9 commit 42778c0
Show file tree
Hide file tree
Showing 6 changed files with 8,320 additions and 18 deletions.
Binary file modified .DS_Store
Binary file not shown.
2,915 changes: 2,915 additions & 0 deletions 500k_post/data_amphibians.csv

Large diffs are not rendered by default.

File renamed without changes.
2,266 changes: 2,266 additions & 0 deletions 500k_post/data_mammals.csv

Large diffs are not rendered by default.

3,111 changes: 3,111 additions & 0 deletions 500k_post/data_reptiles.csv

Large diffs are not rendered by default.

46 changes: 28 additions & 18 deletions 500k_post/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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);

Expand All @@ -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)) {
Expand Down

0 comments on commit 42778c0

Please sign in to comment.