1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* webtrees: online genealogy |
5
|
|
|
* Copyright (C) 2021 webtrees development team |
6
|
|
|
* This program is free software: you can redistribute it and/or modify |
7
|
|
|
* it under the terms of the GNU General Public License as published by |
8
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
9
|
|
|
* (at your option) any later version. |
10
|
|
|
* This program is distributed in the hope that it will be useful, |
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13
|
|
|
* GNU General Public License for more details. |
14
|
|
|
* You should have received a copy of the GNU General Public License |
15
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
declare(strict_types=1); |
19
|
|
|
|
20
|
|
|
namespace Fisharebest\Webtrees\Services; |
21
|
|
|
|
22
|
|
|
use Fisharebest\Webtrees\I18N; |
23
|
|
|
use Fisharebest\Webtrees\Module\ModuleMapProviderInterface; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Generate the configuration data needed to create a LeafletJs map. |
27
|
|
|
*/ |
28
|
|
|
class LeafletJsService |
29
|
|
|
{ |
30
|
|
|
private ModuleService $module_service; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* LeafletJsService constructor. |
34
|
|
|
* |
35
|
|
|
* @param ModuleService $module_service |
36
|
|
|
*/ |
37
|
|
|
public function __construct(ModuleService $module_service) |
38
|
|
|
{ |
39
|
|
|
$this->module_service = $module_service; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return object |
44
|
|
|
*/ |
45
|
|
|
public function config(): object |
46
|
|
|
{ |
47
|
|
|
$default = 'openstreetmap'; |
48
|
|
|
|
49
|
|
|
$map_providers = $this->module_service |
50
|
|
|
->findByInterface(ModuleMapProviderInterface::class) |
51
|
|
|
->map(static function (ModuleMapProviderInterface $map_provider) use ($default): object { |
52
|
|
|
return (object) [ |
53
|
|
|
'children' => $map_provider->leafletJsTileLayers(), |
54
|
|
|
'collapsed' => true, |
55
|
|
|
'default' => $map_provider->name() === $default, |
56
|
|
|
'label' => $map_provider->title(), |
57
|
|
|
]; |
58
|
|
|
}) |
59
|
|
|
->values(); |
60
|
|
|
|
61
|
|
|
return (object) [ |
62
|
|
|
'i18n' => [ |
63
|
|
|
'reset' => I18N::translate('Reload map'), |
64
|
|
|
'zoomIn' => I18N::translate('Zoom in'), |
65
|
|
|
'zoomOut' => I18N::translate('Zoom out'), |
66
|
|
|
], |
67
|
|
|
'icons' => [ |
68
|
|
|
'collapse' => view('icons/collapse'), |
69
|
|
|
'expand' => view('icons/expand'), |
70
|
|
|
], |
71
|
|
|
'mapProviders' => $map_providers, |
72
|
|
|
]; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|