PHP code example of 2amigos / yii2-leaflet-markercluster-plugin

1. Go to this page and download the library: Download 2amigos/yii2-leaflet-markercluster-plugin library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

2amigos / yii2-leaflet-markercluster-plugin example snippets


// LeafLet initialization component
// ...

// create cluster plugin
$cluster = new dosamigos\leaflet\plugins\markercluster\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']]);


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"],

        ]
    ]);
}