bakerkretzmar / laravel-mapbox
A Laravel package for managing Mapbox Datasets and Tilesets.
Installs: 1 981
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 2
Forks: 5
Open Issues: 1
Requires
- php: ^7.2
- bakerkretzmar/zttp: ^0.6.0
Requires (Dev)
- codedungeon/phpunit-result-printer: ^0.26.2
- orchestra/testbench: ^3.8
- phpunit/phpunit: ^8.2
This package is auto-updated.
Last update: 2024-10-29 05:59:17 UTC
README
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
Installation
composer require bakerkretzmar/laravel-mapbox
Configuration
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"
Usage
Datasets
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();
Features
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();
Tilesets
List Tilesets:
$tilesets = Mapbox::tilesets()->list();
Delete a Tileset:
Mapbox::tilesets($tileset)->delete();
Uploads
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();
Testing
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
Changelog
See the CHANGELOG for information about what has changed recently.
Security
If you discover any security related issues, please email jacobtbk@gmail.com instead of using the issue tracker.
License
This package is licensed under the MIT License (MIT). Please see the LICENSE for details.