Jesse
Jesse

Reputation: 2053

Programmatically update tileset

Mapbox data management workflow documentation (or my unserstanding of it) seems to be lacking.

I currently have a custom style with some custom tilesets added to it. Whenever the data of my tileset needs to be updated, is there and elegant way to update the existing data through the API and retain any styling for a particular style?

My best guess for what that workflow would look like:

  1. Request Mapbox S3 credentials
  2. Upload data to new tileset
  3. Retrieve new tileset ID
  4. List style's current tileset IDs
  5. Remove old tileset from style
  6. Add new tileset to style
  7. Restyle new tileset to match old tileset

I'm hoping I'm missing something obvious that lets me do the following instead:

  1. Update style's tileset's data

Upvotes: 1

Views: 1220

Answers (1)

Steve Bennett
Steve Bennett

Reputation: 126105

You can use Mapbox's mapbox-upload Node module to replace an existing tileset: https://github.com/mapbox/mapbox-upload

var progress = upload({
    file: __dirname + '/test.mbtiles', // Path to mbtiles file on disk.
    account: 'test', // Mapbox user account.
    accesstoken: 'validtoken', // A valid Mapbox API secret token with the uploads:write scope enabled.
    mapid: 'test.upload', // The identifier of the map to create or update.
    name: 'My upload' // Optional name to set, otherwise a default such as original.geojson will be used.
});

Set the mapid property to the id of your existing tileset. Real-life example here.

Similarly via the command line:

$ npm install --global mapbox-upload
$ export MapboxAccessToken=<access token with uploads:write scope enabled>
$ mapbox-upload username.dataid /path/to/file

Upvotes: 2

Related Questions