lbcdev/livewire-maps-core
Composer 安装命令:
composer require lbcdev/livewire-maps-core
包简介
A Livewire component for interactive maps using Leaflet
README 文档
README
A Livewire component for interactive maps with Leaflet.js integration. Core package for the LBCDev Maps Suite.
Features
- 🗺️ Interactive Maps: Full Leaflet.js integration via Alpine.js
- 🎯 Single & Multi Marker: Support for single markers or marker collections
- 🔄 Reactive Updates: Real-time map updates with Livewire
- 📍 Coordinate Validation: Built-in validation for latitude/longitude
- ⚡ Events System: Emit and listen to map events
- 🎨 Customizable: Extensive configuration options
- ✅ Well Tested: 13 comprehensive tests
- 📚 Fully Documented: Complete API documentation
Requirements
- PHP 8.1 or higher
- Laravel 10.x or 11.x
- Livewire 3.x
- lbcdev/map-geometries
Installation
composer require lbcdev/livewire-maps-core
Publish the configuration file:
php artisan vendor:publish --tag="livewire-maps-config"
Quick Start
Basic Usage
@livewire('livewire-map', [ 'center' => ['lat' => 40.7128, 'lng' => -74.0060], 'zoom' => 13 ])
With Single Marker
use LBCDev\MapGeometries\Marker; $marker = Marker::make(40.7128, -74.0060, 'New York City') ->tooltip('The Big Apple') ->iconColor('blue');
@livewire('livewire-map', [ 'marker' => $marker, 'center' => ['lat' => 40.7128, 'lng' => -74.0060], 'zoom' => 13 ])
With Multiple Markers
use LBCDev\MapGeometries\Marker; use LBCDev\MapGeometries\MarkerCollection; $markers = new MarkerCollection(); $markers->add( Marker::make(40.7128, -74.0060, 'New York') ->iconColor('blue') ); $markers->add( Marker::make(51.5074, -0.1278, 'London') ->iconColor('red') );
@livewire('livewire-map', [ 'markers' => $markers, 'center' => ['lat' => 40.7128, 'lng' => -74.0060], 'zoom' => 3 ])
Configuration
The package comes with sensible defaults, but you can customize everything:
// config/livewire-maps.php return [ 'default_center' => [ 'lat' => env('LIVEWIRE_MAPS_DEFAULT_LAT', 0), 'lng' => env('LIVEWIRE_MAPS_DEFAULT_LNG', 0), ], 'default_zoom' => env('LIVEWIRE_MAPS_DEFAULT_ZOOM', 10), 'tile_layer' => [ 'url' => 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', 'attribution' => '© OpenStreetMap contributors', ], 'default_options' => [ 'scrollWheelZoom' => true, 'dragging' => true, 'zoomControl' => true, ], ];
Component API
Properties
| Property | Type | Default | Description |
|---|---|---|---|
$marker |
Marker|null |
null |
Single marker to display |
$markers |
MarkerCollection|null |
null |
Collection of markers |
$center |
array |
config | Map center ['lat' => X, 'lng' => Y] |
$zoom |
int |
config | Initial zoom level |
$height |
string |
'500px' |
Map container height |
$interactive |
bool |
true |
Enable/disable interactions |
$options |
array |
config | Leaflet map options |
Methods
| Method | Parameters | Description |
|---|---|---|
addMarker() |
Marker $marker |
Add a marker to the map |
removeMarker() |
string $id |
Remove a marker by ID |
clearMarkers() |
- | Remove all markers |
flyTo() |
float $lat, float $lng, int $zoom |
Center map with animation |
Computed Properties
| Property | Type | Description |
|---|---|---|
markersData |
array |
Get all markers as array |
hasCoordinates |
bool |
Check if valid coordinates |
Events
Emitted Events
// Coordinates updated $this->dispatch('map-coordinates-updated', [ 'lat' => 40.7128, 'lng' => -74.0060 ]);
Listening to Events
protected $listeners = [ 'fly-to-coordinates' => 'flyTo', ]; public function flyTo(array $data) { // $data = ['lat' => X, 'lng' => Y, 'zoom' => Z] }
Advanced Usage
Custom Map Options
@livewire('livewire-map', [ 'center' => ['lat' => 40.7128, 'lng' => -74.0060], 'zoom' => 13, 'options' => [ 'scrollWheelZoom' => false, 'minZoom' => 10, 'maxZoom' => 18, 'maxBounds' => [ [40.5, -74.5], [40.9, -73.5] ], ] ])
Read-Only Mode
@livewire('livewire-map', [ 'marker' => $marker, 'interactive' => false ])
Custom Height
@livewire('livewire-map', [ 'center' => ['lat' => 40.7128, 'lng' => -74.0060], 'height' => '700px' ])
Legacy Mode (Separate lat/lng)
For backward compatibility:
@livewire('livewire-map', [ 'latitude' => 40.7128, 'longitude' => -74.0060 ])
Using in Livewire Components
use Livewire\Component; use LBCDev\MapGeometries\Marker; use LBCDev\MapGeometries\MarkerCollection; class LocationPicker extends Component { public ?Marker $selectedLocation = null; public MarkerCollection $locations; protected $listeners = [ 'map-coordinates-updated' => 'handleLocationSelected' ]; public function mount() { $this->locations = new MarkerCollection(); // Add some locations $this->locations->add( Marker::make(40.7128, -74.0060, 'New York') ); } public function handleLocationSelected($data) { $this->selectedLocation = Marker::make( $data['lat'], $data['lng'], 'Selected Location' ); } public function render() { return view('livewire.location-picker'); } }
Testing
composer test
With coverage:
composer test-coverage
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email luinux81@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Related Packages
This package is part of the LBCDev Maps Suite:
- map-geometries - Map geometry classes (Marker, Polyline, etc.)
- filament-maps-fields - Map form fields for Filament
- filament-maps-widgets - Map widgets for Filament panels
- lbcdev-filament-maps-suite - Meta-package for all components
lbcdev/livewire-maps-core 适用场景与选型建议
lbcdev/livewire-maps-core 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「map」 「component」 「laravel」 「leaflet」 「livewire」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lbcdev/livewire-maps-core 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lbcdev/livewire-maps-core 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lbcdev/livewire-maps-core 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Maps in minutes. Powered by the Google Maps API.
FSi DataSource Component
Yii2 map input widget. Allows you to select geographcal coordinates via a human-friendly inteface.
Priveate for SkeekS CMS
The enumeration type for PHP
Yandex map
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 37
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-16