PHP code example of afsakar / filament-leaflet-map-picker

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

    

afsakar / filament-leaflet-map-picker example snippets


Schema::create('properties', function (Blueprint $table) {
    $table->id();
    $table->json('location')->nullable();
    $table->timestamps();
});

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Property extends Model
{
    protected $fillable = [
        'location',
    ];

    protected $casts = [
        'location' => 'array',
    ];
}

use Afsakar\LeafletMapPicker\LeafletMapPicker;

LeafletMapPicker::make('location')
    ->label('Property Location')
    ->height('500px')
    ->defaultLocation(['lat' => 41.0082, 'lng' => 28.9784])
    ->defaultZoom(15)
    ->draggable()
    ->clickable()
    ->myLocationButtonLabel('Go to My Location')
    ->geocoderEndpoint('https://nominatim.openstreetmap.org/search')
    ->geolocationTimeout(10000)
    ->geolocationHighAccuracy()
    ->hideTileControl()
    ->readOnly()
    ->tileProvider('openstreetmap')
    ->customTiles([
        'mapbox' => [
            'url' => 'https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}',
            'options' => [
                'attribution' => '&copy; <a href="https://www.mapbox.com/">Mapbox</a>',
                'id' => 'mapbox/streets-v11',
                'maxZoom' => 19,
                'accessToken' => 'YOUR_MAPBOX_TOKEN',
            ],
        ],
    ])
    ->customMarker([
        'iconUrl' => asset('pin-2.png'),
        'iconSize' => [38, 38],
        'iconAnchor' => [19, 38],
        'popupAnchor' => [0, -38],
    ]);

LeafletMapPicker::make('location')
    ->showCoordinateInputs();

LeafletMapPicker::make('location')
    ->defaultLocation(['lat' => 41.0082, 'lng' => 28.9784]);

use Afsakar\LeafletMapPicker\LeafletMapPickerColumn;

public function table(Table $table): Table
{
    return $table->columns([
        LeafletMapPickerColumn::make('location')
            ->label('Location')
            ->height('240px'),
    ]);
}

use Afsakar\LeafletMapPicker\LeafletMapPickerEntry;

LeafletMapPickerEntry::make('location')
    ->label('Property Location')
    ->height('500px')
    ->defaultLocation(['lat' => 41.0082, 'lng' => 28.9784])
    ->tileProvider('openstreetmap')
    ->hideTileControl()
    ->customTiles([
        'mapbox' => [
            'url' => 'https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}',
            'options' => [
                'attribution' => '&copy; <a href="https://www.mapbox.com/">Mapbox</a>',
                'id' => 'mapbox/streets-v11',
                'maxZoom' => 19,
                'accessToken' => 'YOUR_MAPBOX_TOKEN',
            ],
        ],
    ])
    ->customMarker([
        'iconUrl' => asset('pin-2.png'),
        'iconSize' => [38, 38],
        'iconAnchor' => [19, 38],
        'popupAnchor' => [0, -38],
    ]);