How to use the @conveyal/lonlat.isEqual function in @conveyal/lonlat

To help you get started, we’ve selected a few @conveyal/lonlat examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github conveyal / analysis-ui / lib / utils / get-segment.js View on Github external
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) {
github conveyal / analysis-ui / lib / utils / get-segment.js View on Github external
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
github ibi-group / datatools-ui / lib / scenario-editor / utils / valhalla.js View on Github external
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
}
github conveyal / analysis-ui / lib / utils / get-line-string.js View on Github external
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
github conveyal / analysis-ui / lib / components / application.js View on Github external
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)
    }
  }
github conveyal / analysis-ui / lib / components / application.js View on Github external
componentWillReceiveProps (nextProps: Props) {
    if (!lonlat.isEqual(nextProps.center, this.props.center)) {
      this.setState({
        center: nextProps.center
      })
    }
  }
github conveyal / analysis-ui / lib / utils / get-line-string.js View on Github external
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
    }