How to use the @turf/line-slice function in @turf/line-slice

To help you get started, we’ve selected a few @turf/line-slice 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 / components / report / reroute.js View on Github external
let nStopsRemoved = toStopIndex - fromStopIndex
  if (modification.fromStop && modification.toStop) nStopsRemoved-- // -1 because it's an exclusive interval on both sides, don't include from and to stops

  let nStopsAdded = stops.length

  // the endpoints are included, subtract them off where they overlap with existing stops
  if (modification.fromStop) nStopsAdded--
  if (modification.toStop) nStopsAdded--

  // NB using indices here so we get an object even if fromStop or toStop is null
  // stops in pattern are in fact objects but they only have stop ID.
  const fromStop = feed.stopsById[pattern.stops[fromStopIndex].stop_id]
  const toStop = feed.stopsById[pattern.stops[toStopIndex].stop_id]

  const geometry = lineSlice(
    point([fromStop.stop_lon, fromStop.stop_lat]),
    point([toStop.stop_lon, toStop.stop_lat]),
    {
      type: 'Feature',
      geometry: pattern.geometry,
      properties: {}
    }
  )

  const removedLengthThisPattern = turfLength(geometry)

  return (
    <table></table>
github developmentseed / skynet-scrub / app / scripts / components / map / index.js View on Github external
splitLine: function (e) {
    const { draw } = this;
    const ids = draw.getFeatureIdsAt(e.point);
    if (!ids.length) { return; }
    const line = draw.get(ids[0]);
    const cursorAt = point([e.lngLat.lng, e.lngLat.lat]);

    // delete the existing line, and add two additional lines.
    draw.delete(line.id);
    const newIds = [];
    newIds.push(draw.add(lineSlice(point(firstCoord(line)), cursorAt, line)));
    newIds.push(draw.add(lineSlice(cursorAt, point(lastCoord(line)), line)));

    this.splitMode({ featureIds: newIds });
    const newLines = newIds.map(id => draw.get(id));

    // Mark the new lines as edited
    newLines.forEach(this.markAsEdited);
    const actions = newLines.map(createRedo).concat(createUndo(line));
    this.props.dispatch(updateSelection(actions));
  },
github conveyal / analysis-ui / lib / components / modifications-map / hop-layer.js View on Github external
const makeGeometryIfNecessary = () => {
          // TODO: SIDE EFFECTS!!
          if (startHopIndex >= 0) {
            // get geometry
            const fromStopId = pattern.stops[startHopIndex].stop_id
            const fromStop = feed.stopsById[fromStopId]
            // get feature at end of hop
            const toStopId = pattern.stops[prevHopIndex + 1].stop_id
            const toStop = feed.stopsById[toStopId]
            const geometry = lineSlice(
              point([fromStop.stop_lon, fromStop.stop_lat]),
              point([toStop.stop_lon, toStop.stop_lat]),
              {
                type: 'Feature',
                properties: {},
                geometry: pattern.geometry
              }
            )

            selectedHopGeometries.push(geometry)
          }
        }
github conveyal / analysis-ui / lib / components / modifications-map / reroute-layer.js View on Github external
// make sure to find a toStopIndex _after_ the fromStopIndex (helps with loop routes also)
      const toStopIndex = modification.toStop != null
        ? pattern.stops.findIndex(
          (s, i) => i > fromStopIndex && s.stop_id === modification.toStop
        )
        : pattern.stops.length - 1

      const modificationAppliesToThisPattern =
        fromStopIndex !== -1 && toStopIndex !== -1
      if (modificationAppliesToThisPattern) {
        // NB using indices here so we get an object even if fromStop or toStop
        // is null stops in pattern are in fact objects but they only have stop ID.
        const fromStop = feed.stopsById[pattern.stops[fromStopIndex].stop_id]
        const toStop = feed.stopsById[pattern.stops[toStopIndex].stop_id]

        return lineSlice(
          point([fromStop.stop_lon, fromStop.stop_lat]),
          point([toStop.stop_lon, toStop.stop_lat]),
          {
            type: 'Feature',
            geometry: pattern.geometry,
            properties: {}
          }
        )
      }
    })
    .filter(segment => !!segment)
github developmentseed / skynet-scrub / app / scripts / components / map / index.js View on Github external
splitLine: function (e) {
    const { draw } = this;
    const ids = draw.getFeatureIdsAt(e.point);
    if (!ids.length) { return; }
    const line = draw.get(ids[0]);
    const cursorAt = point([e.lngLat.lng, e.lngLat.lat]);

    // delete the existing line, and add two additional lines.
    draw.delete(line.id);
    const newIds = [];
    newIds.push(draw.add(lineSlice(point(firstCoord(line)), cursorAt, line)));
    newIds.push(draw.add(lineSlice(cursorAt, point(lastCoord(line)), line)));

    this.splitMode({ featureIds: newIds });
    const newLines = newIds.map(id => draw.get(id));

    // Mark the new lines as edited
    newLines.forEach(this.markAsEdited);
    const actions = newLines.map(createRedo).concat(createUndo(line));
    this.props.dispatch(updateSelection(actions));
  },
github FreemapSlovakia / freemap-v3-react / src / components / TrackViewerResult.tsx View on Github external
computeInfoDistanceKm = (
    infoLat: number,
    infoLon: number,
    geojsonLineString,
  ) => {
    const p1 = point(geojsonLineString.geometry.coordinates[0]);
    const p2 = point([infoLon, infoLat]);
    return turfLength(turfLineSlice(p1, p2, geojsonLineString));
  };

@turf/line-slice

turf line-slice module

MIT
Latest version published 5 months ago

Package Health Score

94 / 100
Full package analysis

Popular @turf/line-slice functions