swisnl/filament-geometry

Geometry form field for Filament PHP

dev-main 2025-07-02 12:52 UTC

This package is auto-updated.

Last update: 2025-07-02 12:52:54 UTC


README

Latest Version on Packagist Software License Buy us a tree GitHub Tests Action Status GitHub Code Style Action Status Total Downloads Made by SWIS

Filament geometry screenshot

Warning

Work in progress, not stable yet!

Installation

You can install the package via composer:

composer require swisnl/filament-geometry

You can publish the views using

php artisan vendor:publish --tag="filament-geometry-views"

Component

Geometry Field

The Geometry field displays a leaflet map, with a set of configuration options.

Map Field

Usage

Geometry Field

Note: The Geometry field expects the 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,
        ]),
    ...
]

The name used for make() must be the one you set up as your model's computed geojson property. Note that you can have multiple maps on a form, by adding a second computed property referencing a second pair of geojson fields.

Full options

The full set of options is as follows. All option methods support closures, as well as direct values.

use Swis\Filament\Geometry\Enums\DrawMode;
use Swis\Filament\Geometry\Forms\Geometry;

...

Geometry::make('location')
    ->label(__('Location'))

    // Basic configuration
    ->detectRetina(true)
    ->maxZoom(28)
    ->minZoom(0)
    ->tilesUrl('https://tile.openstreetmap.org/{z}/{x}/{y}.png')
    ->zoom(15)

    // Marker configuration
    ->markerColor("#3b82f6")
    
    // Controls
    ->showFullscreenControl(true)
    ->showZoomControl(true)
    ->drawModes([
        DrawMode::Marker,
        DrawMode::Polygon,
        DrawMode::Polyline,
        DrawMode::Rectangle,
    ])
    
    // Location features
    ->boundaries(true, 49.5, -11, 61, 2) // Example for British Isles

    // GeoMan Integration
    ->geoManPosition('topleft')

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.