Skip to content

Commit

Permalink
fix(map): fix bug that occurred when rendering geometry with 0 length
Browse files Browse the repository at this point in the history
  • Loading branch information
evansiroky committed Sep 18, 2019
1 parent e37a7df commit 09b1e64
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/components/map/base-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ class BaseMap extends Component {
center={center}
// onClick={this._onLeftClick}
zoom={config.map.initZoom || 13}
maxZoom={config.map.maxZoom}
onOverlayAdd={this._onOverlayAdd}
onOverlayRemove={this._onOverlayRemove}
onViewportChanged={this._onViewportChanged}
Expand Down
17 changes: 15 additions & 2 deletions lib/util/itinerary.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,24 @@ export function getItineraryBounds (itinerary) {
return latLngBounds(coords)
}

/**
* Return a leaflet LatLngBounds object that encloses the given leg's geometry.
*/
export function getLegBounds (leg) {
return latLngBounds(polyline
let coords = polyline
.toGeoJSON(leg.legGeometry.points)
.coordinates.map(c => [c[1], c[0]])
)

// in certain cases, there might be zero-length coordinates in the leg
// geometry. In these cases, build us an array of coordinates using the from
// and to data of the leg.
if (coords.length === 0) {
coords = [
[leg.from.lat, leg.from.lon],
[leg.to.lat, leg.to.lon]
]
}
return latLngBounds(coords)
}

export function routeComparator (a, b) {
Expand Down

0 comments on commit 09b1e64

Please sign in to comment.