1. Go to this page and download the library: Download lbcdev/filament-maps-fields 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/ */
lbcdev / filament-maps-fields example snippets
use Filament\Panel;
public function panel(Panel $panel): Panel
{
return $panel
// ... otras configuraciones
->renderHook(
'panels::head.end',
fn(): string => view('filament-maps-fields::hooks.leaflet-assets')->render()
);
}
use Illuminate\Database\Eloquent\Model;
class Place extends Model
{
protected $fillable = ['name', 'location'];
protected $casts = [
'location' => 'array', // Cast automático a array
];
}
use LBCDev\FilamentMapsFields\Forms\Components\MapField;
use Filament\Forms\Components\TextInput;
public static function form(Form $form): Form
{
return $form->schema([
TextInput::make('name')
->
use Illuminate\Database\Eloquent\Model;
class Location extends Model
{
protected $fillable = ['name', 'latitude', 'longitude'];
}
use LBCDev\FilamentMapsFields\Forms\Components\MapField;
use Filament\Forms\Components\TextInput;
public static function form(Form $form): Form
{
return $form->schema([
TextInput::make('name')
-> ->columnSpanFull(),
// Opcionalmente puedes mostrar los campos
TextInput::make('latitude')
->disabled()
->dehydrated(),
TextInput::make('longitude')
->disabled()
->dehydrated(),
]);
}
MapField::make('location_map')
->latitude('location.latitude') // Notación de punto
->longitude('location.longitude') // Notación de punto
Schema::table('locations', function (Blueprint $table) {
$table->json('location')->nullable()->after('name');
});
// Antes (Legacy)
MapField::make('map')
->latitude('latitude')
->longitude('longitude')
// Después (JSON)
MapField::make('location')
Schema::table('locations', function (Blueprint $table) {
$table->dropColumn(['latitude', 'longitude']);
});
// Modo JSON (simple)
MapField::make('location')
->height(500) // Altura del mapa en píxeles (default: 400)
->zoom(15) // Nivel de zoom inicial (default: 15)
->showPasteButton() // Mostrar botón para pegar coordenadas
->showLabel() // Mostrar etiqueta con coordenadas (default: true)
->interactive(true) // Permitir interacción (default: true)
->readOnly() // Hacer el mapa de solo lectura
// Modo Legacy (requiere latitude y longitude)
MapField::make('map')
->latitude('latitude') // Campo de latitud (requerido en modo Legacy)
->longitude('longitude') // Campo de longitud (requerido en modo Legacy)
->height(500)
->zoom(15)
->latitude('latitude') // Campo simple
->latitude('location.latitude') // Campo anidado
->longitude('longitude') // Campo simple
->longitude('location.longitude') // Campo anidado
->height(400) // Altura por defecto
->height(600) // Mapa más alto
->zoom(15) // Zoom por defecto
->zoom(10) // Zoom más alejado
->zoom(18) // Zoom más cercano
->interactive() // Mapa interactivo (por defecto)
->interactive(false) // Mapa de solo lectura
->readOnly() // Mapa de solo lectura
->readOnly(false) // Mapa interactivo
use LBCDev\FilamentMapsFields\Forms\Components\MapField;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\Section;
public static function form(Form $form): Form
{
return $form->schema([
Section::make('Información Básica')
->schema([
TextInput::make('name')
->label('Nombre del lugar')
->ude('longitude')
->height(500)
->zoom(15)
->showPasteButton(),
TextInput::make('latitude')
->label('Latitud')
->disabled()
->dehydrated()
->numeric()
->
use LBCDev\FilamentMapsFields\Forms\Components\MapField;
public static function form(Form $form): Form
{
return $form->schema([
MapField::make('location')
->latitude('latitude')
->longitude('longitude')
->readOnly() // No permite cambiar la ubicación
->showLabel(false) // Oculta la etiqueta de coordenadas
->height(400)
->zoom(15),
]);
}
use LBCDev\FilamentMapsFields\Forms\Components\MapField;
use Filament\Forms\Components\Section;
public static function form(Form $form): Form
{
return $form->schema([
Section::make('Ubicación de Origen')
->schema([
MapField::make('origin_location')
->latitude('origin_latitude')
->longitude('origin_longitude')
->height(300),
]),
Section::make('Ubicación de Destino')
->schema([
MapField::make('destination_location')
->latitude('destination_latitude')
->longitude('destination_longitude')
->height(300),
]),
]);
}
Schema::create('locations', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->json('location'); // Contiene latitude y longitude
$table->timestamps();
});
class Location extends Model
{
protected $fillable = ['name', 'location'];
protected $casts = [
'location' => 'array',
];
}
use LBCDev\FilamentMapsFields\Infolists\Entries\MapEntry;
MapEntry::make('location')
->height(300)
->zoom(15)