Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
to,
toStopId
}) {
let geometry
try {
if (from && to) {
if (followRoad) {
const coordinates = await getRoutePolyline(lonlat(from), lonlat(to))
const c0 = coordinates[0]
const cy = coordinates[coordinates.length - 1]
const epsilon = 1e-6
if (!coordinatesAreEqual(c0, from, epsilon)) {
coordinates.unshift(from)
}
if (!coordinatesAreEqual(cy, to, epsilon)) {
coordinates.push(to)
}
geometry = {
type: 'LineString',
coordinates
}
} else {
geometry = await lineString([from, to]).geometry
}
} else {
// start of geometry, from or to is undefined
const coord = from || to
geometry = await point(coord).geometry
}
} catch (e) {
spacing = DEFAULT_STOP_SPACING_METERS,
stopAtEnd,
stopAtStart,
to,
toStopId
}) {
let geometry
try {
if (from && to) {
if (followRoad) {
const coordinates = await getRoutePolyline(lonlat(from), lonlat(to))
const c0 = coordinates[0]
const cy = coordinates[coordinates.length - 1]
const epsilon = 1e-6
if (!coordinatesAreEqual(c0, from, epsilon)) {
coordinates.unshift(from)
}
if (!coordinatesAreEqual(cy, to, epsilon)) {
coordinates.push(to)
}
geometry = {
type: 'LineString',
coordinates
}
} else {
geometry = await lineString([from, to]).geometry
}
} else {
// start of geometry, from or to is undefined
const coord = from || to
let geometry
if (followRoad) {
// if followRoad
const coordinates = await polyline(
points.map(p => ({lng: p[0], lat: p[1]}))
) // [{lng: from[0], lat: from[1]}, {lng: to[0], lat: to[1]}])
if (!coordinates) {
if (defaultToStraightLine) {
geometry = lineString(points).geometry
} else {
return null
}
} else {
const c0 = coordinates[0]
const epsilon = 1e-6
if (!coordinatesAreEqual(c0, points[0], epsilon)) {
coordinates.unshift(points[0])
}
geometry = {
type: 'LineString',
coordinates
}
}
} else {
geometry = lineString(points).geometry
}
return geometry
}
export default async function getLineString (from: LonLatC, to: LonLatC, {followRoad}: {
followRoad: boolean
}) {
try {
if (followRoad) {
const coordinates = await getRoutePolyline(from, to)
const c0 = coordinates[0]
const cy = coordinates[coordinates.length - 1]
if (!coordinatesAreEqual(c0, from, MINIMUM_COORDINATE_DISTANCE)) {
coordinates.unshift(lonlat.toCoordinates(from))
}
if (!coordinatesAreEqual(cy, to, MINIMUM_COORDINATE_DISTANCE)) {
coordinates.push(lonlat.toCoordinates(to))
}
return {
type: 'LineString',
coordinates
}
} else {
return await lineString([
lonlat.toCoordinates(from),
lonlat.toCoordinates(to)
]).geometry
}
} catch (e) {
console.error(e.stack)
throw e
componentWillReceiveProps (nextProps: Props) {
if (!lonlat.isEqual(nextProps.center, this.props.center)) {
this.setState({
center: nextProps.center
})
}
if (nextProps.regionId &&
this.props.regionId !== nextProps.regionId &&
nextProps.regionId !== CREATING_ID) {
this.props.loadRegion(nextProps.regionId)
}
}
componentWillReceiveProps (nextProps: Props) {
if (!lonlat.isEqual(nextProps.center, this.props.center)) {
this.setState({
center: nextProps.center
})
}
}
export default async function getLineString (from: LonLatC, to: LonLatC, {followRoad}: {
followRoad: boolean
}) {
try {
if (followRoad) {
const coordinates = await getRoutePolyline(from, to)
const c0 = coordinates[0]
const cy = coordinates[coordinates.length - 1]
if (!coordinatesAreEqual(c0, from, MINIMUM_COORDINATE_DISTANCE)) {
coordinates.unshift(lonlat.toCoordinates(from))
}
if (!coordinatesAreEqual(cy, to, MINIMUM_COORDINATE_DISTANCE)) {
coordinates.push(lonlat.toCoordinates(to))
}
return {
type: 'LineString',
coordinates
}
} else {
return await lineString([
lonlat.toCoordinates(from),
lonlat.toCoordinates(to)
]).geometry
}