diff --git a/lib/editor/components/EntityDetailsHeader.js b/lib/editor/components/EntityDetailsHeader.js index d807671e8..20fe6ccbe 100644 --- a/lib/editor/components/EntityDetailsHeader.js +++ b/lib/editor/components/EntityDetailsHeader.js @@ -10,7 +10,7 @@ import {getEntityBounds, getEntityName} from '../util/gtfs' import {entityIsNew} from '../util/objects' import {GTFS_ICONS} from '../util/ui' -import type {Entity, Feed, GtfsRoute, Pattern} from '../../types' +import type {Entity, Feed, GtfsRoute, GtfsStop, Pattern} from '../../types' import type {MapState} from '../../types/reducers' import type {EditorValidationIssue} from '../util/validation' @@ -20,6 +20,7 @@ type Props = { activeComponent: string, activeEntity: Entity, activePattern: Pattern, + activePatternStops: Array, editFareRules: boolean, entityEdited: boolean, feedSource: Feed, @@ -62,12 +63,12 @@ export default class EntityDetailsHeader extends Component { } _onClickZoomTo = () => { - const { activeEntity, subEntityId, updateMapSetting } = this.props + const { activeEntity, activePatternStops, subEntityId, updateMapSetting } = this.props let props if (subEntityId) { const castedRoute = ((activeEntity: any): RouteWithPatterns) const pattern = castedRoute.tripPatterns.find(p => p.id === subEntityId) - props = { bounds: getEntityBounds(pattern), target: subEntityId } + props = { bounds: getEntityBounds(pattern, activePatternStops), target: subEntityId } } else { props = { bounds: getEntityBounds(activeEntity), target: +activeEntity.id } } diff --git a/lib/editor/containers/ActiveEntityList.js b/lib/editor/containers/ActiveEntityList.js index c885ffc2f..0ba4887dc 100644 --- a/lib/editor/containers/ActiveEntityList.js +++ b/lib/editor/containers/ActiveEntityList.js @@ -12,7 +12,7 @@ import {cloneGtfsEntity, newGtfsEntity, updateEntitySort} from '../actions/edito import {getTableById} from '../util/gtfs' import EntityList from '../components/EntityList' import {findProjectByFeedSource} from '../../manager/util' -import {getActiveEntityList} from '../selectors' +import {getActiveEntityList, getActivePatternStops} from '../selectors' import type {AppState} from '../../types/reducers' @@ -36,10 +36,12 @@ const mapStateToProps = (state: AppState, ownProps: Props) => { const activeEntity = list.find(entity => entity.isActive) const entities = activeComponent && getTableById(tables, activeComponent) const project = findProjectByFeedSource(state.projects.all, feedSourceId) + const activePatternStops = getActivePatternStops(state) const feedSource = project && project.feedSources && project.feedSources.find(fs => fs.id === feedSourceId) return { activeEntity, + activePatternStops, entities, feedSource, hasRoutes, diff --git a/lib/editor/selectors/index.js b/lib/editor/selectors/index.js index c8f318ab3..751a1f3bc 100644 --- a/lib/editor/selectors/index.js +++ b/lib/editor/selectors/index.js @@ -125,6 +125,20 @@ const getPresentControlPoints = (state: AppState) => { return state.editor.editSettings.present.controlPoints } export const getTripCounts = (state: AppState) => state.editor.data.tables.trip_counts +export const getActivePatternStops = createSelector( + [ + getActivePattern, + getStops + ], + (pattern, stops) => { + if (!pattern || !stops || !pattern.patternStops) return null + const patternStops = pattern.patternStops.map(ps => { + const stop = stops.find(s => s.stop_id === ps.stopId) + return stop + }) + return patternStops + } +) export const getActivePatternTripCount = createSelector( [ getActivePattern, diff --git a/lib/editor/util/gtfs.js b/lib/editor/util/gtfs.js index 6ee20e315..19398d46a 100644 --- a/lib/editor/util/gtfs.js +++ b/lib/editor/util/gtfs.js @@ -165,7 +165,7 @@ export const generateProps = (component: string, editorState: any): any => { } } -export function getEntityBounds (entity: any, offset: number = 0.005): ?latLngBounds { +export function getEntityBounds (entity: any, stops?: Array, offset: number = 0.005): ?latLngBounds { if (!entity) return null if (entity.constructor === Array) { @@ -202,9 +202,9 @@ export function getEntityBounds (entity: any, offset: number = 0.005): ?latLngBo // trip pattern const pattern: Pattern = ((entity: any): Pattern) return latLngBounds(pattern.shape.coordinates.map(c => [c[1], c[0]])) - } else if (entity.patternStops) { - // TODO: add pattern stops bounds extraction - return null + } else if (entity.patternStops && stops) { + // Convert stops to bounds + return latLngBounds(stops.map(s => [s.stop_lat, s.stop_lon])) } }