. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Services; use Fisharebest\Webtrees\I18N; use Fisharebest\Webtrees\Module\ModuleMapProviderInterface; /** * Generate the configuration data needed to create a LeafletJs map. */ class LeafletJsService { private ModuleService $module_service; /** * LeafletJsService constructor. * * @param ModuleService $module_service */ public function __construct(ModuleService $module_service) { $this->module_service = $module_service; } /** * @return object */ public function config(): object { $default = 'openstreetmap'; $map_providers = $this->module_service ->findByInterface(ModuleMapProviderInterface::class) ->map(static function (ModuleMapProviderInterface $map_provider) use ($default): object { return (object) [ 'children' => $map_provider->leafletJsTileLayers(), 'collapsed' => true, 'default' => $map_provider->name() === $default, 'label' => $map_provider->title(), ]; }) ->values(); return (object) [ 'i18n' => [ 'reset' => I18N::translate('Reload map'), 'zoomIn' => I18N::translate('Zoom in'), 'zoomOut' => I18N::translate('Zoom out'), ], 'icons' => [ 'collapse' => view('icons/collapse'), 'expand' => view('icons/expand'), ], 'mapProviders' => $map_providers, ]; } }