How to use pbf - 10 common examples

To help you get started, we’ve selected a few pbf 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 w3reality / three-laser-pointer / examples / demo-path / src / index.js View on Github external
return;
                    };
                    console.log('buffer:', buffer); // ArrayBuffer(39353) {}

                    if (0) { // dump buffer
                        // https://discourse.threejs.org/t/how-to-create-a-new-file-and-save-it-with-arraybuffer-content/628/2
                        let file = new Blob([buffer], {type: "application/octet-stream"});
                        let a = document.createElement("a");
                        a.href = URL.createObjectURL(file);
                        a.download = "blob.dat";
                        document.body.appendChild(a);
                        a.click();
                    }
                    // return; //!!!!!!!!!!!!!!!

                    let tile = new VectorTile(new Pbf(buffer));
                    processTile(tile, zoompos, geojson, bottomTiles);

                    if (queryCount === tilesCovered.length) {
                        console.log('finished downloading at '+Date.now());

                        let eleList = getEleList(geojson);
                        console.log('eleList:', eleList);
                        addBottomEle(geojson, bottomTiles, eleList);
                        console.log('geojson:', geojson);

                        let contours = getContours(eleList, geojson, polygon, maxArea);
                        console.log('contours:', contours);
                        console.log('got contours at '+Date.now());
                        cb(contours);
                    }
                }); // end of xhr
github iTowns / itowns / src / Parser / VectorTileParser.js View on Github external
function readPBF(file, options) {
    const vectorTile = new VectorTile(new Protobuf(file));
    const extentSource = options.extentSource || file.extent;
    const sourceLayers = Object.keys(vectorTile.layers);

    if (sourceLayers.length < 1) {
        return;
    }

    // x,y,z tile coordinates
    const x = extentSource.col;
    const z = extentSource.zoom;
    // We need to move from TMS to Google/Bing/OSM coordinates
    // https://alastaira.wordpress.com/2011/07/06/converting-tms-tile-coordinates-to-googlebingosm-tile-coordinates/
    // Only if the layer.origin is top
    const y = options.isInverted ? extentSource.row : (1 << z) - extentSource.row - 1;

    options.buildExtent = true;
github countable-web / threejs-go / src / vectors.js View on Github external
blobToBuffer(blob, function(err, buf) {
        if (err) throw err

        var tile = new VectorTile(new Protobuf(buf));
        console.log(tile.layers);
        cb(tile);
    })
github ubilabs / axidraw / src / lib / load-lines-mapbox.js View on Github external
const projection = getProjection(viewport);
  const visibleTiles = tile()
    .size([width, height])
    .scale(projection.scale() * 2 * Math.PI)
    .translate(projection([0, 0]))();

  const getUrl = ({x, y, z}) =>
    `${TILE_BASE_URL}/${z}/${x}/${y}.vector.pbf?access_token=${MAPBOX_TOKEN}`;

  const geojsons = [];

  for (const visibleTile of visibleTiles) {
    const buffer = await fetch(getUrl(visibleTile)).then(res =>
      res.arrayBuffer()
    );
    const vectorLayers = new VectorTile(new Protobuf(buffer));

    for (const layer of Object.values(vectorLayers.layers)) {
      if (!INCLUDED.includes(layer.name)) {
        continue;
      }

      for (let i = 0; i < layer.length; i++) {
        const feature = layer.feature(i);
        const geojson = feature.toGeoJSON(
          visibleTile.x,
          visibleTile.y,
          visibleTile.z
        );
        geojsons.push(geojson);
      }
    }
github hotosm / osm-analytics / app / components / Stats / searchFeatures.js View on Github external
getArrayBuffer(url, function done(err, data) {
    if (err) return callback(err)
    if (data === null) return callback(null, featurecollection([]))
    data = new vt.VectorTile(new Protobuf(new Uint8Array(data)))
    parseTile(tile, data, callback)
  })
}
github openlayers / openlayers / src / ol / format / MVT.js View on Github external
readFeatures(source, opt_options) {
    const layers = this.layers_;
    const options = /** @type {import("./Feature.js").ReadOptions} */ (this.adaptOptions(opt_options));
    const dataProjection = get(options.dataProjection);
    dataProjection.setWorldExtent(options.extent);
    options.dataProjection = dataProjection;

    const pbf = new PBF(/** @type {ArrayBuffer} */ (source));
    const pbfLayers = pbf.readFields(layersPBFReader, {});
    const features = [];
    for (const name in pbfLayers) {
      if (layers && layers.indexOf(name) == -1) {
        continue;
      }
      const pbfLayer = pbfLayers[name];

      const extent = pbfLayer ? [0, 0, pbfLayer.extent, pbfLayer.extent] : null;
      dataProjection.setExtent(extent);

      for (let i = 0, ii = pbfLayer.length; i < ii; ++i) {
        const rawFeature = readRawFeature(pbf, pbfLayer, i);
        features.push(this.createFeature_(pbf, rawFeature, options));
      }
    }
github wladich / nakarte / src / lib / leaflet.control.panoramas / lib / mapillary / mvt.js View on Github external
function decodeMvt(ar, tileExtent=256) {
    const
        pbf = new Pbf(new Uint8Array(ar)),
        tileData = TileProto.read(pbf);
    const parsedLayers = [];
    for (let layer of tileData.layers) {
        let scale = tileExtent / layer.extent;
        parsedLayers.push({
            name: layer.name,
            features: parseFeatures(layer, scale)
        });
    }
    return parsedLayers;
}
github antvis / L7 / src / source / vector_tile_worker_source.js View on Github external
const request = getArrayBuffer({ url: params.url }, (err, data) => {
    if (err) {
      callback(err);
    } else if (data) {
      callback(null, {
        vectorTile: new VectorParser.VectorTile(new PBF(data.data)),
        rawData: data.data
      });
    }
  });
  return () => {
github ThinkGeo / VectorMap-js / src / format / MVT.js View on Github external
readFeatures(source, opt_options) {
    const layers = this.layers_;

    const pbf = new PBF(/** @type {ArrayBuffer} */ (source));
    const pbfLayers = pbf.readFields(layersPBFReader, {});
    /** @type {Array} */
    const features = [];
    for (const name in pbfLayers) {
      if (layers && layers.indexOf(name) == -1) {
        continue;
      }
      const pbfLayer = pbfLayers[name];

      for (let i = 0, ii = pbfLayer.length; i < ii; ++i) {
        const rawFeature = readRawFeature(pbf, pbfLayer, i);
        features.push(this.createFeature_(pbf, rawFeature));
      }
      this.extent_ = pbfLayer ? [0, 0, pbfLayer.extent, pbfLayer.extent] : null;
    }
github wladich / nakarte / src / lib / leaflet.layer.tracks-collection / index.js View on Github external
unpackTileData(dataArray) {
        const
            pbf = new Pbf(new Uint8Array(dataArray)),
            tileData = TileProto.read(pbf);

        const tracksById = {};
        for (let track of tileData.tracks) {
            const
                ar = track.coordinates,
                ar_len = ar.length,
                ar2 = new Float64Array(ar_len);
            for (let i = 0; i < ar_len; i++) {
                ar2[i] = ar[i] / 255 * 256;
            }
            track.coordinates = ar2;
            tracksById[track.trackId] = track;
        }
        tileData.tracksById = tracksById;
        return tileData;

pbf

a low-level, lightweight protocol buffers implementation in JavaScript

BSD-3-Clause
Latest version published 5 months ago

Package Health Score

84 / 100
Full package analysis

Popular pbf functions