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 18declare(strict_types=1); 19 20namespace Fisharebest\Webtrees\Module; 21 22use Fisharebest\Webtrees\FlashMessages; 23use Fisharebest\Webtrees\I18N; 24use Psr\Http\Message\ResponseInterface; 25use Psr\Http\Message\ServerRequestInterface; 26 27use function redirect; 28 29/** 30 * Class OpenStreetMap - use maps within webtrees 31 */ 32class OpenStreetMap extends AbstractModule implements ModuleConfigInterface, ModuleMapProviderInterface 33{ 34 use ModuleConfigTrait; 35 use ModuleMapProviderTrait; 36 37 /** 38 * Name of the map provider. 39 * 40 * @return string 41 */ 42 public function description(): string 43 { 44 $link = '<a href="https://www.openstreetmap.org" dir="ltr">www.openstreetmap.org</a>'; 45 46 // I18N: %s is a link/URL 47 return I18N::translate('Create maps using %s.', $link); 48 } 49 50 /** 51 * Name of the map provider. 52 * 53 * @return string 54 */ 55 public function title(): string 56 { 57 return I18N::translate('OpenStreetMap™'); 58 } 59 60 /** 61 * @return ResponseInterface 62 */ 63 public function getAdminAction(): ResponseInterface 64 { 65 $this->layout = 'layouts/administration'; 66 67 return $this->viewResponse('modules/openstreetmap/config', [ 68 'title' => $this->title(), 69 ]); 70 } 71 72 /** 73 * @param ServerRequestInterface $request 74 * 75 * @return ResponseInterface 76 */ 77 public function postAdminAction(ServerRequestInterface $request): ResponseInterface 78 { 79 $params = (array) $request->getParsedBody(); 80 81 FlashMessages::addMessage(I18N::translate('The preferences for the module “%s” have been updated.', $this->title()), 'success'); 82 83 return redirect($this->getConfigLink()); 84 } 85 86 /** 87 * Parameters to create a TileLayer in LeafletJs. 88 * 89 * @return array<object> 90 */ 91 public function leafletJsTileLayers(): array 92 { 93 return [ 94 (object) [ 95 'attribution' => 'Map data ©<a href="https://www.openstreetmap.org">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0">CC-BY-SA</a>', 96 'default' => true, 97 'label' => 'Mapnik', 98 'maxZoom' => 19, 99 'minZoom' => 2, 100 'subdomains' => ['a', 'b', 'c'], 101 'url' => 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', 102 ], 103 (object) [ 104 'attribution' => 'Map data ©<a href="https://www.openstreetmap.org">Karte hergestellt aus OpenStreetMap-Daten</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0">CC-BY-SA</a>', 105 'default' => false, 106 'label' => 'Deutsch', 107 'maxZoom' => 18, 108 'minZoom' => 2, 109 'subdomains' => ['a', 'b', 'c'], 110 'url' => 'https://{s}.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png', 111 ], 112 (object) [ 113 'attribution' => 'Map data ©<a href="https://www.openstreetmap.org">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0">CC-BY-SA</a>', 114 'default' => false, 115 'label' => 'Français', 116 'maxZoom' => 20, 117 'minZoom' => 2, 118 'subdomains' => ['a', 'b', 'c'], 119 'url' => 'https://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png', 120 ], 121 ]; 122 } 123} 124