boriskorobkov / yii2-leaflet-extension
LeafLet Mobile-Friendly Interactive Maps Extension Library for Yii2.
Installs: 3
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 27
Type:yii2-extension
pkg:composer/boriskorobkov/yii2-leaflet-extension
Requires
- php: ^8.1
- npm-asset/leaflet: ^1.9
- yiisoft/yii2: ^2.0.52
Requires (Dev)
- phpunit/phpunit: ^10.5
Replaces
This package is auto-updated.
Last update: 2026-01-03 19:04:20 UTC
README
Extension library to display interactive maps with LeafletJs
Installation
The preferred way to install this extension is through
composer. This requires the
composer-asset-plugin,
which is also a dependency for yii2 – so if you have yii2 installed, you are
most likely already set.
Either run
composer require boriskorobkov/yii2-leaflet-extension:^2.0.0
or add
"boriskorobkov/yii2-leaflet-extension" : "^2.0.0"
to the require section of your application's composer.json file.
Migration from 1.x to 2.x
- Replace namespace
dosamigos/yii2-leaflet-extensionwithboriskorobkov/yii2-leaflet-extensionin your code - If you use a custom widget, check the correct usage of the
;symbol
Usage
One of the things to take into account when working with LeafletJs is that we need a Tile Provider. Is very important, if we fail to provide a Tile Provider Url, the map will display plain, without any maps at all.
The following example, is making use of MapQuest:
// first lets setup the center of our map $center = new boriskorobkov\leaflet\types\LatLng(['lat' => 51.508, 'lng' => -0.11]); // now lets create a marker that we are going to place on our map $marker = new \boriskorobkov\leaflet\layers\Marker(['latLng' => $center, 'popupContent' => 'Hi!']); // The Tile Layer (very important) $tileLayer = new \boriskorobkov\leaflet\layers\TileLayer([ 'urlTemplate' => 'https://otile{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpeg', 'clientOptions' => [ 'attribution' => 'Tiles Courtesy of <a href="https://www.mapquest.com/" target="_blank">MapQuest</a> ' . '<img src="https://developer.mapquest.com/content/osm/mq_logo.png">, ' . 'Map data © <a href="https://openstreetmap.org">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>', 'subdomains' => ['1', '2', '3', '4'], ], ]); // now our component and we are going to configure it $leaflet = new \boriskorobkov\leaflet\LeafLet([ 'center' => $center, // set the center ]); // Different layers can be added to our map using the `addLayer` function. $leaflet->addLayer($marker) // add the marker ->addLayer($tileLayer); // add the tile layer // finally render the widget echo \boriskorobkov\leaflet\widgets\Map::widget(['leafLet' => $leaflet]); // we could also do // echo $leaflet->widget();
Testing
To test the extension, is better to clone this repository on your computer. After, go to the extensions folder and do
the following (assuming you have composer installed on your computer):
$ composer install --no-interaction --prefer-source --dev
Once all required libraries are installed then do:
$ vendor/bin/phpunit
Further Information
For further information regarding the multiple settings of LeafLetJS library please visit its API reference
Contributing
Please see CONTRIBUTING for details.
Credits
License
The BSD License (BSD). Please see License File for more information.
Web development has never been so fun!
www.2amigos.us