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

[feat] Different path color based on sport type #741

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions src/utils/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,10 @@ export const NEED_FIX_MAP = false;
export const MAIN_COLOR = nike;
export const PROVINCE_FILL_COLOR = '#47b8e0';
export const COUNTRY_FILL_COLOR = dark_vanilla;

export const RUN_COLOR = MAIN_COLOR;
export const RUN_TRAIL_COLOR = 'rgb(255,153,51)';
export const CYCLING_COLOR = 'rgb(51,255,87)';
export const HIKING_COLOR = 'rgb(151,51,255)';
export const WALKING_COLOR = HIKING_COLOR;
export const SWIMMING_COLOR = 'rgb(255,51,51)';
29 changes: 26 additions & 3 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { WebMercatorViewport } from 'viewport-mercator-project';
import { chinaGeojson, RPGeometry } from '@/static/run_countries';
import worldGeoJson from '@surbowl/world-geo-json-zh/world.zh.json';
import { chinaCities } from '@/static/city';
import { MAIN_COLOR, MUNICIPALITY_CITIES_ARR, NEED_FIX_MAP, RUN_TITLES, ACTIVITY_TYPES, RICH_TITLE } from './const';
import { MAIN_COLOR, MUNICIPALITY_CITIES_ARR, NEED_FIX_MAP, RUN_TITLES, ACTIVITY_TYPES, RICH_TITLE, CYCLING_COLOR, HIKING_COLOR, WALKING_COLOR, SWIMMING_COLOR, RUN_COLOR, RUN_TRAIL_COLOR } from './const';
import { FeatureCollection, LineString } from 'geojson';

export type Coordinate = [number, number];
Expand Down Expand Up @@ -210,15 +210,38 @@ const pathForRun = (run: Activity): Coordinate[] => {
}
};

const colorForRun = (run: Activity): string => {
switch (run.type) {
case 'Run':{
if (run.subtype === 'trail') {
return RUN_TRAIL_COLOR;
} else if (run.subtype === 'generic') {
return RUN_COLOR;
}
return RUN_COLOR;
}
case 'cycling':
return CYCLING_COLOR;
case 'hiking':
return HIKING_COLOR;
case 'walking':
return WALKING_COLOR;
case 'swimming':
return SWIMMING_COLOR;
default:
return MAIN_COLOR;
}
}

const geoJsonForRuns = (runs: Activity[]): FeatureCollection<LineString> => ({
type: 'FeatureCollection',
features: runs.map((run) => {
const points = pathForRun(run);

const color = colorForRun(run);
return {
type: 'Feature',
properties: {
color: MAIN_COLOR,
color: color,
},
geometry: {
type: 'LineString',
Expand Down