swisnl / filament-geometry
Geometry form field for Filament PHP
Fund package maintenance!
swisnl
Requires
- php: ^8.2
- filament/filament: ^3.0
- filament/forms: ^3.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.11|^3.5
- laravel/pint: ^1.14
- nunomaduro/collision: ^7.10.0|^8.1.1
- orchestra/testbench: ^8.22.0|^9.0.0|^10.0.0
- pestphp/pest: ^3.0|^2.36
- pestphp/pest-plugin-laravel: ^3.0|^2.4
- phpstan/extension-installer: ^1.3|^2.0
- phpstan/phpstan-deprecation-rules: ^1.1|^2.0
- phpstan/phpstan-phpunit: ^1.3|^2.0
- spatie/laravel-ray: ^1.35
README
Warning
Work in progress, not stable yet!
Installation
You can install the package via composer:
composer require swisnl/filament-geometry
In an effort to align with Filament's theming methodology you will need to use a custom theme to use this plugin.
Note If you have not set up a custom theme and are using a Panel follow the instructions in the Filament Docs first.
Add the plugin's views to your tailwind.config.js
file.
content: [ '<path-to-vendor>/swisnl/filament-geometry/**/*.blade.php', ]
Component
Geometry Field
The Geometry field displays a leaflet map, with a set of configuration options.
Usage
Geometry Field
Important
This field is designed to be used in conjunction with a database column of type POINT
, LINESTRING
, POLYGON
or GEOMETRY
. It currently does not support geometry types with multiple items like MULTIPOINT
, MULTILINESTRING
, MULTIPOLYGON
or GEOMETRYCOLLECTION
. This field expects the attribute value to be a valid GeoJSON string. Make sure your model attribute stores and retrieves GeoJSON data as a string.
The form field can be used with no options, by simply adding this to your Filament form schema:
use Swis\Filament\Geometry\Enums\DrawMode; use Swis\Filament\Geometry\Forms\Geometry; ... ->schema[ ... Geometry::make('location') ->drawModes([ DrawMode::Marker, DrawMode::Polygon, DrawMode::Polyline, DrawMode::Rectangle, ]), ... ]
Full options
The full set of options is as follows. Some option methods support closures, as well as direct values.
use Swis\Filament\Geometry\Enums\ControlPosition; use Swis\Filament\Geometry\Enums\DrawMode; use Swis\Filament\Geometry\Forms\Geometry; use Swis\Filament\Geometry\Icons\Marker; use Swis\Filament\Geometry\TileLayers\Carto; ... Geometry::make('location') ->label(__('Location')) // Map configuration ->maxZoom(16) ->minZoom(4) ->center(52.164206390898904, 4.491920969490259) ->zoom(15) ->boundaries(true, 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) ->drawModes([ DrawMode::Polygon, DrawMode::Rectangle, ]) ->drawControlPosition(ControlPosition::TopRight)
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
SWIS ❤️ Open Source
SWIS is a web agency from Leiden, the Netherlands. We love working with open source software.