PHP code example of boriskorobkov / yii2-leaflet-extension
1. Go to this page and download the library: Download boriskorobkov/yii2-leaflet-extension 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/ */
boriskorobkov / yii2-leaflet-extension example snippets
// 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();