How to use polyline - 10 common examples

To help you get started, we’ve selected a few polyline 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 Project-OSRM / osrm-backend / features / step_definitions / trip.js View on Github external
got.code = json.code;
                    }

                    if (headers.has('status')) {
                        got.status = json.code;
                    }

                    if (headers.has('message')) {
                        got.message = json.message;
                    }

                    if (headers.has('geometry')) {
                        if (this.queryParams['geometries'] === 'polyline') {
                            got.geometry = polyline.decode(json.trips[0].geometry).toString();
                        } else if (this.queryParams['geometries'] === 'polyline6') {
                            got.geometry = polyline.decode(json.trips[0].geometry, 6).toString();
                        } else {
                            got.geometry = json.trips[0].geometry.coordinates;
                        }
                    }

                    if (headers.has('#')) {
                        // comment column
                        got['#'] = row['#'];
                    }

                    var subTrips;
                    var trip_durations;
                    var trip_distance;
                    if (res.statusCode === 200) {
                        if (headers.has('trips')) {
                            subTrips = json.trips.filter(t => !!t).map(t => t.legs).map(tl => Array.prototype.concat.apply([], tl.map((sl, i) => {
github Project-OSRM / osrm-backend / features / step_definitions / matching.js View on Github external
// and return in that header
                    headers.forEach((k) => {
                        let whitelist = ['duration', 'distance', 'datasources', 'nodes', 'weight'];
                        if (k.match(/^a:/)) {
                            let a_type = k.slice(2);
                            if (whitelist.indexOf(a_type) == -1)
                                return cb(new Error('Unrecognized annotation field:' + a_type));
                            if (!annotation[a_type])
                                return cb(new Error('Annotation not found in response: ' + a_type));
                            got[k] = annotation[a_type];
                        }
                    });

                    if (headers.has('geometry')) {
                        if (this.queryParams['geometries'] === 'polyline') {
                            got.geometry = polyline.decode(geometry).toString();
                        } else if (this.queryParams['geometries'] === 'polyline6') {
                            got.geometry = polyline.decode(geometry,6).toString();
                        } else {
                            got.geometry = geometry.coordinates;
                        }
                    }

                    if (headers.has('OSM IDs')) {
                        got['OSM IDs'] = OSMIDs;
                    }

                    if (headers.has('alternatives')) {
                        got['alternatives'] = alternatives;
                    }
                    var ok = true;
                    var encodedResult = '',
github Project-OSRM / osrm-backend / features / step_definitions / trip.js View on Github external
if (res.body.length) {
                        json = JSON.parse(res.body);
                        got.code = json.code;
                    }

                    if (headers.has('status')) {
                        got.status = json.code;
                    }

                    if (headers.has('message')) {
                        got.message = json.message;
                    }

                    if (headers.has('geometry')) {
                        if (this.queryParams['geometries'] === 'polyline') {
                            got.geometry = polyline.decode(json.trips[0].geometry).toString();
                        } else if (this.queryParams['geometries'] === 'polyline6') {
                            got.geometry = polyline.decode(json.trips[0].geometry, 6).toString();
                        } else {
                            got.geometry = json.trips[0].geometry.coordinates;
                        }
                    }

                    if (headers.has('#')) {
                        // comment column
                        got['#'] = row['#'];
                    }

                    var subTrips;
                    var trip_durations;
                    var trip_distance;
                    if (res.statusCode === 200) {
github mapbox / leaflet-omnivore / leaflet-omnivore.js View on Github external
function polylineParse(txt, options, layer) {
    layer = layer || L.geoJson();
    options = options || {};
    var coords = polyline.decode(txt, options.precision);
    var geojson = { type: 'LineString', coordinates: [] };
    for (var i = 0; i < coords.length; i++) {
        // polyline returns coords in lat, lng order, so flip for geojson
        geojson.coordinates[i] = [coords[i][1], coords[i][0]];
    }
    addData(layer, geojson);
    return layer;
}
github socib / Leaflet.TimeDimension / examples / js / vendors / leaflet-plugins / leaflet-omnivore.js View on Github external
function polylineParse(txt, options, layer) {
    layer = layer || L.geoJson();
    options = options || {};
    var coords = polyline.decode(txt, options.precision);
    var geojson = { type: 'LineString', coordinates: [] };
    for (var i = 0; i < coords.length; i++) {
        // polyline returns coords in lat, lng order, so flip for geojson
        geojson.coordinates[i] = [coords[i][1], coords[i][0]];
    }
    addData(layer, geojson);
    return layer;
}
github rstudio / leaflet / inst / htmlwidgets / lib / leaflet-omnivore / leaflet-omnivore.js View on Github external
function polylineParse(txt, options, layer) {
    layer = layer || L.geoJson();
    options = options || {};
    var coords = polyline.decode(txt, options.precision);
    var geojson = { type: 'LineString', coordinates: [] };
    for (var i = 0; i < coords.length; i++) {
        // polyline returns coords in lat, lng order, so flip for geojson
        geojson.coordinates[i] = [coords[i][1], coords[i][0]];
    }
    addData(layer, geojson);
    return layer;
}
github mapbox / leaflet-omnivore / index.js View on Github external
function polylineParse(txt, options, layer) {
    layer = layer || L.geoJson();
    options = options || {};
    var coords = polyline.decode(txt, options.precision);
    var geojson = { type: 'LineString', coordinates: [] };
    for (var i = 0; i < coords.length; i++) {
        // polyline returns coords in lat, lng order, so flip for geojson
        geojson.coordinates[i] = [coords[i][1], coords[i][0]];
    }
    addData(layer, geojson);
    return layer;
}
github ibi-group / datatools-ui / lib / scenario-editor / utils / valhalla.js View on Github external
const legArray = json.trip.legs.map((leg, index) => {
      return decodePolyline(leg.shape)
        .map((c, index) => [c[1] / 10, c[0] / 10]) // Mapzen or Mapbox is encoding/decoding wrong?
    })
    return [].concat.apply([], legArray)
github mapbox / mapbox-gl-directions / src / containers / app.js View on Github external
componentWillReceiveProps(props) {
    const { map, data } = props;
    const geojson = {
      type: 'FeatureCollection',
      features: [data.origin, data.destination].filter((d) => {
        return d.geometry;
      })
    };

    if (data.directions.length) {
      geojson.features.push({
        geometry: {
          type: 'LineString',
          coordinates: decode(data.directions[0].geometry, 6).map((c) => {
            return c.reverse();
          })
        }
      });
    }

    // TODO fitBounds to geojson?
    if (geojson.features.length) {
      map.getSource('directions').setData(geojson);

      if (!data.origin.geometry) {
        map.flyTo({ center: data.destination.geometry.coordinates });
      } else if (!data.destination.geometry) {
        map.flyTo({ center: data.origin.geometry.coordinates });
      }
    }
github chriswhong / nyctaxi / data_prep / getDirections.js View on Github external
function getPolyline(leg){ //gets steps for leg, combines into one polyline
    //console.log(leg);
    var legPoints = [];
    for(s in leg.steps){
        var points = leg.steps[s].polyline.points;
        points = polyline.decode(points);
        for(p in points){
            legPoints.push(points[p]);
        }
    }

    legPolyline = polyline.encode(legPoints);
    return legPolyline;


}

polyline

Polyline encoding and decoding

BSD-3-Clause
Latest version published 9 years ago

Package Health Score

53 / 100
Full package analysis

Popular polyline functions