PHP code example of humaidem / filament-map-picker

1. Go to this page and download the library: Download humaidem/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/ */

    

humaidem / filament-map-picker example snippets



namespace App\Filament\Resources;
use Filament\Resources\Resource;
use Filament\Resources\Forms\Form;
use Humaidem\FilamentMapPicker\Fields\OSMMap;
...
class FilamentResource extends Resource
{
    ...
    public static function form(Form $form)
    {
        return $form->schema([
            OSMMap::make('location')
                ->label('Location')
                ->showMarker()
                ->draggable()
                ->extraControl([
                    'zoomDelta'           => 1,
                    'zoomSnap'            => 0.25,
                    'wheelPxPerZoomLevel' => 60
                ])
                // tiles url (refer to https://www.spatialbias.com/2018/02/qgis-3.0-xyz-tile-layers/)
                ->tilesUrl('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}')
           ]);
    }
    ...
}

...
OSMMap::make('location')
    ->afterStateHydrated(function ($state, callable $set) {
            if ($state instanceof Point) {
                /** @var Point $state */
                $set('location', ['lat' => $state->getLat(), 'lng' => $state->getLng()]);
            }
        });
...

...
OSMMap::make('location')
   ->mutateDehydratedStateUsing(function ($state) {
                if (!($state instanceof Point))
                    return new Point($state['lat'], $state['lng']);

                return $state;
            });
...

...
OSMMap::make('location')
    ->afterStateUpdated(function ($state, callable $set) use ($name) {
            if ($state instanceof Point) {
                /** @var Point $state */
                $set($name, ['lat' => $state->getLat(), 'lng' => $state->getLng()]);
            }
        });
...