bakerkretzmar/laravel-mapbox

A Laravel package for managing Mapbox Datasets and Tilesets.

1.1.1 2019-11-29 14:46 UTC

This package is auto-updated.

Last update: 2021-09-29 02:36:02 UTC


README

Build status StyleCI Scrutinizer code quality Code coverage Latest stable version Total downloads

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:

DatasetsFeaturesTilesetsUploads

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

Mapbox documentation.

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

Mapbox documentation.

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

Mapbox documentation.

List Tilesets:

$tilesets = Mapbox::tilesets()->list();

Delete a Tileset:

Mapbox::tilesets($tileset)->delete();

Uploads

Mapbox documentation.

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.