pushlogicltd / mapbox-api-laravel
A Laravel 11+ Package for managing Mapbox Datasets and Tilesets
Requires
- php: >=8.2.0
- guzzlehttp/guzzle: ^7.2
- illuminate/contracts: ^11.0
- illuminate/support: ^11.0
- jmikola/geojson: ^1.1.2
Requires (Dev)
- orchestra/testbench: ^8.14.0
- phpunit/phpunit: ^10.1
This package is auto-updated.
Last update: 2024-11-07 14:28:26 UTC
README
A Laravel 11+ Package for managing Mapbox Datasets and Tilesets
This library supports the listing, creation, and deletion of the following types via the Mapbox API:
Installation
Install Via Composer:
composer require pushlogicltd/mapbox-api-laravel
Laravel 11+
The service provider should be automatically registered.
// Facade Alias
'Mapbox' => PushLogicLtd\MapBoxAPILaravel\Facades\Mapbox::class,
Lumen:
// bootstrap/app.php:
$app->register(PushLogicLtd\MapBoxAPILaravel\MapBoxAPILaravelServiceProvider::class);
$app->withFacades(true, [
'PushLogicLtd\MapBoxAPILaravel\Facades\Mapbox' => 'Mapbox'
]);
Configuration
Add the following to your .env
file:
MAPBOX_ACCESS_TOKEN=[Your Mapbox Access Token]
MAPBOX_USERNAME=[Your Mapbox Username]
Note: Make sure your Access Token has the proper scope for all the operations you need to perform.
Usage
Datasets
List Datasets:
$list = Mapbox::datasets()->list();
Create Dataset:
$dataset = Mapbox::datasets()->create([
'name' => 'My Dataset',
'description' => 'This is my dataset'
]);
Retrieve Dataset:
$dataset = Mapbox::datasets($datasetID)->get();
Update Dataset:
$dataset = Mapbox::datasets($datasetID)->update([
'name' => 'My Dataset Updated',
'description' => 'This is my latest dataset'
]);
Delete Dataset:
$response = Mapbox::datasets($datasetID)->delete();
List Feature:
$response = Mapbox::datasets($datasetID)->features()->list();
Insert or Update Feature:
$response = Mapbox::datasets($datasetID)->features()->add($feature);
Retrieve Feature:
$response = Mapbox::datasets($datasetID)->features($featureID)->get();
Delete Feature:
$response = Mapbox::datasets($datasetID)->features($featureID)->delete();
Tilesets
List Tilesets:
// Options array is optional
$list = Mapbox::tilesets()->list([
'type' => 'raster',
'visibility' => 'public',
'sortby' => 'modified',
'limit' => 500
]);
Uploads
Get S3 Credentials:
// Returns S3Credentials Object
$response = Mapbox::uploads()->credentials();
Create Upload:
$response = Mapbox::uploads()->create([
'tileset' => '{username}.mytilesetid',
'url' => 'mapbox://datasets/{username}/{dataset}', // Or S3 Bucket URL from S3Credentials Object
'name' => 'Upload Name'
]);
Retrieve Upload Status:
$response = Mapbox::uploads($uploadID)->get();
List Upload Statuses:
$list = Mapbox::uploads()->list();
Delete Upload:
$response = Mapbox::uploads($uploadID)->delete();