PHPackages                             beastbytes/yii2-leaflet - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. beastbytes/yii2-leaflet

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

beastbytes/yii2-leaflet
=======================

Yii2 extension to integrate the Leaflet JavaScript mapping library

V1.0.0(7y ago)0437[1 issues](https://github.com/beastbytes/yii2-leaflet/issues)BSD-3-ClauseJavaScript

Since Nov 18Pushed 7y ago1 watchersCompare

[ Source](https://github.com/beastbytes/yii2-leaflet)[ Packagist](https://packagist.org/packages/beastbytes/yii2-leaflet)[ RSS](/packages/beastbytes-yii2-leaflet/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

BeastBytes\\Leaflet
===================

[](#beastbytesleaflet)

Yii2 extension to integrate the Leaflet JavaScript mapping library.

Features
--------

[](#features)

- For Leaflet V1.\*
- Easy to use predefined tile providers (port of [Leaflet Providers](/leaflet-extras/leaflet-providers))
- Simple popup creation for markers and vector components; just set the 'content' option
- Simple plugin interface

For license information see the [LICENSE](LICENSE.md)-file.

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist beastbytes/yii2-leaflet

```

or add

```
"beastbytes/yii2-leaflet": "*"
```

to the require section of your composer.json.

Usage
-----

[](#usage)

To create a map, first create the components, e.g. markers, controls, shapes, etc., to display on the map, then run the Map widget, adding the the components in its configuration.

The example below displays a map using OpenStreetMap as the tile provider. It has a marker in the centre of the map and a 5km raduis circle centred on the marker; these are in a layer group that is not initially displayed. When the layer is shown using the Layers control, the centre marker can be dragged and dropped and it's new position is shown - this demonstrates using component events. Three other markers are added in another layer group, and a layers and fullscreen control is added to the map; the fullscreen control is a plugin.

### Example

[](#example)

```
use BeastBytes\Leaflet\Map;

$centre = new LatLng([
    'lat' => 51.737022,
    'lng' => -4.931467
]);

$centreLayerGroup = new LayerGroup([ // Layer group with a marker and circle
    'layers' => [
        new Circle([
            'latLng' => $centre,
            'content' => 'This circle has a 5km raduis', // Setting 'content' creates a popup
            'options' => [
                'radius' => 5000
            ]
        ]),
        new Marker([
            'latLng' => $centre,
            'options' => [
                'draggable' => true,
                'icon' => new Icon([
                    'options' => [
                        'iconAnchor' => new Point(['x' => 12, 'y' => 40]), // This is important - it anchors a point in the image, measured in pixels from the top left of the image, to the geographical point given by latLng
                        'iconUrl' => "/images/leaflet/marker-icon-magenta.png", // replace with your own image URL
                        'shadowUrl' => '/images/leaflet/marker-shadow.png' // replace with your own image URL
                    ]
                ])
            ],
            'events' => [
                'dragend' => 'function(e){
                    var marker = e.target;
                    var position = marker.getLatLng();
                    window.alert("New position " + position.lat + " " + position.lng);
                }'
            ]
        ])
    ]
]);
$centreLayerGroup->map = false; // don't show initially

$icon = new Icon([
    'options' => [
        'iconAnchor' => new Point(['x' => 12, 'y' => 40]),
        'iconUrl' => "/images/leaflet/marker-icon-green.png",
        'shadowUrl' => '/images/leaflet/marker-shadow.png'
    ]
]);

$pubLayers = [];
$pubs = [
    [
        'name' => 'The Cottage Inn',
        'address' => 'Llangwm, Haverfordwest, Dyfed SA62 4HH',
        'tel' => '+44 1437 891494',
        'location' => ['lat' => 51.749558, 'lng' => -4.911994]
    ],
    [
        'name' => 'The Ferry Inn',
        'address' => 'Pembroke Ferry, Pembroke Dock, Pembrokeshire SA72 6UD',
        'tel' => '+44 1646 682947',
        'location' => ['lat' => 51.707498, 'lng' => -4.927023]
    ]
];

foreach ($pubs as $pub) {
    $pubLayers[] = new Marker([
        'latLng' => new LatLng($pub['location']),
        'options' => compact('icon'),
        'content' => ''.$pub['name'].''.$pub['address'].'Tel: '.$pub['tel'].''
    ]);
}

$pubsLayerGroup = new LayerGroup([ // group the public layers
    'layers' => $pubLayers
]);

$layersControl = new Layers([ // create a layers control to control layer visibility
    'overlays' => [
        'Centre of Map' => $centreLayerGroup,
        'Pubs' => $pubsLayerGroup
    ]
]);

echo Map::widget([
    'options' => [
        'id' => 'leaflet',
        'style' => 'height:800px' // a height must be specified
    ],
    'mapOptions' => [
        'center' => $centre,
        'layers' => [
            new TileProvider('OpenStreetMap') // this creates the tile layer
        ],
        'zoom' => 10
    ],
    'controls' => [
        $layersControl,
        new Scale()
    ],
    'layers' => [
        $centreLayerGroup,
        $pubsLayerGroup
    ],
    'plugins' => [
        new Fullscreen()
    ]
]);
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2738d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b0b5133b5137b26eeb25056449c28364ac0af31836eefba78912a9c8f0743aa3?d=identicon)[BeastBytes](/maintainers/BeastBytes)

---

Top Contributors

[![beastbytes](https://avatars.githubusercontent.com/u/1470144?v=4)](https://github.com/beastbytes "beastbytes (1 commits)")

---

Tags

mapmappingyii2widgetmapsleaflet

### Embed Badge

![Health badge](/badges/beastbytes-yii2-leaflet/health.svg)

```
[![Health](https://phpackages.com/badges/beastbytes-yii2-leaflet/health.svg)](https://phpackages.com/packages/beastbytes-yii2-leaflet)
```

###  Alternatives

[cornford/googlmapper

An easy way to integrate Google Maps with Laravel.

457447.9k4](/packages/cornford-googlmapper)[kolyunya/yii2-map-input-widget

Yii2 map input widget. Allows you to select geographcal coordinates via a human-friendly inteface.

2836.3k4](/packages/kolyunya-yii2-map-input-widget)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
