Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Livewire Map Component Laravel Package

lbcdev/livewire-map-component

Componente Livewire para integrar mapas Leaflet.js en Laravel: marcador arrastrable, click para ubicar, entrada manual de coordenadas, modo claro/oscuro, opción solo lectura y eventos Livewire. Soporta coords iniciales, zoom y altura configurables.

View on GitHub
Deep Wiki
Context7

Getting Started

First Steps

  1. Installation:

    composer require lbcdev/livewire-map-component
    

    Add Leaflet CSS/JS to your layout's <head> (before @livewireStyles):

    <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
    <script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
    
  2. First Component:

    <livewire:lbcdev-map latitude="40.7128" longitude="-74.0060" />
    

    Verify the map renders at NYC coordinates.

  3. Key Props:

    • :latitude, :longitude (required)
    • :zoom (default: 13)
    • :readOnly (default: false)

First Use Case

Display a draggable marker:

<livewire:lbcdev-map
    latitude="40.7128"
    longitude="-74.0060"
    :markers="['40.7128,-74.0060']"
    marker-draggable="true"
/>

Implementation Patterns

Core Workflows

  1. Dynamic Marker Management:

    // In Livewire component
    public $markers = ['40.7128,-74.0060', '34.0522,-118.2437'];
    
    public function addMarker($lat, $lng) {
        $this->markers[] = "$lat,$lng";
    }
    
    <livewire:lbcdev-map
        :markers="$markers"
        @marker-added="addMarker"
    />
    
  2. Event-Driven Integration:

    • Map Click: @map-clicked="handleMapClick($event)"
    • Marker Drag: @marker-dragged="updateMarker($event)"
    public function handleMapClick($event) {
        $this->addMarker($event['lat'], $event['lng']);
    }
    
  3. Theme Switching:

    <livewire:lbcdev-map
        :darkMode="app()->isDarkModeEnabled()"
    />
    

Integration Tips

  • Form Submission: Bind marker data to a model:

    public $location;
    public function updatedMarkers() {
        $this->location = implode(',', $this->markers);
    }
    
    <input wire:model="location" type="hidden">
    
  • Custom Styling: Publish views (php artisan vendor:publish --tag=lbcdev-map-views) and override:

    @push('leaflet-styles')
        .leaflet-container { border-radius: 8px; }
    @endpush
    
  • Server-Side Validation:

    protected $rules = [
        'markers' => 'required|array',
        'markers.*' => 'regex:/^\d+\.\d+,\s*-\d+\.\d+$/'
    ];
    

Gotchas and Tips

Common Pitfalls

  1. Missing Leaflet Dependencies:

    • Symptom: Blank map or JS errors.
    • Fix: Ensure Leaflet CSS/JS are loaded before @livewireStyles.
  2. Marker Coordinates Format:

    • Issue: markers prop expects strings like "40.7128,-74.0060" (not arrays/objects).
    • Fix: Use implode(',', [$lat, $lng]) when passing PHP arrays.
  3. Event Payload Mismatch:

    • Problem: @marker-dragged emits {lat, lng, id}, but your handler expects {lat, lng}.
    • Solution: Update handler to destructure:
      public function updateMarker($event) {
          $this->markers[$event['id']] = "$event['lat'],$event['lng']";
      }
      
  4. Read-Only Mode Quirks:

    • Gotcha: Disables all interactions (clicks, drags). Use sparingly for forms.

Debugging Tips

  • Inspect Events:

    @this.on('marker-dragged', function(event) {
        console.log('Event:', event);
    })
    
  • Check Published Views: If customizations disappear after vendor:publish, clear cached views:

    php artisan view:clear
    

Extension Points

  1. Custom Layers: Override the mountMap method in your Livewire component:

    public function mountMap() {
        $this->map->addLayer(LbcdevMap::tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'));
    }
    
  2. Geocoding: Integrate with a service (e.g., Nominatim) via @map-clicked:

    public function handleMapClick($event) {
        $address = $this->geocode($event['lat'], $event['lng']);
        $this->address = $address;
    }
    
  3. Performance:

    • For >50 markers, use marker-cluster-group:
      public function mountMap() {
          $this->map->addLayer(LbcdevMap::markerClusterGroup($this->markers));
      }
      
    • Lazy-load markers via @map-view event.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
datacore/hub-sdk
alengo/sulu-http-cache-bundle
croct/coding-standard
croct/plug-php
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
imbo/imbo-coding-standard
visualbuilder/filament-lottie
servicioslineaonce/starter-kit
atomcoder/laravel-reorderable
irajul/filament-shadcn-theme
agtp/agtp-php
agtp/mod-php
centraldesktop/protobuf-php
trappistes/laravel-custom-fields