PHP code example of darkclow4 / filament-map-picker
1. Go to this page and download the library: Download darkclow4/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/ */
darkclow4 / filament-map-picker example snippets
Darkclow4\FilamentMapPicker\FilamentMapPickerServiceProvider::class
[
'lat' => -6.2,
'lng' => 106.816666,
]
[
'lat' => -6.2,
'lng' => 106.816666,
'geojson' => [
'type' => 'FeatureCollection',
'features' => [
// polygon / rectangle / circle features
],
],
]
use Darkclow4\FilamentMapPicker\Forms\Components\MapPicker;
use Filament\Schemas\Components\Utilities\Set;
MapPicker::make('location')
->mode('click')
->defaultLocation(-6.2, 106.816666)
->zoom(13)
->height(420)
->live()
->afterStateUpdated(function (?array $state, Set $set): void {
$set('latitude', $state['lat'] ?? null);
$set('longitude', $state['lng'] ?? null);
});
use Darkclow4\FilamentMapPicker\Forms\Components\MapPicker;
use Filament\Forms\Components\Hidden;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Components\Utilities\Set;
MapPicker::make('location')
->mode('drag')
->defaultLocation(-6.2, 106.816666)
->drawable()
->drawTools(['polygon', 'rectangle', 'circle'])
->multipleShapes()
->fitDrawBounds(false)
->height(480)
->live()
->afterStateHydrated(function (MapPicker $component, Get $get): void {
$component->state([
'lat' => is_numeric($get('latitude')) ? (float) $get('latitude') : -6.2,
'lng' => is_numeric($get('longitude')) ? (float) $get('longitude') : 106.816666,
'geojson' => is_array($get('area'))
? $get('area')
: [
'type' => 'FeatureCollection',
'features' => [],
],
]);
})
->afterStateUpdated(function (?array $state, Set $set): void {
$set('latitude', $state['lat'] ?? null);
$set('longitude', $state['lng'] ?? null);
$set('area', $state['geojson'] ?? [
'type' => 'FeatureCollection',
'features' => [],
]);
});
Hidden::make('area');
MapPicker::make('location')->mode('drag')
MapPicker::make('location')->mode('click')
MapPicker::make('location')
->tile('osm')
[
'osm' => [
'label' => 'OpenStreetMap',
'url' => 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
'options' => [
'maxZoom' => 19,
'attribution' => '© OpenStreetMap contributors',
],
],
]
MapPicker::make('location')
->tiles([
'opentopo' => [
'label' => 'Open Topo Map',
'url' => 'https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png',
'options' => [
'maxZoom' => 19,
'attribution' => 'Map data: © OpenStreetMap contributors | Map style: © OpenTopoMap',
],
],
])
->tile('opentopo');
MapPicker::make('location')
->searchable()
->searchPlaceholder('Search for a place')
->searchResultLimit(8)
https://nominatim.openstreetmap.org/search
->searchProviderUrl('https://nominatim.openstreetmap.org/search')
MapPicker::make('location')
->drawable()
->drawTools(['polygon', 'rectangle', 'circle'])
->multipleShapes()
->fitDrawBounds(false)
->tile('osm')
[
'custom-key' => [
'label' => 'Tile Name',
'url' => 'https://example.com/{z}/{x}/{y}.png',
'options' => [
'maxZoom' => 20,
'attribution' => '...'
],
],
]
->showDefaultTile(false)
->mode('drag')
->mode('click')
->defaultLocation(-6.2, 106.816666)
->zoom(13)
->height(420)
->height('32rem')
->height('60vh')
->markerColor('#0f766e')
->markerColor('rgb(37, 99, 235)')
->searchable()
->searchPlaceholder('Search for a city or address')
->searchProviderUrl('https://nominatim.openstreetmap.org/search')
->searchResultLimit(8)
->drawable()
->drawTools(['polygon', 'rectangle'])
->fitDrawBounds(false)
->multipleShapes()
->showAreaMeasurement()
->areaMeasurementUnit('m2')
->areaMeasurementUnit('ha')
bash
php artisan filament:assets