Skip to content

Commit

Permalink
Update marker
Browse files Browse the repository at this point in the history
  • Loading branch information
chunlaw committed Jan 7, 2024
1 parent 4ef3a3e commit 798a43e
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 43 deletions.
5 changes: 0 additions & 5 deletions public/img/bus.svg

This file was deleted.

4 changes: 2 additions & 2 deletions public/img/bus_ctb.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 17 additions & 3 deletions public/img/bus_jointly.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion public/img/bus_kmb.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion public/img/bus_mtr.svg → public/img/bus_lrtfeeder.svg
File renamed without changes
2 changes: 1 addition & 1 deletion public/img/bus_lwb.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion public/img/mtr.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
101 changes: 73 additions & 28 deletions src/components/route-eta/RouteMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface RouteMapProps {
routeId: string;
stops: Array<StopListEntry>;
stopIdx: number;
co: Company;
companies: Company[];
onMarkerClick: (idx: number, event: unknown) => void;
}

Expand All @@ -53,7 +53,7 @@ const RouteMap = ({
routeId,
stops,
stopIdx,
co,
companies,
onMarkerClick,
}: RouteMapProps) => {
const { geolocation, geoPermission, updateGeoPermission, colorMode } =
Expand Down Expand Up @@ -185,7 +185,7 @@ const RouteMap = ({
icon={StopMarker({
active: idx === stopIdx,
passed: idx < stopIdx,
co,
companies,
})}
alt={`${idx}. ${stop.name[i18n.language]}`}
eventHandlers={{
Expand Down Expand Up @@ -222,31 +222,68 @@ const geoJsonStyle = function (feature: GeoJSON.Feature) {
};
};

const StopMarker = ({ active, passed, co }) => {
if (co === "mtr") {
interface StopMarkerProps {
active: boolean;
passed: boolean;
companies: Company[];
}

const StopMarker = ({ active, passed, companies }: StopMarkerProps) => {
if (companies[0] === "mtr") {
return Leaflet.divIcon({
iconSize: [20, 20],
iconAnchor: [10, 10],
className: `${classes.mtrMarker} ${active ? classes.active : ""} ${
passed ? classes.passed : ""
}`,
className: `${classes.mtrMarker} ${classes.marker} ${
active ? classes.active : ""
} ${passed ? classes.passed : ""}`,
});
}
if (co.startsWith("gmb")) {
} else if (companies[0].startsWith("gmb")) {
return Leaflet.divIcon({
iconSize: [40, 40],
iconAnchor: [20, 40],
className: `${classes.gmbMarker} ${classes.marker} ${
active ? classes.active : ""
} ${passed ? classes.passed : ""}`,
});
} else if (companies.includes("lrtfeeder")) {
return Leaflet.divIcon({
iconSize: [40, 40],
iconAnchor: [20, 40],
className: `${classes.gmbMarker} ${active ? classes.active : ""} ${
passed ? classes.passed : ""
}`,
className: `${classes.lrtfeederMarker} ${classes.marker} ${
active ? classes.active : ""
} ${passed ? classes.passed : ""}`,
});
} else if (companies.includes("nlb")) {
return Leaflet.divIcon({
iconSize: [40, 40],
iconAnchor: [20, 40],
className: `${classes.nlbMarker} ${classes.marker} ${
active ? classes.active : ""
} ${passed ? classes.passed : ""}`,
});
} else if (companies.includes("ctb") && companies.includes("kmb")) {
return Leaflet.divIcon({
iconSize: [40, 40],
iconAnchor: [20, 40],
className: `${classes.jointlyMarker} ${classes.marker} ${
active ? classes.active : ""
} ${passed ? classes.passed : ""}`,
});
} else if (companies.includes("ctb")) {
return Leaflet.divIcon({
iconSize: [40, 40],
iconAnchor: [20, 40],
className: `${classes.ctbMarker} ${classes.marker} ${
active ? classes.active : ""
} ${passed ? classes.passed : ""}`,
});
}
return Leaflet.divIcon({
iconSize: [40, 40],
iconAnchor: [20, 40],
className: `${classes.marker} ${active ? classes.active : ""} ${
passed ? classes.passed : ""
}`,
className: `${classes.kmbMarker} ${classes.marker} ${
active ? classes.active : ""
} ${passed ? classes.passed : ""}`,
});
};

Expand All @@ -259,6 +296,11 @@ const classes = {
marker: `${PREFIX}-marker`,
mtrMarker: `${PREFIX}-mtrMarker`,
gmbMarker: `${PREFIX}-gmbMarker`,
ctbMarker: `${PREFIX}-ctbMarker`,
jointlyMarker: `${PREFIX}-jointlyMarker`,
lrtfeederMarker: `${PREFIX}-lrtfeederMarker`,
nlbMarker: `${PREFIX}-nlbMarker`,
kmbMarker: `${PREFIX}-kmbMarker`,
active: `${PREFIX}-active`,
passed: `${PREFIX}-passed`,
};
Expand All @@ -270,23 +312,26 @@ const rootSx: SxProps<Theme> = {
[`& .${classes.mapContainer}`]: {
height: "35vh",
},
[`& .${classes.marker}`]: {
zIndex: 618,
outline: "none",
backgroundImage: `url(/img/bus.svg)`,
backgroundSize: "cover",
},
[`& .${classes.mtrMarker}`]: {
zIndex: 618,
outline: "none",
backgroundImage: `url(/img/mtr.svg)`,
backgroundSize: "cover",
},
[`& .${classes.gmbMarker}`]: {
zIndex: 618,
outline: "none",
backgroundImage: `url(/img/minibus.svg)`,
backgroundSize: "cover",
},
[`& .${classes.ctbMarker}`]: {
backgroundImage: `url(/img/bus_ctb.svg)`,
},
[`& .${classes.jointlyMarker}`]: {
backgroundImage: `url(/img/bus_jointly.svg)`,
},
[`& .${classes.lrtfeederMarker}`]: {
backgroundImage: `url(/img/bus_lrtfeeder.svg)`,
},
[`& .${classes.nlbMarker}`]: {
backgroundImage: `url(/img/bus_nlb.svg)`,
},
[`& .${classes.kmbMarker}`]: {
backgroundImage: `url(/img/bus_kmb.svg)`,
},
[`& .${classes.active}`]: {
animation: "blinker 1.5s infinite",
Expand Down
2 changes: 1 addition & 1 deletion src/pages/RouteEta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ const RouteEta = () => {
routeId={routeId}
stops={stopsExtracted}
stopIdx={stopIdx}
co={co[0]}
companies={co}
onMarkerClick={onMarkerClick}
/>
)}
Expand Down

0 comments on commit 798a43e

Please sign in to comment.