PHP code example of marshmallow / nova-map-box-field

1. Go to this page and download the library: Download marshmallow/nova-map-box-field library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

marshmallow / nova-map-box-field example snippets


use Marshmallow\MapBox\MapBox;

public function fields(NovaRequest $request)
{
    return [
        MapBox::make('Area', 'area'),
    ];
}

use Marshmallow\MapBox\MapBox;

MapBox::make('Area', 'area')
    ->height(400)
    ->defaultZoom(10)
    ->latitude(52.111221)
    ->longitude(4.647251)
    ->style('mapbox://styles/mapbox/streets-v11')
    ->navigationControls(true)
    ->drawControls(true)
    ->polygonPreviewColor('#ff133b')
    ->polygonPreviewOpacity(0.5);

MapBox::make('Area', 'area')
    ->setCenter(function ($field) {
        return [52.111221, 4.647251];
    });

MapBox::make('Area', 'area')
    ->addMarker(fn ($field) => [52.111221, 4.647251])
    ->addMarker(fn ($field) => [51.924420, 4.477733]);

MapBox::make('Area', 'area')
    ->defaultPolygon(latitude: 52.111221, longitude: 4.647251, range_in_km: 5);

use Marshmallow\MapBox\MapBox;
use Marshmallow\MapBox\Polygon;

MapBox::make('Area', 'area')
    ->prefillWith(function ($field) {
        return [
            new Polygon(
                polygon: [[52.111221, 4.647251], [52.120000, 4.650000], [52.115000, 4.660000]],
                color: '#ff133b',
                opacity: 0.5,
            ),
        ];
    });
bash
php artisan vendor:publish --provider="Marshmallow\MapBox\FieldServiceProvider"