Skip to content

Commit

Permalink
day2 - lines
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosci committed Nov 2, 2021
1 parent 59b0f2d commit 60d4cd0
Show file tree
Hide file tree
Showing 8 changed files with 22,744 additions and 4 deletions.
43 changes: 43 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"type": "module",
"dependencies": {
"leaflet": "^1.7.1",
"leaflet-ajax": "^2.1.0",
"leaflet-minimap": "^3.6.1",
"leaflet.control.opacity": "^1.6.0"
}
Expand Down
3 changes: 1 addition & 2 deletions src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
<head>
<meta charset="utf-8" />
<link rel="icon" href="/favicon.ico" />
<script src="plugin/Leaflet.Control.Opacity/dist/L.Control.Opacity.js"></script>
<link href="plugin/Leaflet.Control.Opacity/dist/L.Control.Opacity.css" rel="stylesheet" />

<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- Global site tag (gtag.js) - Google Analytics -->
Expand All @@ -15,6 +13,7 @@
gtag('js', new Date());

gtag('config', 'G-KKMHKSHQ32');
var global = window;
</script>
%svelte.head%
</head>
Expand Down
57 changes: 55 additions & 2 deletions src/lib/LeafletMap.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import { browser } from "$app/env";
import SidebarLeft from "$lib/SidebarLeft.svelte";
import SidebarRight from "$lib/SidebarRight.svelte";
import curiosity_path from "$lib/data/curiosity_path.json";
import perseverance_path from "$lib/data/perseverance_path.json";
import helicopter_path from "$lib/data/helicopter_path.json";
onMount(async () => {
if (browser) {
Expand Down Expand Up @@ -37,7 +40,7 @@
}).bindPopup(
"<b>Spirit</b><br> <img style='width: 300px' src='https://upload.wikimedia.org/wikipedia/commons/thumb/f/f8/KSC-03PD-0786.jpg/2880px-KSC-03PD-0786.jpg'> <br> <a href='https://en.wikipedia.org/wiki/Spirit_(rover)'>Learn more about me!</a>"
),
curiosity = L.marker([-4.5895, 137.4417], {
curiosity = L.marker([-4.589467, 137.441633], {
icon: roverIcon,
}).bindPopup(
"<b>Curiosity</b><br> <img style='width: 300px' src='https://upload.wikimedia.org/wikipedia/commons/thumb/f/f3/Curiosity_Self-Portrait_at_%27Big_Sky%27_Drilling_Site.jpg/1920px-Curiosity_Self-Portrait_at_%27Big_Sky%27_Drilling_Site.jpg'> <br> <a href='https://en.wikipedia.org/wiki/Curiosity_(rover)'>Learn more about me!</a>"
Expand Down Expand Up @@ -84,7 +87,8 @@
"<b>Viking 2</b><br> <img style='width: 300px' src='https://upload.wikimedia.org/wikipedia/commons/7/75/Viking_spacecraft.jpg' > <br> <a href='https://en.wikipedia.org/wiki/Viking_2'>Learn more about me!</a>"
);
var landingsites = L.layerGroup([
// group them as featureGroup
var landingsites = L.featureGroup([
mars2,
mars3,
deepspace2,
Expand All @@ -104,6 +108,7 @@
viking2,
]);
// define underlying basemaps
var baseMaps = {
Basemap: L.tileLayer(
"https://cartocdn-gusc.global.ssl.fastly.net/opmbuilder/api/v1/map/named/opm-mars-basemap-v0-2/all/{z}/{x}/{y}.png",
Expand Down Expand Up @@ -194,10 +199,47 @@
),
};
// rover paths
var roverStyle = {
color: "#ff7800",
weight: 5,
opacity: 0.65,
};
var heliStyle = {
color: "#ffac62",
weight: 5,
opacity: 0.65,
};
var curiosity_line = L.geoJSON(curiosity_path, {
style: roverStyle,
});
var perseverance_line = L.geoJSON(perseverance_path, {
style: roverStyle,
});
var helicopter_line = L.geoJSON(helicopter_path, {
style: heliStyle,
});
helicopter_line.bindTooltip("Perseverance copter flight path");
curiosity_line.bindTooltip("Curiosity rover path");
perseverance_line.bindTooltip("Perseverance rover path");
var curiosityPaths = L.featureGroup([curiosity_line]);
var perseverancePaths = L.featureGroup([
perseverance_line,
helicopter_line,
]);
var overlayMaps = {
"Landing Sites": landingsites,
Curiosity: curiosityPaths,
Perseverance: perseverancePaths,
};
// let s do the actual map
const map = leaflet
.map("map", {
layers: [landingsites, baseMaps.Basemap],
Expand Down Expand Up @@ -225,6 +267,17 @@
map.on("baselayerchange", function (e) {
miniMap.changeLayer(baseMaps_minimap[e.name]);
});
// zoom to extent of selected layer
map.on("overlayadd", function (e) {
if (e.name === "Landing Sites") {
map.fitBounds(landingsites.getBounds());
} else if (e.name === "Perseverance") {
map.fitBounds(perseverancePaths.getBounds());
} else if (e.name === "Curiosity") {
map.fitBounds(curiosityPaths.getBounds());
}
});
}
});
</script>
Expand Down
Loading

0 comments on commit 60d4cd0

Please sign in to comment.