goodappr / moonshine-yandex-maps
Yandex Maps and Polygons fields for MoonShine 4.x - point markers and drawable polygons
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Language:Blade
pkg:composer/goodappr/moonshine-yandex-maps
Requires
- php: ^8.2
- moonshine/moonshine: ^4.0
README
Пакет полей для MoonShine 4.x — работа с картами и полигонами через Yandex Maps API.
Возможности
- YandexMap — точки с метками, балуны, кастомный контент
- YandexMapPolygon — рисование полигонов, зоны доставки, районы
Требования
- PHP 8.2+
- Laravel 11+
- MoonShine 4.x
- API-ключ Яндекс.Карт
Установка
composer require goodappr/moonshine-yandex-maps
Конфигурация
Опубликуйте конфиг и задайте API-ключ:
php artisan vendor:publish --tag=moonshine-yandex-maps-config
В .env:
YANDEX_MAPS_API_KEY=your_yandex_maps_api_key
Либо добавьте в config/services.php:
'yandex' => [ 'maps_api_key' => env('YANDEX_MAPS_API_KEY', ''), ],
Использование
YandexMap — точки на карте
use MoonShine\YandexMaps\Fields\YandexMap; use MoonShine\UI\Fields\Text; use MoonShine\UI\Fields\Textarea; use MoonShine\UI\Fields\Select; use MoonShine\UI\Fields\Color; use MoonShine\UI\Fields\Image; YandexMap::make('Местоположение', 'location') ->coordinates([55.751574, 37.573856]) ->zoom(12) ->mapHeight('400px') ->indexDisplayFields(['address', 'phone', 'email']) ->indexShowAddressCopy(true) ->balloonContent([ 'title' => 'model.name', 'address' => 'model.address', 'phone' => 'model.phone', ]) ->placemarkProperties([ 'hintContent' => 'Кликните для просмотра', 'iconCaption' => 'Филиал', ]) ->placemarkOptions([ 'preset' => Select::make('Тип иконки', 'icon_type') ->options([ 'islands#blueHomeIcon' => 'Дом', 'islands#redRestaurantIcon' => 'Ресторан', ]) ->default('islands#blueHomeIcon'), 'iconColor' => Color::make('Цвет', 'icon_color')->default('#3B82F6'), 'iconImageHref' => Image::make('Кастомная иконка', 'iconImageHref') ->dir('icons') ->allowedExtensions(['png', 'svg', 'webp']), 'draggable' => true, ]) ->customBalloonFields([ Text::make('Заголовок балуна', 'title')->default('Объект'), Textarea::make('Описание', 'description'), ]);
Данные сохраняются в JSON: lat, lng, coordinates, balloon_data, placemark_options, placemark_properties.
YandexMapPolygon — полигоны
use MoonShine\YandexMaps\Fields\YandexMapPolygon; YandexMapPolygon::make('Зоны доставки', 'delivery_zones') ->mapHeight('300px') ->allowMultiplePolygons() ->allowEditExisting() ->allowImportExport() ->defaultPolygonColor('#3B82F6') ->defaultPolygonOpacity(0.3) ->polygonColors(['#3B82F6', '#10B981', '#F59E0B', '#EF4444']) ->showMiniMapOnIndex();
Подключение assets для Layout
Для копирования адреса по клику и корректной отправки длинных данных полигонов добавьте трейт в ваш Layout:
namespace App\MoonShine\Layouts; use MoonShine\YandexMaps\Traits\WithYandexMapsAssets; use MoonShine\Laravel\Layouts\AppLayout; class MoonShineLayout extends AppLayout { use WithYandexMapsAssets; protected function assets(): array { return [ ...parent::assets(), ...$this->getYandexMapsAssets(), ]; } }
Структура данных
YandexMap (location)
{
"lat": 55.751574,
"lng": 37.573856,
"coordinates": [55.751574, 37.573856],
"balloon_data": { "title": "...", "description": "..." },
"placemark_options": { "preset": "...", "iconImageHref": "..." },
"placemark_properties": { "hintContent": "...", "iconCaption": "..." }
}
YandexMapPolygon (GeoJSON-like)
[
{
"type": "Polygon",
"coordinates": [[[lng, lat], [lng, lat], ...]],
"style": { "fillColor": "#3B82F6", "strokeColor": "#1D4ED8" },
"data": { "name": "Зона 1" }
}
]
Миграции
Для хранения:
$table->json('location')->nullable(); $table->json('delivery_zones')->nullable();
Лицензия
MIT



