2014-12-29 12:17:40 +01:00
|
|
|
<?php
|
|
|
|
|
|
2015-01-12 19:03:29 +01:00
|
|
|
/**
|
|
|
|
|
* @package dev
|
|
|
|
|
* @author David Molineus <david.molineus@netzmacht.de>
|
|
|
|
|
* @copyright 2014 netzmacht creative David Molineus
|
|
|
|
|
* @license LGPL 3.0
|
|
|
|
|
* @filesource
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2014-12-29 12:17:40 +01:00
|
|
|
use Netzmacht\Contao\Leaflet\Boot;
|
|
|
|
|
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
|
|
|
|
use Netzmacht\Contao\Leaflet\MapService;
|
2015-01-16 15:01:48 +01:00
|
|
|
use Netzmacht\JavascriptBuilder\Builder;
|
|
|
|
|
use Netzmacht\JavascriptBuilder\Encoder;
|
|
|
|
|
use Netzmacht\JavascriptBuilder\Encoder\JavascriptEncoder;
|
|
|
|
|
use Netzmacht\JavascriptBuilder\Encoder\ResultCacheEncoder;
|
|
|
|
|
use Netzmacht\JavascriptBuilder\Output;
|
|
|
|
|
use Netzmacht\JavascriptBuilder\Symfony\EventDispatchingEncoder;
|
2014-12-29 12:17:40 +01:00
|
|
|
use Netzmacht\LeafletPHP\Leaflet;
|
|
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher;
|
|
|
|
|
|
|
|
|
|
/** @var \Pimple $container */
|
|
|
|
|
global $container;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Leaflet map service is a simply api entry to to get the leaflet map from the database.
|
|
|
|
|
*/
|
|
|
|
|
$container['leaflet.map.service'] = $container->share(function ($container) {
|
|
|
|
|
return new MapService(
|
|
|
|
|
$container['leaflet.definition.mapper'],
|
|
|
|
|
$container['leaflet.definition.builder'],
|
|
|
|
|
$container['event-dispatcher']
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The leaflet boot.
|
|
|
|
|
*/
|
|
|
|
|
$container['leaflet.boot'] = $container->share(function ($container) {
|
|
|
|
|
return new Boot($container['event-dispatcher']);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The definition mapper.
|
|
|
|
|
*/
|
|
|
|
|
$container['leaflet.definition.mapper'] = $container->share(function ($container) {
|
|
|
|
|
/** @var Boot $boot */
|
|
|
|
|
$boot = $container['leaflet.boot'];
|
|
|
|
|
$mapper = new DefinitionMapper($container['event-dispatcher']);
|
|
|
|
|
|
|
|
|
|
return $boot->initializeDefinitionMapper($mapper);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The local event dispatcher is used for the leaflet javascript encoding system.
|
|
|
|
|
*/
|
|
|
|
|
$container['leaflet.definition.builder.event-dispatcher'] = $container->share(function ($container) {
|
|
|
|
|
/** @var Boot $boot */
|
|
|
|
|
$boot = $container['leaflet.boot'];
|
|
|
|
|
$dispatcher = new EventDispatcher();
|
|
|
|
|
|
|
|
|
|
return $boot->initializeEventDispatcher($dispatcher);
|
|
|
|
|
});
|
|
|
|
|
|
2015-01-16 15:01:48 +01:00
|
|
|
/*
|
|
|
|
|
* The javascript encoder factory being used for building the map javascript.
|
|
|
|
|
*/
|
|
|
|
|
$container['leaflet.definition.builder.encoder-factory'] = function ($container) {
|
|
|
|
|
$dispatcher = $container['leaflet.definition.builder.event-dispatcher'];
|
|
|
|
|
|
|
|
|
|
return function (Output $output) use ($dispatcher) {
|
|
|
|
|
return new ResultCacheEncoder(
|
|
|
|
|
new EventDispatchingEncoder(
|
|
|
|
|
new JavascriptEncoder($output, JSON_UNESCAPED_SLASHES),
|
|
|
|
|
$dispatcher
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
};
|
2014-12-29 12:17:40 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The leaflet builder transforms the definition to javascript.
|
|
|
|
|
*/
|
|
|
|
|
$container['leaflet.definition.builder'] = $container->share(function($container) {
|
|
|
|
|
/** @var Boot $boot */
|
|
|
|
|
$boot = $container['leaflet.boot'];
|
|
|
|
|
$dispatcher = $container['leaflet.definition.builder.event-dispatcher'];
|
2015-01-16 15:01:48 +01:00
|
|
|
$factory = $container['leaflet.definition.builder.encoder-factory'];
|
2014-12-29 12:17:40 +01:00
|
|
|
|
2015-01-16 15:01:48 +01:00
|
|
|
$builder = new Builder($factory);
|
|
|
|
|
$leaflet = new Leaflet($builder, $dispatcher, array(), JSON_UNESCAPED_SLASHES);
|
2014-12-29 12:17:40 +01:00
|
|
|
|
|
|
|
|
return $boot->initializeLeafletBuilder($leaflet);
|
|
|
|
|
});
|