lbcdev/livewire-maps-core 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lbcdev/livewire-maps-core

Composer 安装命令:

composer require lbcdev/livewire-maps-core

包简介

A Livewire component for interactive maps using Leaflet

README 文档

README

Tests Latest Stable Version Total Downloads License

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

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:

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 lbcdev/livewire-maps-core 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 37
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-16