certles / filament-maps
Reliable map fields for Filament: location picker with address search, GeoJSON drawing, table column and infolist entries that work in tabs, repeaters, modals and SPA mode.
Requires
- php: ^8.2
- filament/filament: ^4.16|^5.11
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- orchestra/testbench: ^10.0|^11.0
- pestphp/pest: ^3.0|^4.0
- pestphp/pest-plugin-laravel: ^3.0|^4.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Map fields for Filament 4 and 5 that keep working where map plugins usually break: hidden tabs, collapsed sections, repeaters, modals, slide-overs and SPA mode.
MapPicker: click the map, drag the marker or type the coordinates.LocationPicker: the same plus address search, the address of the picked point written to a field, and "use my location".GeoJsonPicker: draw, edit and remove polygons, rectangles, lines and markers, saved as GeoJSON.MapColumn,MapEntry,GeoJsonEntry: map previews in tables and on view pages.
Leaflet with OpenStreetMap. No API key, no build step: the package ships prebuilt assets, and each map component loads only on pages that use it. Free and open source (MIT).
Requirements
- PHP 8.2+
- Filament 4.16+ or 5.11+
Installation
composer require certles/filament-maps php artisan filament:assets
Optionally publish the config file:
php artisan vendor:publish --tag=filament-maps-config
Pick a point
One JSON column
// migration $table->json('location')->nullable(); // model protected function casts(): array { return ['location' => 'array']; } // form use Certles\FilamentMaps\Forms\Components\MapPicker; MapPicker::make('location');
The state is ['lat' => 52.2297, 'lng' => 21.0122] or null. An empty field is saved as null, never as 0,0.
Separate latitude and longitude columns
MapPicker::make('location_picker') ->latitudeField('latitude') ->longitudeField('longitude'), TextInput::make('latitude')->numeric(), TextInput::make('longitude')->numeric(),
The picker reads both fields, writes the picked point back to them and is not saved itself. The two fields can also be Hidden.
Options
MapPicker::make('location') ->defaultCenter(50.0617, 19.9373) // used when there is no point yet ->defaultZoom(12) ->mapHeight(400) // px, or any CSS length: '24rem' ->draggable(false) // marker cannot be dragged ->clickToPlace(false) // clicking the map does not move the marker ->coordinateInputs(false) // hide the latitude/longitude inputs ->tiles('https://{s}.tile.example.com/{z}/{x}/{y}.png', '© Example', 18);
Use ->live() when other fields need to react to the point immediately.
Search for an address
use Certles\FilamentMaps\Forms\Components\LocationPicker; LocationPicker::make('location') ->addressField('address'), // optional: fills this field with the address TextInput::make('address'),
Choosing a search result moves the marker and fills the address. Clicking the map or dragging the marker looks up the address of the new point. All MapPicker options work too.
LocationPicker::make('location') ->searchable(false) // no search box ->locateUser(false); // no "use my location" button (it needs HTTPS)
Draw shapes
// migration: $table->json('service_area')->nullable(); // model: 'service_area' => 'array' in casts() use Certles\FilamentMaps\Forms\Components\GeoJsonPicker; GeoJsonPicker::make('service_area') ->shapes(['polygon', 'rectangle']) // any of: marker, polyline, polygon, rectangle ->maxShapes(1) // with 1, a new shape replaces the old one ->searchable(), // search box to find the area first
The state is a GeoJSON FeatureCollection with coordinates rounded to 7 decimals, or null. Invalid GeoJSON and too many shapes fail validation. Rectangles are saved as polygons.
Tables and view pages
use Certles\FilamentMaps\Infolists\Components\GeoJsonEntry; use Certles\FilamentMaps\Infolists\Components\MapEntry; use Certles\FilamentMaps\Tables\Columns\MapColumn; MapColumn::make('location')->mapWidth(200)->mapHeight(120), MapEntry::make('location'), // from separate columns MapEntry::make('position') ->state(fn ($record) => ['lat' => $record->latitude, 'lng' => $record->longitude]), GeoJsonEntry::make('service_area'),
Geocoding
Address search runs on your server: provider API keys never reach the browser, results are cached and each user is rate limited (30 requests per minute by default). The default provider is Photon with OpenStreetMap data and no key.
The public Photon instance is meant for fair use. For heavier use, self-host Photon and set FILAMENT_MAPS_PHOTON_URL. The public instance labels results in English, German or French. Other app locales get local names (for example "Kraków", "Warszawa").
To use another provider, implement Certles\FilamentMaps\Geocoding\Geocoder and bind it:
use Certles\FilamentMaps\Geocoding\CachedGeocoder; use Certles\FilamentMaps\Geocoding\Geocoder; $this->app->singleton(Geocoder::class, fn () => new CachedGeocoder(new MyGeocoder(/* ... */), cache()->store()));
In tests, bind Certles\FilamentMaps\Geocoding\FakeGeocoder with a list of GeocodingResult objects. It never calls the network.
Tiles
OpenStreetMap's public tiles are fine for an admin panel with a handful of users. Read the tile usage policy and switch to a tile provider (tiles() or the config file) for heavier use.
How it stays reliable
- A map is created only when its container becomes visible (
IntersectionObserver), so maps in hidden tabs, collapsed sections and modals start with the right size. - Every size change (tab switch, modal animation, sidebar collapse) calls Leaflet's
invalidateSize()and re-centres the map if it was never visible. - The map element is ignored by Livewire morphing and is replaced only when its configuration or record changes.
- Components clean up on destroy, so SPA navigation and removed repeater items do not leak map instances.
- Mouse-wheel zoom turns on only after you click the map, so scrolling the page never gets stuck on it.
- The package never sets
window.L, so it does not clash with other Leaflet code on the page.
Testing
composer test # Pest; CI runs PHP 8.2–8.5 with Filament 4 and 5
tests/e2e/smoke.mjs and tests/e2e/geo-smoke.mjs run Playwright checks against a sandbox app: tabs, a collapsed section with a repeater, a modal, infolists, SPA navigation, address search, drawing and console errors.
License
MIT. See LICENSE.md.




