Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/map type toggle button #43

Merged
merged 4 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/components/map/GoogleMap.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import LocationButton from '$lib/LocationButton/LocationButton.svelte';
import StopMarker from './StopMarker.svelte';
import RouteMap from './RouteMap.svelte';

import MapTypeButton from '$lib/MapTypeButton/MapTypeButton.svelte';
import { faBus } from '@fortawesome/free-solid-svg-icons';
import {
RouteType,
Expand All @@ -32,6 +34,7 @@
const dispatch = createEventDispatcher();

let map = null;
let mapTypeId = 'roadmap';

let markers = [];
let allStops = [];
Expand Down Expand Up @@ -204,6 +207,13 @@
});
}

function handleMapTypeChange(event) {
mapTypeId = event.detail;
if (map) {
map.setMapTypeId(mapTypeId);
}
}

onMount(async () => {
if (!window.google) {
loadGoogleMapsLibrary(apiKey);
Expand Down Expand Up @@ -237,6 +247,7 @@
{/if}

<LocationButton on:locationObtained={handleLocationObtained} />
<MapTypeButton {mapTypeId} on:mapTypeChanged={handleMapTypeChange} />

<style>
#map {
Expand Down
58 changes: 58 additions & 0 deletions src/lib/MapTypeButton/MapTypeButton.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<script>
import { createEventDispatcher } from 'svelte';

const dispatch = createEventDispatcher();
export let mapTypeId = 'roadmap';

const mapTypes = ['roadmap', 'satellite', 'hybrid', 'terrain'];

function cycleMapType() {
const currentIndex = mapTypes.indexOf(mapTypeId);
const nextIndex = (currentIndex + 1) % mapTypes.length;
mapTypeId = mapTypes[nextIndex];
dispatch('mapTypeChanged', mapTypeId);
}

function getMapTypeIcon(type) {
switch (type) {
case 'roadmap':
return '🗺️';
case 'satellite':
return '🛰️';
case 'hybrid':
return '🌎';
case 'terrain':
return '⛰️';
default:
return '🗺️';
}
}
</script>

<button class="map-type-button" on:click={cycleMapType}>
{getMapTypeIcon(mapTypeId)}
</button>

<style>
.map-type-button {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To maintain consistency, you can use the Tailwind CSS inline at the button.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I noticed that we use tailwind in the codebase. I’m not familiar with it yet, but I plan to learn it and rewrite the styles using tailwind. I initially wrote in regular css because I saw that the location button was already styled that way.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, no problem. We will add the button CSS code into a global CSS file in the future.

background-color: #fff;
border-radius: 2px;
box-shadow: 0 1px 4px -1px rgba(0, 0, 0, 0.3);
margin: 10px;
font-size: 25px;
color: #666;
overflow: hidden;
height: 40px;
width: 40px;
position: absolute;
bottom: 5.8em;
right: 0;
display: flex;
align-items: center;
justify-content: center;
}

.map-type-button:hover {
background-color: #f0f0f0;
}
</style>
Loading