A lightweight wrapper to make working with Mapbox Maps service APIs in Laravel apps a breeze. Based on Matt Fox’s mapbox-api-laravel
.
This package supports managing the following services via the Mapbox API:
Datasets • Features • Tilesets • Uploads
composer require bakerkretzmar/laravel-mapbox
Add the following to your .env
file:
MAPBOX_USERNAME={your Mapbox username}
MAPBOX_TOKEN={your Mapbox access token}
Optionally, you can publish the package’s config file:
php artisan vendor:publish --provider="bakerkretzmar\LaravelMapbox\LaravelMapboxServiceProvider"
List Datasets:
$datasets = Mapbox::datasets()->list();
Retrieve a Dataset:
$dataset = Mapbox::datasets($dataset_id)->get();
Create a Dataset:
$dataset = Mapbox::datasets()->create();
// or
$dataset = Mapbox::datasets()->create([
'name' => 'My Dataset',
'description' => 'A new Mapbox Dataset',
]);
Update a Dataset:
$dataset = Mapbox::datasets($dataset_id)->update([
'name' => 'My Updated Dataset',
'description' => 'An updated Mapbox Dataset',
]);
Delete a Dataset:
Mapbox::datasets($dataset_id)->delete();
List Features:
$features = Mapbox::datasets($dataset_id)->features()->list();
// or
$features = Mapbox::features($dataset_id)->list();
Retrieve a Feature:
$feature = Mapbox::datasets($dataset_id)->features($feature_id)->get();
// or
$feature = Mapbox::features($dataset_id, $feature_id)->get();
Create or update a Feature:
$feature = Mapbox::datasets($dataset_id)->features()->add($feature);
// or
$feature = Mapbox::features($dataset_id)->add($feature);
Delete a Feature:
Mapbox::datasets($dataset_id)->features($feature_id)->delete();
// or
Mapbox::features($dataset_id, $feature_id)->delete();
List Tilesets:
$tilesets = Mapbox::tilesets()->list();
Delete a Tileset:
Mapbox::tilesets($tileset)->delete();
Get temporary S3 credentials:
$credentials = Mapbox::uploads()->credentials();
Create an Upload:
$upload = Mapbox::uploads()->create([
'tileset' => 'my_tileset_name',
'url' => 'http://{bucket}.s3.amazonaws.com/{key}',
'name' => 'My Tileset',
]);
// or
$upload = Mapbox::uploads()->create([
'tileset' => 'my_tileset_name',
'dataset' => 'my_dataset_id',
'name' => 'My Tileset',
]);
Retrieve an Upload’s status:
$upload = Mapbox::uploads($upload_id)->get();
List Upload statuses:
$uploads = Mapbox::uploads()->list();
Delete an Upload:
Mapbox::uploads($upload_id)->delete();
Note — Tests hit the real Mapbox API. Before testing the package, set up a local testing environment file with valid Mapbox credentials (cp .env.testing.example .env.testing
and fill in the blanks).
composer test
See the CHANGELOG for information about what has changed recently.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
This package is licensed under the MIT License (MIT). Please see the LICENSE for details.