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

Add support for OpenStreetMap #50

Merged
merged 4 commits into from
Oct 17, 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
3 changes: 2 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export default [
languageOptions: {
globals: {
...globals.browser,
...globals.node
...globals.node,
L: 'readonly'
}
}
},
Expand Down
37 changes: 36 additions & 1 deletion package-lock.json

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

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
"type": "module",
"dependencies": {
"@fortawesome/free-regular-svg-icons": "^6.6.0",
"onebusaway-sdk": "^1.0.1"
"@googlemaps/js-api-loader": "^1.16.8",
"leaflet": "^1.9.4",
"leaflet-polylinedecorator": "^1.6.0",
"onebusaway-sdk": "^1.0.1",
"polyline-encoded": "^0.0.9"
}
}
31 changes: 31 additions & 0 deletions src/assets/styles/leaflet-map.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.leaflet-touch {
.leaflet-bar {
position: absolute;
bottom: 6px;
padding: 0px;
right: 0px;

.leaflet-control-zoom-in,
.leaflet-control-zoom-out {
width: 2.2rem;
height: 40px;
margin: 1.6px;
padding: 0px;
z-index: 5;
}

.leaflet-control-zoom-out span .leaflet-control-zoom-in span {
width: 2.2rem;
height: 2.2rem;
background-repeat: no-repeat;
align-items: center;
}
}

.leaflet-control-attribution {
display: none;
}
}
.leaflet-control {
background-color: #fff;
}
48 changes: 48 additions & 0 deletions src/components/MapContainer.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<script>
import MapView from './map/MapView.svelte';
import GoogleMapProvider from '$lib/Provider/GoogleMapProvider';
import OpenStreetMapProvider from '$lib/Provider/OpenStreetMapProvider';
import {
PUBLIC_OBA_MAP_PROVIDER,
PUBLIC_OBA_GOOGLE_MAPS_API_KEY as apiKey
} from '$env/static/public';
import { createEventDispatcher, onMount } from 'svelte';
import { MapSource } from './../config/mapSource.js';

let mapProvider = null;
let mapSource = null;
const dispatch = createEventDispatcher();

onMount(() => {
if (PUBLIC_OBA_MAP_PROVIDER === MapSource.Google) {
mapProvider = new GoogleMapProvider(apiKey);
mapSource = MapSource.Google;
} else if (PUBLIC_OBA_MAP_PROVIDER === MapSource.OpenStreetMap) {
mapProvider = new OpenStreetMapProvider(apiKey);
mapSource = MapSource.OpenStreetMap;
} else {
console.error('Unknown map provider:');
}
});

function forward(event) {
dispatch(event.type, event.detail);
}
</script>

{#if mapProvider}
<MapView
{mapProvider}
{mapSource}
{...$$props}
on:stopSelected={forward}
on:selectedTrip={forward}
on:selectedRoute={forward}
on:showRoute={forward}
on:showRouteMap={forward}
on:stop={forward}
on:mapProvider={forward}
/>
{:else}
<p>Loading map...</p>
{/if}
Loading
Loading