Skip to content

Commit

Permalink
fix(editor): zoom to pattern extents if no shape exists
Browse files Browse the repository at this point in the history
fixes #399
  • Loading branch information
landonreed committed Jan 24, 2019
1 parent 3bad9b7 commit 9b4340f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
7 changes: 4 additions & 3 deletions lib/editor/components/EntityDetailsHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -20,6 +20,7 @@ type Props = {
activeComponent: string,
activeEntity: Entity,
activePattern: Pattern,
activePatternStops: Array<GtfsStop>,
editFareRules: boolean,
entityEdited: boolean,
feedSource: Feed,
Expand Down Expand Up @@ -62,12 +63,12 @@ export default class EntityDetailsHeader extends Component<Props> {
}

_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 }
}
Expand Down
4 changes: 3 additions & 1 deletion lib/editor/containers/ActiveEntityList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions lib/editor/selectors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions lib/editor/util/gtfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<GtfsStop>, offset: number = 0.005): ?latLngBounds {
if (!entity) return null

if (entity.constructor === Array) {
Expand Down Expand Up @@ -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]))
}
}

Expand Down

0 comments on commit 9b4340f

Please sign in to comment.