From 09b1e64c0f6cbc34c0f0bec7a8c573a17db2abd7 Mon Sep 17 00:00:00 2001 From: Evan Siroky Date: Wed, 18 Sep 2019 12:28:36 -0700 Subject: [PATCH] fix(map): fix bug that occurred when rendering geometry with 0 length Fixes https://github.com/ibi-group/trimet-mod-otp/issues/250 --- lib/components/map/base-map.js | 1 + lib/util/itinerary.js | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/components/map/base-map.js b/lib/components/map/base-map.js index bb40defad..b0ace488f 100644 --- a/lib/components/map/base-map.js +++ b/lib/components/map/base-map.js @@ -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} diff --git a/lib/util/itinerary.js b/lib/util/itinerary.js index c89e1bcac..8caa6d853 100644 --- a/lib/util/itinerary.js +++ b/lib/util/itinerary.js @@ -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) {