-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
267 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<script lang="ts"> | ||
import { GoogleMapsAdapter } from "$lib/maps/GoogleMapsAdapter"; | ||
import type { MapAdapter } from "$lib/maps/MapAdapter"; | ||
import { createEventDispatcher, onMount } from "svelte"; | ||
const dispatch = createEventDispatcher(); | ||
// @ts-ignore | ||
export let mapAdapter: MapAdapter = null; | ||
let container: HTMLDivElement; | ||
export let mapInfo: any; | ||
export let zoom = 17; | ||
export let center: number[]; | ||
//@ts-ignore | ||
window.initMap = () => { | ||
mapAdapter = new GoogleMapsAdapter(container, mapInfo, center, zoom); | ||
dispatch("ready", mapAdapter); | ||
}; | ||
</script> | ||
|
||
<svelte:head> | ||
<script | ||
defer | ||
async | ||
src="https://maps.googleapis.com/maps/api/js?key={mapInfo.apiKey}&callback=initMap" | ||
> | ||
</script> | ||
</svelte:head> | ||
|
||
<div class="full-screen" bind:this={container}></div> | ||
|
||
<style> | ||
.full-screen { | ||
width: 100vw; | ||
height: 100vh; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<script> | ||
// @ts-nocheck | ||
import { LeafletMapsAdapter } from "$lib/maps/LeaftletMapsAdapter"; | ||
import { createEventDispatcher, onMount } from "svelte"; | ||
const dispatch = createEventDispatcher(); | ||
/** | ||
* @type {HTMLDivElement} | ||
*/ | ||
let container; | ||
/** | ||
* @type {MapAdapter} | ||
*/ | ||
export let mapAdapter = null; | ||
/** | ||
* @type {number[]} | ||
*/ | ||
export let center; | ||
const ready = () => { | ||
mapAdapter = new LeafletMapsAdapter(container, center, 17) | ||
dispatch("ready", mapAdapter); | ||
}; | ||
</script> | ||
|
||
<svelte:head> | ||
<link | ||
rel="stylesheet" | ||
href="https://unpkg.com/[email protected]/dist/leaflet.css" | ||
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" | ||
crossorigin="" | ||
/> | ||
<script | ||
src="https://unpkg.com/[email protected]/dist/leaflet.js" | ||
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" | ||
on:load={ready} | ||
crossorigin="" | ||
></script> | ||
</svelte:head> | ||
|
||
<style> | ||
.full-screen { | ||
width: 100vw; | ||
height: 100vh; | ||
} | ||
</style> | ||
|
||
<div class="full-screen" bind:this={container}></div> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type { Service } from "$lib/stagecoachTypes"; | ||
import { MapAdapter } from "./MapAdapter"; | ||
|
||
export class GoogleMapsAdapter extends MapAdapter { | ||
map: google.maps.Map; | ||
marker: any; | ||
|
||
constructor( | ||
container: HTMLDivElement, | ||
mapOptions: any, | ||
startPos: number[], | ||
scale: number | ||
) { | ||
super(); | ||
|
||
this.map = new google.maps.Map(container, { | ||
zoom: scale, | ||
center: this.adaptLatLng(startPos), | ||
mapId: mapOptions.mapId, | ||
}); | ||
} | ||
|
||
async setupMarker(pos: number[], markerElement: HTMLElement) { | ||
//@ts-ignore | ||
const { AdvancedMarkerElement } = await google.maps.importLibrary("marker"); | ||
|
||
this.marker = new AdvancedMarkerElement({ | ||
position: this.adaptLatLng(pos), | ||
map: this.map, | ||
content: markerElement, | ||
}); | ||
} | ||
|
||
setMarkerPosition(pos: number[]) { | ||
this.marker.position = this.adaptLatLng(pos) | ||
} | ||
|
||
adaptLatLng([lat, lng]: number[]): google.maps.LatLng { | ||
return new google.maps.LatLng(lat, lng); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// @ts-nocheck | ||
import { MapAdapter } from "./MapAdapter"; | ||
|
||
export class LeafletMapsAdapter extends MapAdapter { | ||
map | ||
marker | ||
|
||
/** | ||
* @param {any} container | ||
* @param {any} startPos | ||
* @param {number} scale | ||
*/ | ||
constructor(container, startPos, scale) { | ||
super(); | ||
|
||
this.map = L.map(container).setView(startPos, scale); | ||
L.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png", { | ||
maxZoom: 19, | ||
attribution: | ||
'© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>', | ||
}).addTo(this.map); | ||
} | ||
|
||
setupMarker(pos, markerElement) { | ||
let marker = L.divIcon({ html: markerElement }) | ||
this.marker = L.marker(pos, { icon: marker }).addTo(this.map); | ||
} | ||
|
||
setMarkerPosition(pos) { | ||
let newPos = this.adaptLatLng(pos) | ||
this.marker.setLatLng(newPos) | ||
} | ||
|
||
adaptLatLng(pos) { | ||
return L.latLng(pos[0], pos[1]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export class MapAdapter { | ||
setupMarker(pos: number[], markerElement: HTMLElement) {} | ||
setMarkerPosition(pos: number[]) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
import type { Service } from "./stagecoachTypes" | ||
|
||
const BASE_URL = "/api/stagecoach" | ||
const BASE_URL = "http://localhost:8080" | ||
|
||
export function fetchVehicleInfo(fleetNo: string): Promise<Service> { | ||
return fetch(`${BASE_URL}/vehicle/${fleetNo}`) | ||
return fetch(`${BASE_URL}/api/stagecoach/vehicle/${fleetNo}`) | ||
.then(res => res.json()) | ||
} | ||
|
||
export function fetchMapInfo(): Promise<any> { | ||
return fetch(`${BASE_URL}/api/maps/info`) | ||
.then(res => res.json()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.