1. Go to this page and download the library: Download swisnl/filament-geometry 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/ */
swisnl / filament-geometry example snippets
use Filament\Forms\Form;
use Swis\Filament\Geometry\Enums\DrawMode;
use Swis\Filament\Geometry\Forms\Geometry;
public function form(Form $form): Form
{
return $form
->schema([
Geometry::make('location'),
]);
}
use Filament\Forms\Form;
use Swis\Filament\Geometry\Bounds;
use Swis\Filament\Geometry\Enums\ControlPosition;
use Swis\Filament\Geometry\Enums\DrawMode;
use Swis\Filament\Geometry\Forms\Geometry;
use Swis\Filament\Geometry\GeoSearchProviders\OpenStreetMap;
use Swis\Filament\Geometry\Icons\Marker;
use Swis\Filament\Geometry\TileLayers\Carto;
public function form(Form $form): Form
{
return $form
->schema([
Geometry::make('location')
->label(__('Location'))
// Map configuration
->maxZoom(16)
->minZoom(4)
->center(52.164206390898904, 4.491920969490259)
->zoom(15)
->bounds(Bounds::make(49.5, -11, 61, 2)) // Example for British Isles
->tileLayer(Carto::make())
// Marker configuration
->markerIcon(Marker::make('#3b82f6'))
// Controls
->showFullscreenControl(true)
->showZoomControl(true)
->showAttributionControl(true)
->geoSearch(OpenStreetMap::make())
->drawModes([
DrawMode::Polygon,
DrawMode::Rectangle,
])
->multipart(false)
->drawControlPosition(ControlPosition::TopRight),
]);
}
use Filament\Forms\Form;
use Swis\Filament\Geometry\Forms\Geometry;
public function form(Form $form): Form
{
return $form
->schema([
Geometry::make('location')
// Use one of the following state cast methods:
->asString()
->asArray()
->asObject()
->asEloquentSpatial()
// Or use a custom state cast that implements \Filament\Schemas\Components\StateCasts\Contracts\StateCast:
->stateCast(new YourCustomStateCast()),
]);
}