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

Public transport labels fixes #187

Merged
merged 6 commits into from
Sep 24, 2023
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
48 changes: 47 additions & 1 deletion src/components/FeaturePanel/PublicTransport/LineNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,52 @@ interface LineNumberProps {
color: string;
}

/**
* A function to map a color name to hex. When a color is not found, it is returned as is, the same goes for hex colors.
* @param color The color to map to hex
* @returns The color in hex format, e.g. #ff0000
*/
function mapColorToHex(color: string) {
switch (color.toLowerCase()) {
case 'black':
return '#000000';
case 'gray':
case 'grey':
return '#808080';
case 'maroon':
return '#800000';
case 'olive':
return '#808000';
case 'green':
return '#008000';
case 'teal':
return '#008080';
case 'navy':
return '#000080';
case 'purple':
return '#800080';
case 'white':
return '#ffffff';
case 'silver':
return '#c0c0c0';
case 'red':
return '#ff0000';
case 'yellow':
return '#ffff00';
case 'lime':
return '#00ff00';
case 'aqua':
case 'cyan':
return '#00ffff';
case 'blue':
return '#0000ff';
case 'fuchsia':
case 'magenta':
return '#ff00ff';
default:
return color;
}
}
/**
* A function to determine whether the text color should be black or white
* @param hexBgColor The background color in hex format, e.g. #ff0000
Expand All @@ -26,7 +72,7 @@ export const LineNumber: React.FC<LineNumberProps> = ({ name, color }) => {
let bgcolor: string;
if (!color) bgcolor = darkmode ? '#898989' : '#dddddd';
// set the default color
else bgcolor = color.toLowerCase();
else bgcolor = mapColorToHex(color);

const divStyle: React.CSSProperties = {
backgroundColor: bgcolor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ export const PublicTransport: React.FC<PublicTransportProps> = ({ tags }) => {
const isPublicTransport =
Object.keys(tags).includes('public_transport') ||
tags.railway === 'station' ||
tags.railway === 'halt' ||
tags.railway === 'subway_entrance';
tags.railway === 'halt';

if (!isPublicTransport) {
return null;
Expand Down
10 changes: 3 additions & 7 deletions src/components/FeaturePanel/PublicTransport/requestRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@ export interface LineInformation {
export async function requestLines(
featureType: 'node' | 'way' | 'relation',
id: number,
radius = 150,
) {
// use the overpass api to request the lines in
const overpassQuery = `[out:csv(ref, colour; false; ';')];
${featureType}(${id})->.center;
(
node(around.center:${radius})["public_transport"="stop_position"];
nw(around.center:${radius})["highway"="bus_stop"];
nwr(around.center:${radius})["amenity"="ferry_terminal"];
) -> .stops;
${featureType}(${id});
rel(bn)["public_transport"="stop_area"];
node(r: "stop") -> .stops;
rel(bn.stops)["route"~"bus|train|tram|subway|light_rail|ferry|monorail"];
Comment on lines +14 to 17
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, this is some advanced query! I will have to study how this works. It could be useful on my other PR #186 .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see also here: #387

out;`;

Expand Down