PHP code example of lbcdev / filament-maps-widgets
1. Go to this page and download the library: Download lbcdev/filament-maps-widgets 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-widgets example snippets
namespace App\Filament\Widgets;
use LBCDev\FilamentMapsWidgets\Widgets\MapWidget;
use LBCDev\MapGeometries\Marker;
use LBCDev\MapGeometries\MarkerCollection;
class LocationsMap extends MapWidget
{
protected function getMarkers(): MarkerCollection
{
$markers = new MarkerCollection();
$markers->add(
Marker::make('home')
->lat(40.7128)
->lng(-74.0060)
->popup('New York City')
);
return $markers;
}
protected function getMapCenter(): array
{
return ['lat' => 40.7128, 'lng' => -74.0060];
}
}
use LBCDev\FilamentMapsWidgets\Widgets\MapWidget;
use LBCDev\MapGeometries\Marker;
class MyMap extends MapWidget
{
protected function getMarkers(): array
{
return [
Marker::make('marker-1')
->lat(51.505)
->lng(-0.09)
->popup('London'),
];
}
}
class MyMap extends MapWidget
{
protected function getMapCenter(): array
{
return ['lat' => 51.505, 'lng' => -0.09];
}
protected function getMapZoom(): int
{
return 13;
}
protected function getMapOptions(): array
{
return [
'scrollWheelZoom' => true,
'dragging' => true,
'minZoom' => 10,
'maxZoom' => 18,
];
}
}
use App\Models\Location;
class LocationsMap extends MapWidget
{
protected function getMarkers(): MarkerCollection
{
$markers = new MarkerCollection();
Location::all()->each(function ($location) use ($markers) {
$markers->add(
Marker::make($location->id)
->lat($location->latitude)
->lng($location->longitude)
->color($location->is_active ? 'green' : 'red')
->popup("<b>{$location->name}</b><br>{$location->address}")
);
});
return $markers;
}
}
use LBCDev\FilamentMapsWidgets\Actions\ZoomAction;
class MyMap extends MapWidget
{
protected function getActions(): array
{
return [
ZoomAction::make()
->position('topright'),
];
}
}