LeafLet MarkerCluster Plugin

What is LeafLet Marker Cluster Plugin?

Yii 2 LeafletJs Plugin to provide beautiful, sophisticated, high performance marker clustering solution with smooth animations and lots of great features. This Plugin works in conjunction with LeafLet library for Yii 2 framework.

Installation

The preferred way to install this extension is through composer.

Either run

composer require 2amigos/yii2-leaflet-markercluster-plugin:~1.0

or add the following to the require section of your application's composer.json file:

"2amigos/yii2-leaflet-markercluster-plugin" : "~1.0"

Usage example

Using an external json url source:

use dosamigos\leaflet\plugins\markercluster\MarkerCluster;
// LeafLet initialization component
// ...

// create cluster plugin
$cluster = new MarkerCluster([
     'jsonUrl' =>  Yii::$app->controller->createUrl('site/json')
]);

// install to LeafLet component
$leafLet->plugins->install($cluster);

// done render widget
echo $leafLet->widget(['options' => ['style' => 'height: 400px']]);

The example action returning the markers:

public function actionJson()
{
    Yii::$app->getResponse()->format = Response::FORMAT_JSON;
    echo json_encode([
        "markers" =>  [
            ["lat"=>-37.8210922667, "lng"=>175.2209316333, "popup" => "2"],
            ["lat"=>-37.8210819833, "lng"=>175.2213903167, "popup" => "3"],

        ]
    ]);
}

Share this

Contributors Thanks All

 

Do you have a good idea? Why Don't We Talk?