Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mapbox/vector-tile

Package Overview
Dependencies
Maintainers
28
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mapbox/vector-tile

Parses vector tiles

  • 2.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.2M
increased by3.43%
Maintainers
28
Weekly downloads
 
Created

What is @mapbox/vector-tile?

@mapbox/vector-tile is a library for working with vector tiles, which are a way to deliver geographic data in small chunks. This package allows you to parse and work with vector tiles, which are commonly used in mapping applications to render map data efficiently.

What are @mapbox/vector-tile's main functionalities?

Parsing Vector Tiles

This code demonstrates how to parse a vector tile file and convert its features to GeoJSON format. It reads a vector tile from the file system, parses it using the VectorTile class, and iterates over its layers and features.

const fs = require('fs');
const { VectorTile } = require('@mapbox/vector-tile');
const Protobuf = require('pbf');

const data = fs.readFileSync('path/to/vector-tile.mvt');
const tile = new VectorTile(new Protobuf(data));

for (const layerName in tile.layers) {
  const layer = tile.layers[layerName];
  console.log(`Layer: ${layerName}`);
  for (let i = 0; i < layer.length; i++) {
    const feature = layer.feature(i);
    console.log(feature.toGeoJSON(0, 0, 0));
  }
}

Accessing Feature Properties

This code shows how to access the properties of a specific feature within a vector tile. It reads the vector tile, parses it, and then retrieves the properties of the first feature in a specified layer.

const fs = require('fs');
const { VectorTile } = require('@mapbox/vector-tile');
const Protobuf = require('pbf');

const data = fs.readFileSync('path/to/vector-tile.mvt');
const tile = new VectorTile(new Protobuf(data));

const layer = tile.layers['layer-name'];
const feature = layer.feature(0);
console.log(feature.properties);

Converting Features to GeoJSON

This code demonstrates how to convert a feature from a vector tile to GeoJSON format. It reads and parses the vector tile, retrieves a feature from a specified layer, and converts it to GeoJSON.

const fs = require('fs');
const { VectorTile } = require('@mapbox/vector-tile');
const Protobuf = require('pbf');

const data = fs.readFileSync('path/to/vector-tile.mvt');
const tile = new VectorTile(new Protobuf(data));

const layer = tile.layers['layer-name'];
const feature = layer.feature(0);
const geojson = feature.toGeoJSON(0, 0, 0);
console.log(JSON.stringify(geojson, null, 2));

Other packages similar to @mapbox/vector-tile

FAQs

Package last updated on 16 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc