PHP code example of traineratwot / filament-openstreetmap

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

    

traineratwot / filament-openstreetmap example snippets



return new class extends Migration {
    public function up(): void
    {
        Schema::create('map_points', function (Blueprint $table) {
            $table->id();

            $table->point('point')->nullable(); // for Point type in Laravel 10
            $table->geography('point', 'point', 0)->nullable(); // for Point type in Laravel 11

            $table->string('point_string')->nullable(); // for String type
            $table->json('point_array')->nullable(); // for Array type
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('map_points');
    }
};

namespace App\Models;

use MatanYadaev\EloquentSpatial\Objects\Point;
use Illuminate\Database\Eloquent\Model;

class MapPoint extends Model
{

    protected $casts = [
        'point' => Point::class, // Important for Point type
        'point_array' => 'array', // Important for Array type
    ];
    
    ...
}




namespace App\Filament\Resources;

use Traineratwot\FilamentOpenStreetMap\Forms\Components\MapInput;


class MapPointResource extends Resource
{
    protected static ?string $model = MapPoint::class;

    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                MapInput::make('point')
                    ->saveAsPoint() // Important for Point type
                    ->srid(4326) // Change srid for Point
                    ->placeholder('Choose your location')
                    ->coordinates(37.619, 55.7527) // start coordinates
                    ->rows(10) // height of map
                ,

                MapInput::make('point_string')
                    ->saveAsString() // default 
                    ->placeholder('Choose your location')
                    ->coordinates(37.619, 55.7527) // start coordinates
                    ->rows(10) // height of map
                ,

                MapInput::make('point_array')
                    ->saveAsArray() // Important for Array type
                    ->placeholder('Choose your location')
                    ->coordinates(37.619, 55.7527) // start coordinates
                    ->rows(10) // height of map
                ,

              ]);
    }
...
}