Skip to content
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
47 changes: 47 additions & 0 deletions custom-icons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {
ClassicBus,
ClassicGondola,
ClassicModeIcon,
Ferry,
LegIcon,
StandardGondola
} from '@opentripplanner/icons'

/**
* For more advanced users, you can replicate and customize components and
* observe the change in icons.
* - For LegIcon: https://github.com/opentripplanner/otp-ui/blob/master/packages/icons/src/trimet-leg-icon.js
* - For ModeIcon: https://github.com/opentripplanner/otp-ui/blob/master/packages/icons/src/trimet-mode-icon.js
* The example below shuffles some icons around from what you might normally
* expect for demonstration purposes.
*/

const CustomTransitIcon = Ferry
const CustomRailIcon = ClassicGondola
const CustomStreetcarIcon = StandardGondola
const CustomBikeRentalIcon = ClassicBus

export const CustomModeIcon = ({ mode, ...props }) => {
if (!mode) return null
switch (mode.toLowerCase()) {
// Place custom icons for each mode here.
case 'transit':
return <CustomTransitIcon {...props} />
case 'rail':
return <CustomRailIcon {...props} />
default:
return <ClassicModeIcon mode={mode} {...props} />
}
}

export const CustomLegIcon = ({ leg, ...props }) => {
if (
leg.routeLongName &&
leg.routeLongName.startsWith('MAX')
) {
return <CustomStreetcarIcon />
} else if (leg.rentedBike) {
return <CustomBikeRentalIcon />
}
return <LegIcon leg={leg} ModeIcon={CustomModeIcon} {...props} />
}
62 changes: 11 additions & 51 deletions example.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
// import this polyfill in order to make webapp compatible with IE 11
import 'es6-math'

// The commented imports below are used in the custom icons example.
import {
// ClassicBus,
// ClassicGondola,
ClassicLegIcon,
ClassicModeIcon,
// Ferry,
// LegIcon,
// StandardGondola
} from '@opentripplanner/icons'

import {ClassicLegIcon, ClassicModeIcon} from '@opentripplanner/icons'
import { createHashHistory } from 'history'
import { connectRouter, routerMiddleware } from 'connected-react-router'
import React, { Component } from 'react'
Expand All @@ -20,7 +10,6 @@ import { createStore, combineReducers, applyMiddleware, compose } from 'redux'
import { Provider } from 'react-redux'
import thunk from 'redux-thunk'
import createLogger from 'redux-logger'

// import Bootstrap Grid components for layout
import { Navbar, Grid, Row, Col } from 'react-bootstrap'

Expand All @@ -33,51 +22,22 @@ import {
AppMenu,
createOtpReducer
} from './lib'

// load the OTP configuration
import otpConfig from './config.yml'

// Define icon sets for modes.
const MyLegIcon = ClassicLegIcon
const MyModeIcon = ClassicModeIcon

/**
* For more advanced users, you can replicate and customize components and observe the change in icons.
* - For LegIcon: https://github.com/opentripplanner/otp-ui/blob/master/packages/icons/src/trimet-leg-icon.js
* - For ModeIcon: https://github.com/opentripplanner/otp-ui/blob/master/packages/icons/src/trimet-mode-icon.js
* The example below shuffles some icons around for demonstration purposes.
*/
/*
const CustomTransitIcon = Ferry
const CustomRailIcon = ClassicGondola
const CustomStreetcarIcon = StandardGondola
const CustomBikeRentalIcon = ClassicBus
// Set useCustomIcons to true to override classic icons with the exports from
// custom-icons.js
const useCustomIcons = false

const MyModeIcon = ({ mode, ...props }) => {
if (!mode) return null;
switch (mode.toLowerCase()) {
// Place custom icons for each mode here.
case "transit":
return <CustomTransitIcon {...props} />
case "rail":
return <CustomRailIcon {...props} />
default:
return <ClassicModeIcon mode={mode} {...props} />
}
}
// Define icon sets for modes.
let MyLegIcon = ClassicLegIcon
let MyModeIcon = ClassicModeIcon

const MyLegIcon = ({ leg, ...props }) => {
if (
leg.routeLongName &&
leg.routeLongName.startsWith('MAX')
) {
return <CustomStreetcarIcon />
} else if (leg.rentedBike) {
return <CustomBikeRentalIcon />
}
return <LegIcon leg={leg} ModeIcon={MyModeIcon} {...props} />
if (useCustomIcons) {
const CustomIcons = require('./custom-icons')
MyLegIcon = CustomIcons.CustomLegIcon
MyModeIcon = CustomIcons.CustomModeIcon
}
*/

// create an initial query for demo/testing purposes
const initialQuery = {
Expand Down