PHPackages                             netzmacht/php-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. netzmacht/php-leaflet

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

netzmacht/php-leaflet
=====================

PHP leaflet definition and javascript generator

1.1.3(3y ago)1927.2k—8.3%10[1 PRs](https://github.com/netzmacht/php-leaflet/pulls)2LGPL-3.0-or-laterPHPPHP ^7.1 || ^8.0

Since Jan 28Pushed 3y ago4 watchersCompare

[ Source](https://github.com/netzmacht/php-leaflet)[ Packagist](https://packagist.org/packages/netzmacht/php-leaflet)[ GitHub Sponsors](https://github.com/dmolineus)[ RSS](/packages/netzmacht-php-leaflet/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (14)Used By (2)

PHP Leaflet library
===================

[](#php-leaflet-library)

[![Build Status](https://camo.githubusercontent.com/cced61858024762c8911c503012323d342758e949aed456bf91537d65794f81d/687474703a2f2f696d672e736869656c64732e696f2f7472617669732f6e65747a6d616368742f7068702d6c6561666c65742f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/netzmacht/php-leaflet)[![Version](https://camo.githubusercontent.com/8ba5c61fe09446c58b409d4877a6eccf5d3085c81467249d4d36784b0263c16a/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e65747a6d616368742f7068702d6c6561666c65742e7376673f7374796c653d666c61742d737175617265)](http://packagist.org/packages/netzmacht/php-leaflet)[![License](https://camo.githubusercontent.com/dd857e7717de43586c800221cbce6c3e00b618ca02417d098a623d6ea7f01f9f/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6e65747a6d616368742f7068702d6c6561666c65742e7376673f7374796c653d666c61742d737175617265)](http://packagist.org/packages/netzmacht/php-leaflet)[![Downloads](https://camo.githubusercontent.com/2c1f7fd897cb703b5eb5b6b9d9c03b31ba3723bce79c7bb393d14605bea4630d/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e65747a6d616368742f7068702d6c6561666c65742e7376673f7374796c653d666c61742d737175617265)](http://packagist.org/packages/netzmacht/php-leaflet)[![Contao Community Alliance coding standard](https://camo.githubusercontent.com/5c83beb382413cbfa523bbea12d70d0723a803b3f7cbba029609ed1848dfa99b/687474703a2f2f696d672e736869656c64732e696f2f62616467652f6363612d636f64696e675f7374616e646172642d7265642e7376673f7374796c653d666c61742d737175617265)](https://github.com/contao-community-alliance/coding-standard)

This library provides a PHP API to setup the Leaflet map definitions. The goal of the library is to provide a handy way to handle dynamic map configurations working in a PHP context.

Install
-------

[](#install)

You can install the library using composer:

```
$ php composer.phar require netzmacht/php-leaflet

```

Features
--------

[](#features)

This library provides different components:

- Definition classes to define the leaflet map with all layers, controls and so on.
- Value classes which have real behaviour and can be used to handle LatLng or GeoJSON features.
- The Encoder component to convert the PHP leaflet definition into javascript.
- Support for several Leaflet plugins.
- Assets handling to autoload all required javascripts and css files from all plugins.

Before you start
----------------

[](#before-you-start)

- The definition classes has some mixed behaviours. There useful behaviour is implemented. Some method creates just javascript method calls.
- The goal is to have a close reflection of the Javascript API. Since the languages differs there are some changes which you should be aware of.

Requirements
------------

[](#requirements)

This library requires PHP 5.6 and the symfony event dispatcher. The event dispatcher is used by the [php-javascript-builder](https://github.com/netzmacht/php-javascript-builder) which encodes the PHP definition.

Example
-------

[](#example)

```
/*
 * 1. Setup the encoder
 */

// The event dispatcher
$dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();

// All encoders are event subscribers.
$dispatcher->addSubscriber(new Netzmacht\LeafletPHP\Encoder\ControlEncoder());
$dispatcher->addSubscriber(new Netzmacht\LeafletPHP\Encoder\GroupEncoder());
$dispatcher->addSubscriber(new Netzmacht\LeafletPHP\Encoder\MapEncoder());
$dispatcher->addSubscriber(new Netzmacht\LeafletPHP\Encoder\RasterEncoder());
$dispatcher->addSubscriber(new Netzmacht\LeafletPHP\Encoder\TypeEncoder());
$dispatcher->addSubscriber(new Netzmacht\LeafletPHP\Encoder\UIEncoder());
$dispatcher->addSubscriber(new Netzmacht\LeafletPHP\Encoder\VectorEncoder());

// Create a custom factory for the javascript builder which uses the event dispatcher.
// The order of the registered encoders are important! Only change if you know what you do.
$factory = function(Output $output) use ($dispatcher) {
    $encoder = new ChainEncoder();

    $encoder
        ->register(new \Netzmacht\JavascriptBuilder\Encoder\MultipleObjectsEncoder())
        ->register(new \Netzmacht\JavascriptBuilder\Symfony\EventDispatchingEncoder($dispatcher))
        ->register(new \Netzmacht\JavascriptBuilder\Encoder\JavascriptEncoder($output));

    return $encoder;
};

$builder = new \Netzmacht\JavascriptBuilder\Builder($factory);
$leaflet = new \Netzmacht\LeafletPHP\leaflet($builder, $dispatcher);

/*
 * 2. Create the map definitions
 */
$map = new \Netzmacht\LeafletPHP\Definition\Map('html_id', 'map');
$map
  ->setZoom(12)
  ->addControl(...)
  ->addLayer(...);

/*
 * 3. Build the javascript
 */

// Will return javascript with following local vars: "map", "layers", "controls", "icons".
echo $leaflet->build($map);
```

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity38

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity75

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

Every ~258 days

Recently: every ~410 days

Total

10

Last Release

1184d ago

PHP version history (4 changes)1.0.0-beta1PHP ~5.4

1.0.0PHP &gt;=5.4

1.1.0PHP &gt;=5.6

1.1.1PHP ^7.1 || ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8189209?v=4)[netzmacht](/maintainers/netzmacht)[@netzmacht](https://github.com/netzmacht)

---

Top Contributors

[![dmolineus](https://avatars.githubusercontent.com/u/1186266?v=4)](https://github.com/dmolineus "dmolineus (212 commits)")

---

Tags

javascriptlibrarymapsleaflet

### Embed Badge

![Health badge](/badges/netzmacht-php-leaflet/health.svg)

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

###  Alternatives

[desandro/masonry

Cascading grid layout library

16.7k424.4k1](/packages/desandro-masonry)[desandro/imagesloaded

JavaScript is all like \_You images done yet or what?\_

8.9k439.0k1](/packages/desandro-imagesloaded)[mediawiki/maps

Adds various mapping features to MediaWiki

84145.0k3](/packages/mediawiki-maps)[fedemotta/yii2-widget-datatables

DataTables widget for Yii2

34179.4k1](/packages/fedemotta-yii2-widget-datatables)[netzmacht/contao-leaflet-maps

Contao Leaflet maps integration

1111.0k1](/packages/netzmacht-contao-leaflet-maps)

PHPackages © 2026

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