feat: snap to stops in easy mode
All checks were successful
deploy to cloudflare pages / deploy (push) Successful in 32s
All checks were successful
deploy to cloudflare pages / deploy (push) Successful in 32s
This commit is contained in:
parent
1dc77d6d2a
commit
3ff96cc411
3 changed files with 16 additions and 11 deletions
|
@ -8,7 +8,7 @@ export interface GameOptions {
|
|||
|
||||
export interface GameData {
|
||||
lines: [GeoJSON.Feature, string][];
|
||||
stops: GeoJSON.Feature[];
|
||||
stops: [number, number][];
|
||||
stopName: string;
|
||||
gameId: string;
|
||||
}
|
||||
|
|
|
@ -32,8 +32,9 @@ export const load: PageServerLoad = async ({ fetch, url, platform }) => {
|
|||
const lineCodes = new Set<string>(lineColors.map(([f, _]) => f.properties!.code_ligne));
|
||||
const crossingStops = await getMergedStops(fetch, lineCodes);
|
||||
|
||||
const strippedStops = crossingStops.map((f) => {
|
||||
return { ...f, properties: {} };
|
||||
const strippedStops: [number, number][] = crossingStops.map((f) => {
|
||||
const coords = (f.geometry as GeoJSON.Point).coordinates;
|
||||
return [coords[1], coords[0]];
|
||||
});
|
||||
|
||||
const randomStop = crossingStops[Math.floor(Math.random() * crossingStops.length)];
|
||||
|
|
|
@ -23,6 +23,13 @@
|
|||
function createMap(node: HTMLElement) {
|
||||
map = L.map(node).setView(center, 13);
|
||||
|
||||
function setMarker(pos: L.LatLng) {
|
||||
if (map && playerMarker && !results) {
|
||||
playerMarker.setLatLng(pos);
|
||||
latlng = pos;
|
||||
}
|
||||
}
|
||||
|
||||
L.tileLayer(`https://basemaps.cartocdn.com/light_nolabels/{z}/{x}/{y}{r}.png`, {
|
||||
attribution:
|
||||
'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors © <a href="https://carto.com/attributions">CARTO</a>',
|
||||
|
@ -33,17 +40,14 @@
|
|||
data.gameData.lines.forEach(([feature, color]) => {
|
||||
L.geoJSON(feature, { style: { color } }).addTo(map!);
|
||||
});
|
||||
data.gameData.stops.forEach((f) => L.geoJSON(f).addTo(map!));
|
||||
data.gameData.stops.forEach((coords) => {
|
||||
const marker = L.marker(coords).addTo(map!);
|
||||
marker.on("click", (e) => setMarker(e.latlng));
|
||||
});
|
||||
|
||||
const playerMarker = L.marker([0, 0]).addTo(map);
|
||||
|
||||
map.on("click", (e) => {
|
||||
if (map && playerMarker && !results) {
|
||||
playerMarker.setLatLng(e.latlng);
|
||||
latlng = e.latlng;
|
||||
}
|
||||
});
|
||||
|
||||
map.on("click", (e) => setMarker(e.latlng));
|
||||
map.on("keydown", (e) => {
|
||||
if (latlng.lat !== 0 && latlng.lng !== 0 && e.originalEvent.key === " ") {
|
||||
checkLocation();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue