Skip to content

Commit 9b4340f

Browse files
committed
fix(editor): zoom to pattern extents if no shape exists
fixes #399
1 parent 3bad9b7 commit 9b4340f

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

lib/editor/components/EntityDetailsHeader.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {getEntityBounds, getEntityName} from '../util/gtfs'
1010
import {entityIsNew} from '../util/objects'
1111
import {GTFS_ICONS} from '../util/ui'
1212

13-
import type {Entity, Feed, GtfsRoute, Pattern} from '../../types'
13+
import type {Entity, Feed, GtfsRoute, GtfsStop, Pattern} from '../../types'
1414
import type {MapState} from '../../types/reducers'
1515
import type {EditorValidationIssue} from '../util/validation'
1616

@@ -20,6 +20,7 @@ type Props = {
2020
activeComponent: string,
2121
activeEntity: Entity,
2222
activePattern: Pattern,
23+
activePatternStops: Array<GtfsStop>,
2324
editFareRules: boolean,
2425
entityEdited: boolean,
2526
feedSource: Feed,
@@ -62,12 +63,12 @@ export default class EntityDetailsHeader extends Component<Props> {
6263
}
6364

6465
_onClickZoomTo = () => {
65-
const { activeEntity, subEntityId, updateMapSetting } = this.props
66+
const { activeEntity, activePatternStops, subEntityId, updateMapSetting } = this.props
6667
let props
6768
if (subEntityId) {
6869
const castedRoute = ((activeEntity: any): RouteWithPatterns)
6970
const pattern = castedRoute.tripPatterns.find(p => p.id === subEntityId)
70-
props = { bounds: getEntityBounds(pattern), target: subEntityId }
71+
props = { bounds: getEntityBounds(pattern, activePatternStops), target: subEntityId }
7172
} else {
7273
props = { bounds: getEntityBounds(activeEntity), target: +activeEntity.id }
7374
}

lib/editor/containers/ActiveEntityList.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {cloneGtfsEntity, newGtfsEntity, updateEntitySort} from '../actions/edito
1212
import {getTableById} from '../util/gtfs'
1313
import EntityList from '../components/EntityList'
1414
import {findProjectByFeedSource} from '../../manager/util'
15-
import {getActiveEntityList} from '../selectors'
15+
import {getActiveEntityList, getActivePatternStops} from '../selectors'
1616

1717
import type {AppState} from '../../types/reducers'
1818

@@ -36,10 +36,12 @@ const mapStateToProps = (state: AppState, ownProps: Props) => {
3636
const activeEntity = list.find(entity => entity.isActive)
3737
const entities = activeComponent && getTableById(tables, activeComponent)
3838
const project = findProjectByFeedSource(state.projects.all, feedSourceId)
39+
const activePatternStops = getActivePatternStops(state)
3940
const feedSource = project && project.feedSources && project.feedSources.find(fs => fs.id === feedSourceId)
4041

4142
return {
4243
activeEntity,
44+
activePatternStops,
4345
entities,
4446
feedSource,
4547
hasRoutes,

lib/editor/selectors/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,20 @@ const getPresentControlPoints = (state: AppState) => {
125125
return state.editor.editSettings.present.controlPoints
126126
}
127127
export const getTripCounts = (state: AppState) => state.editor.data.tables.trip_counts
128+
export const getActivePatternStops = createSelector(
129+
[
130+
getActivePattern,
131+
getStops
132+
],
133+
(pattern, stops) => {
134+
if (!pattern || !stops || !pattern.patternStops) return null
135+
const patternStops = pattern.patternStops.map(ps => {
136+
const stop = stops.find(s => s.stop_id === ps.stopId)
137+
return stop
138+
})
139+
return patternStops
140+
}
141+
)
128142
export const getActivePatternTripCount = createSelector(
129143
[
130144
getActivePattern,

lib/editor/util/gtfs.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export const generateProps = (component: string, editorState: any): any => {
165165
}
166166
}
167167

168-
export function getEntityBounds (entity: any, offset: number = 0.005): ?latLngBounds {
168+
export function getEntityBounds (entity: any, stops?: Array<GtfsStop>, offset: number = 0.005): ?latLngBounds {
169169
if (!entity) return null
170170

171171
if (entity.constructor === Array) {
@@ -202,9 +202,9 @@ export function getEntityBounds (entity: any, offset: number = 0.005): ?latLngBo
202202
// trip pattern
203203
const pattern: Pattern = ((entity: any): Pattern)
204204
return latLngBounds(pattern.shape.coordinates.map(c => [c[1], c[0]]))
205-
} else if (entity.patternStops) {
206-
// TODO: add pattern stops bounds extraction
207-
return null
205+
} else if (entity.patternStops && stops) {
206+
// Convert stops to bounds
207+
return latLngBounds(stops.map(s => [s.stop_lat, s.stop_lon]))
208208
}
209209
}
210210

0 commit comments

Comments
 (0)