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

Map tweaks #117

Merged
merged 7 commits into from
Nov 18, 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
6,270 changes: 4,155 additions & 2,115 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/app/student/map/_components/BoothMarker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export function BoothMarker({ booth, scale }: { booth: Booth; scale: number }) {
key={booth.id}
longitude={booth.center[0]}
latitude={booth.center[1]}>
<div className="cursor-default" style={{ transform: `scale(${scale})` }}>
<div
className="cursor-default transition"
style={{ transform: `scale(${scale})` }}>
{logoSrc ? (
<div className="flex size-[60px]">
<Image
Expand Down
2 changes: 1 addition & 1 deletion src/app/student/map/_components/MainView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default function MainView({
filteredBooths={filteredBooths}
setFilteredBooths={setFilteredBooths}
/>
<div className="h-[calc(100dvh-144px)] flex-grow">
<div className="h-[calc(100dvh-144px)] flex-grow sm:h-full">
<MapComponent
initialView={initialView}
boothsById={currentLocationBoothsById}
Expand Down
47 changes: 19 additions & 28 deletions src/app/student/map/_components/MapComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
import { BoothMap, GeoJsonBooth } from "../lib/booths"
import {
addMapIconAssets,
backgroundLayerStyle,
boothLayerStyle,
boothOutlineStyle,
buildingLayerStyle,
Expand Down Expand Up @@ -56,9 +55,7 @@ export function MapComponent({

const mapRef = useRef<MapRef>(null)

const [mapZoom, setMapZoom] = useState(initialView.zoom)

const [markerScale, setMarkerScale] = useState(1)
const [markerScale, setMarkerScale] = useState(0.5)

const [preLocationId, setPreLocationId] = useState<LocationId>(location.id)
// Fly to location center on change
Expand All @@ -76,7 +73,6 @@ export function MapComponent({
const { pathname } = window.location
window.history.replaceState(null, "", pathname)
}, 300)
setMarkerScale(0.6)
return () => clearTimeout(timeout)
}, [location])

Expand Down Expand Up @@ -171,9 +167,10 @@ export function MapComponent({
function onZoomChange() {
const zoom = mapRef.current?.getZoom()
if (zoom === undefined) return
const scale = Math.max(0.2, Math.min(1, 1 + (zoom - 20) * 0.5))
setMarkerScale(scale)
setMapZoom(zoom)

if (zoom < 18.5) setMarkerScale(0.2)
else if (zoom < 20.5) setMarkerScale(0.5)
else setMarkerScale(1.0)
}

return (
Expand All @@ -195,8 +192,6 @@ export function MapComponent({
]}
dragRotate={false}
mapStyle="https://api.maptiler.com/maps/376fa556-c405-4a91-8e9e-15be82eb3a58/style.json?key=mgMcr2yF2fWUHzf27ygv">
<Layer {...backgroundLayerStyle}></Layer>

{/** Order sensitive! */}
<Source
id="buildings"
Expand Down Expand Up @@ -238,25 +233,21 @@ export function MapComponent({
<Layer {...lineLayerStyle}></Layer>
</Source>

{mapZoom > 19 && (
<Source
id="nymble-plan-routes"
type="geojson"
promoteId={"id"}
data={geoJsonPlanRoutesData}>
<Layer {...routeLayerStyle}></Layer>
</Source>
)}
<Source
id="nymble-plan-routes"
type="geojson"
promoteId={"id"}
data={geoJsonPlanRoutesData}>
<Layer {...routeLayerStyle}></Layer>
</Source>

{mapZoom > 19 && (
<Source
id="nymble-plan-points"
type="geojson"
promoteId={"id"}
data={geoJsonPlanData}>
<Layer {...symbolLayerStyle}></Layer>
</Source>
)}
<Source
id="nymble-plan-points"
type="geojson"
promoteId={"id"}
data={geoJsonPlanData}>
<Layer {...symbolLayerStyle}></Layer>
</Source>

{markers}
</MapboxMap>
Expand Down
20 changes: 6 additions & 14 deletions src/app/student/map/_components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area"
import { cn } from "@/lib/utils"
import {
ArrowLeft,
ChevronsLeft,
ChevronsRight,
EraserIcon,
FilterIcon,
MapIcon,
Expand Down Expand Up @@ -135,7 +133,6 @@ export default function Sidebar({
onClick={() => setActiveDrawerBoothId(null)}>
<ArrowLeft size={30} className="stroke-stone-400" />
</Button>

<div className="flex justify-end py-2">
<Button
className="flex gap-2"
Expand Down Expand Up @@ -342,22 +339,17 @@ function SidebarContainer({
)
}

// Sidebar is always open on desktop
return (
<div className={cn("relative h-full", open ? "w-[500px]" : "w-0")}>
<div className={cn("relative h-full w-[500px] overflow-hidden")}>
<DrawerHeader>
<Dialog>{header}</Dialog>
</DrawerHeader>

<ScrollArea className="h-full">
{children}
<ScrollBar></ScrollBar>
</ScrollArea>

<div className="absolute right-[-38px] top-0 z-20">
<Button
variant="ghost"
className="rounded-s-none border-none p-1"
onClick={() => setOpen(!open)}
title={open ? "Close sidebar" : "Open sidebar"}>
{open ? <ChevronsLeft size={30} /> : <ChevronsRight size={30} />}
</Button>
</div>
</div>
)
}
17 changes: 13 additions & 4 deletions src/app/student/map/editor/EditorMapComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
makeBooth
} from "@/app/student/map/lib/booths"
import {
backgroundLayerStyle,
buildingLayerStyle,
lineLayerStyle,
routeLayerStyle,
Expand Down Expand Up @@ -74,8 +73,10 @@ export default function EditorMapComponent({

const [booths, setBooths] = useState<Booth[]>([])

const [markerScale, setMarkerScale] = useState(0.5)

const markers = booths.map(booth => (
<BoothMarker key={booth.id} booth={booth} scale={1} />
<BoothMarker key={booth.id} booth={booth} scale={markerScale} />
))

const draw = useMemo(() => {
Expand Down Expand Up @@ -140,6 +141,15 @@ export default function EditorMapComponent({
updateBooths()
}

function onZoomChange() {
const zoom = mapRef.current?.getZoom()
if (zoom === undefined) return

if (zoom < 18.5) setMarkerScale(0.2)
else if (zoom < 20.5) setMarkerScale(0.5)
else setMarkerScale(1.0)
}

// Effects ----------------------------------------------

function initializeDraw() {
Expand Down Expand Up @@ -200,6 +210,7 @@ export default function EditorMapComponent({
<MapboxMap
ref={mapRef}
onLoad={() => setMapLoaded(true)}
onZoom={onZoomChange}
initialViewState={{
longitude: 18.070567,
latitude: 59.34726,
Expand All @@ -213,8 +224,6 @@ export default function EditorMapComponent({
[18.079, 59.35]
]}
mapStyle="https://api.maptiler.com/maps/376fa556-c405-4a91-8e9e-15be82eb3a58/style.json?key=mgMcr2yF2fWUHzf27ygv">
<Layer {...backgroundLayerStyle}></Layer>

{/** Order sensitive! */}
<Source
id="buildings"
Expand Down
16 changes: 3 additions & 13 deletions src/app/student/map/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ const style = {
routeHintColor: "#F3ECC3",
routeHintWidth: 1,

roomBackgroundColor: "#1f2b24",

backgroundColor: "#40d07e",
backgroundOpacity: 0.0
roomBackgroundColor: "#1f2b24"
} as const

export enum LineType {
Expand Down Expand Up @@ -158,15 +155,6 @@ export const roomLayerStyle: FillLayer = {
}
}

export const backgroundLayerStyle: BackgroundLayer = {
id: "background",
type: "background",
paint: {
"background-color": style.backgroundColor,
"background-opacity": style.backgroundOpacity
}
}

export const lineLayerStyle: LineLayer = {
source: "lines",
id: "lines",
Expand All @@ -183,6 +171,7 @@ export const routeLayerStyle: LineLayer = {
id: "routes",
type: "line",
filter: ["==", "$type", "LineString"],
minzoom: 19,
paint: {
"line-color": [
"case",
Expand Down Expand Up @@ -210,6 +199,7 @@ export const symbolLayerStyle: SymbolLayer = {
id: "points",
type: "symbol",
filter: ["==", "$type", "Point"],
minzoom: 19,
layout: {
// Specify which image to use for each PointType
"icon-image": [
Expand Down
12 changes: 6 additions & 6 deletions src/app/student/map/lib/locations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ export type Location = {
}

const nymbleCenter = {
longitude: 18.070408551823675,
latitude: 59.34726434961294,
zoom: 19
longitude: 18.070592659323438,
latitude: 59.347274028818134,
zoom: 18.891181298825842
}

const libraryCenter = {
longitude: 18.072008997107673,
latitude: 59.347931139608846,
zoom: 19
longitude: 18.072310911561203,
latitude: 59.3479216743261,
zoom: 18.11485244486189
}

export const locations: Location[] = [
Expand Down
Loading