Skip to content

Commit 453c069

Browse files
committed
fix(editor): default new stop location to center of bounds (rather than 0,0)
1 parent a542bfe commit 453c069

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

lib/editor/components/map/EditorMap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export default class EditorMap extends Component {
8383
const stopLatLng = clickToLatLng(e.latlng)
8484
if (activeEntity && entityIsNew(activeEntity)) {
8585
updateActiveEntity(activeEntity, activeComponent, stopLatLng)
86-
this.refs[activeEntity.id].leafletElement.setLatLng(e.latlng)
86+
this.refs[activeEntity.id] && this.refs[activeEntity.id].leafletElement.setLatLng(e.latlng)
8787
} else if (entities && entities.findIndex(entityIsNew) === -1) {
8888
// if a new stop should be constructed
8989
const stop = await constructStop(e.latlng, feedSource.id)

lib/editor/util/gtfs.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,14 @@ export const generateProps = (component: string, editorState: any): any => {
147147
: 3
148148
}
149149
case 'stop':
150+
const {bounds} = editorState.mapState
150151
const stopId = generateUID()
152+
const center = bounds && bounds.getCenter()
151153
return {
152154
stop_id: stopId,
153155
stop_name: null,
154-
stop_lat: 0,
155-
stop_lon: 0
156+
stop_lat: center ? center.lat : 0,
157+
stop_lon: center ? center.lng : 0
156158
}
157159
case 'scheduleexception':
158160
return {
@@ -258,7 +260,9 @@ export function findEntityByGtfsId (
258260
}
259261

260262
export function getEntityName (entity: ?Entity): string {
263+
const NO_NAME = '[no name]'
261264
if (!entity) {
265+
// FIXME: When will this occur...
262266
return '[Unnamed]'
263267
}
264268

@@ -289,7 +293,7 @@ export function getEntityName (entity: ?Entity): string {
289293
? `${stop.stop_name} (${stop.stop_code})`
290294
: stop.stop_name && stop.stop_id
291295
? `${stop.stop_name} (${stop.stop_id})`
292-
: stop.stop_name || '[no name]'
296+
: stop.stop_name || NO_NAME
293297
case 'route_short_name':
294298
const route: GtfsRoute = ((entity: any): GtfsRoute)
295299
if (route.route_short_name &&
@@ -302,7 +306,7 @@ export function getEntityName (entity: ?Entity): string {
302306
} else if (route.route_long_name && route.route_long_name !== '""') {
303307
return route.route_long_name
304308
} else {
305-
return '[no name]'
309+
return NO_NAME
306310
}
307311
case 'description': // service calendar
308312
const serviceCalendar: ServiceCalendar = ((entity: any): ServiceCalendar)
@@ -311,13 +315,13 @@ export function getEntityName (entity: ?Entity): string {
311315
: ''}`
312316
default:
313317
const otherEntityType: any = entity
314-
return otherEntityType[nameKey] || '[no name]'
318+
return otherEntityType[nameKey] || NO_NAME
315319
}
316320
}
317321

318322
export function getAbbreviatedStopName (stop: GtfsStop, maxCharactersPerWord: number = 10): string {
319323
const stopName = getEntityName(stop)
320-
const stopNameParts = stopName ? stopName.split(/(\band\b|&|@|:|\+)+/i) : null
324+
const stopNameParts = stopName ? stopName.split(/(\band\b|&|@|:|\/|\+)+/i) : null
321325
return stopNameParts &&
322326
stopNameParts.length === 3 &&
323327
stop.stop_name.length > maxCharactersPerWord * 2

0 commit comments

Comments
 (0)