1. Go to this page and download the library: Download doode/filament-map-picker 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/ */
doode / filament-map-picker example snippets
namespace App\Filament\Resources;
use Doode\MapPicker\Fields\Map;
...
class FilamentResource extends Resource
{
...
public static function form(Form $form)
{
return $form->schema([
Map::make('location')
->label('Location')
->columnSpanFull()
->defaultLocation(latitude: 52.8027, longitude: -1.0546)
->afterStateUpdated(function (callable $set, ?array $state): void {
$set('latitude', $state['lat']);
$set('longitude', $state['lng']);
})
->afterStateHydrated(function ($state, $record, callable $set): void {
$set('location', ['lat' => $record->latitude, 'lng' => $record->longitude]);
})
->extraStyles([
'min-height: 100vh',
'border-radius: 10px'
])
->liveLocation(true, true, 5000)
->showMarker()
->markerColor("#22c55eff")
->showFullscreenControl()
->showZoomControl()
->draggable()
->tilesUrl("https://tile.openstreetmap.de/{z}/{x}/{y}.png")
->zoom(13)
->detectRetina()
->showMyLocationButton()
->geoManToolbar(true)
->geoManEditable(true)
->geoManPosition('topleft')
->drawCircleMarker()
->rotateMode()
->clickable() //click to move marker
->drawText() //disabled by default
->drawMarker()
->drawPolygon()
->drawPolyline()
->drawCircle()
->dragMode()
->cutPolygon()
->editPolygon()
->deleteLayer()
->setColor('#3388ff')
->setFilledColor('#cad9ec')
]),
// Field to store the geojson data
Hidden::make('geomanbox')
}
...
}