1. Go to this page and download the library: Download netzmacht/php-leaflet 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/ */
netzmacht / php-leaflet example snippets
/*
* 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);
$ php composer.phar
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.