Skip to content

Commit

Permalink
Fix map icon to rocketship, remove ISS icon, adjust map angle calcula…
Browse files Browse the repository at this point in the history
…tion for spaceship icon
  • Loading branch information
pauljones0 committed Sep 13, 2024
1 parent 9a259ea commit 392fc35
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Binary file removed assets/images/iss-icon.png
Binary file not shown.
10 changes: 6 additions & 4 deletions scripts/index-page.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ISSApi } from "./iss-api.js";
import { calculateAngle } from "./utilities.js";
import { calculateAngle, adjustAngleForIcon } from "./utilities.js";

let map;
let marker;
Expand All @@ -19,7 +19,7 @@ const issPosititoData = async (isInitialCall = false) => {
}

const issIcon = L.icon({
iconUrl: './assets/images/iss-icon.png',
iconUrl: 'assets/icons/favicon.ico',
iconSize: [32, 32],
iconAnchor: [16, 16],
});
Expand All @@ -31,11 +31,13 @@ const issPosititoData = async (isInitialCall = false) => {

if (!marker && prevPosition) {
const angle = calculateAngle(prevPosition, newLatLng);
marker = L.marker(newLatLng, {icon: issIcon, rotationAngle: angle, rotationOrigin: 'center center'}).addTo(map);
const adjustedAngle = adjustAngleForIcon(angle);
marker = L.marker(newLatLng, {icon: issIcon, rotationAngle: adjustedAngle, rotationOrigin: 'center center'}).addTo(map);
} else if (marker && prevPosition) {
const angle = calculateAngle(prevPosition, newLatLng);
const adjustedAngle = adjustAngleForIcon(angle);
marker.setLatLng(newLatLng);
marker.setRotationAngle(angle);
marker.setRotationAngle(adjustedAngle);
}

map.setView(newLatLng, 3);
Expand Down
6 changes: 6 additions & 0 deletions scripts/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ export function calculateAngle(prev, next) {

return (angle + 360) % 360;
}

export function adjustAngleForIcon(angle) {
// Subtract 45 degrees to compensate for the icon's initial rotation
// Then normalize to ensure the angle is between 0 and 360
return (angle - 45 + 360) % 360;
}

0 comments on commit 392fc35

Please sign in to comment.