PHP code example of kpebedko22 / filament-yandex-map
1. Go to this page and download the library: Download kpebedko22/filament-yandex-map 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/ */
->schema([
YandexMap::make('point')
// Set mode of geo-object. Always roperties and options
->usingPlacemark(
new PlacemarkProperties(),
new PlacemarkOptions(),
)
// or set mode of geo-object using mode() method
->mode(YandexMapMode::Placemark)
// By default, values are taken from config
// You are free to override them using plain values or closure
->apiKey('your_yandex_api_key')
->suggestApiKey('your_yandex_suggest_api_key')
->center([53.35, 83.75])
->zoom(12)
->lang('ru_RU')
// By default: 600px
->height('600px')
// Setup control buttons
->deleteBtnParameters(
new ButtonData(__('filament-yandex-map::control-buttons.delete')),
new ButtonOptions(
float: ButtonFloat::Right,
selectOnClick: false
),
)
->drawBtnParameters()
->editBtnParameters()
// It's
->schema([
YandexMapEntry::make('point')
// Set mode of geo-object. Always // You are free to override them using plain values or closure
->apiKey('your_yandex_api_key')
->suggestApiKey('your_yandex_suggest_api_key')
->center([53.35, 83.75])
->zoom(12)
->lang('ru_RU')
// By default: 600px
->height('600px')
// It's
YandexMap::make('area')
->usingMultiPolygon()
// or with properties and options which are applied to every polygon
->usingMultiPolygon(
new PolygonProperties(),
new PolygonOptions(),
)
->usingArray() // or ->usingMagellan()
[
[[[53.0, 83.0], [53.0, 84.0], [54.0, 84.0], [53.0, 83.0]]], // polygon with one ring
[[[55.0, 85.0], [55.0, 86.0], [56.0, 86.0], [55.0, 85.0]]], // another polygon
]
// On the form
use Kpebedko22\FilamentYandexMap\Forms\Components\YandexMap;
use Kpebedko22\FilamentYandexMap\ValueObjects\Point;
use Kpebedko22\FilamentYandexMap\Enums\YandexMapMode;
YandexMap::make('point')
->usingPlacemark()
->formatStateUsing(static function (?Model $record) {
return $record
? (new Point($record->lat, $record->lng))->toArray()
: null;
}),
// CreatePage
protected function mutateFormDataBeforeCreate(array $data): array
{
$data['lat'] = $data['point']['lat'];
$data['lng'] = $data['point']['lng'];
unset($data['point']);
return parent::mutateFormDataBeforeCreate($data);
}
// EditPage
protected function mutateFormDataBeforeSave(array $data): array
{
$data['lat'] = $data['point']['lat'];
$data['lng'] = $data['point']['lng'];
unset($data['point']);
return parent::mutateFormDataBeforeSave($data);
}
YandexMap::make('point')
->usingPlacemark()
->deleteBtnParameters(
new ButtonData(__('filament-yandex-map::control-buttons.delete')),
new ButtonOptions(
float: ButtonFloat::Right,
selectOnClick: false
),
);
->drawBtnParameters(
new ButtonData(__('filament-yandex-map::control-buttons.draw')),
new ButtonOptions(float: ButtonFloat::Right),
);
->editBtnParameters(
new ButtonData(__('filament-yandex-map::control-buttons.edit')),
new ButtonOptions(float: ButtonFloat::Right),
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.