Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'pbf' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
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
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;
blobToBuffer(blob, function(err, buf) {
if (err) throw err
var tile = new VectorTile(new Protobuf(buf));
console.log(tile.layers);
cb(tile);
})
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);
}
}
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)
})
}
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));
}
}
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;
}
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 () => {
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;
}
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;