xref: /webtrees/app/Module/MapLinkOpenStreetMap.php (revision c9c6f2ec6e88594e58f14a6418e0de5aaa1484bd)
1*c9c6f2ecSGreg Roach<?php
2*c9c6f2ecSGreg Roach
3*c9c6f2ecSGreg Roach/**
4*c9c6f2ecSGreg Roach * webtrees: online genealogy
5*c9c6f2ecSGreg Roach * Copyright (C) 2021 webtrees development team
6*c9c6f2ecSGreg Roach * This program is free software: you can redistribute it and/or modify
7*c9c6f2ecSGreg Roach * it under the terms of the GNU General Public License as published by
8*c9c6f2ecSGreg Roach * the Free Software Foundation, either version 3 of the License, or
9*c9c6f2ecSGreg Roach * (at your option) any later version.
10*c9c6f2ecSGreg Roach * This program is distributed in the hope that it will be useful,
11*c9c6f2ecSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12*c9c6f2ecSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13*c9c6f2ecSGreg Roach * GNU General Public License for more details.
14*c9c6f2ecSGreg Roach * You should have received a copy of the GNU General Public License
15*c9c6f2ecSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
16*c9c6f2ecSGreg Roach */
17*c9c6f2ecSGreg Roach
18*c9c6f2ecSGreg Roachdeclare(strict_types=1);
19*c9c6f2ecSGreg Roach
20*c9c6f2ecSGreg Roachnamespace Fisharebest\Webtrees\Module;
21*c9c6f2ecSGreg Roach
22*c9c6f2ecSGreg Roachuse Fisharebest\Webtrees\I18N;
23*c9c6f2ecSGreg Roach
24*c9c6f2ecSGreg Roachuse function view;
25*c9c6f2ecSGreg Roach
26*c9c6f2ecSGreg Roach/**
27*c9c6f2ecSGreg Roach * Class MapLinkOpenStreetMap - show locations in external maps
28*c9c6f2ecSGreg Roach */
29*c9c6f2ecSGreg Roachclass MapLinkOpenStreetMap extends AbstractModule implements ModuleMapLinkInterface
30*c9c6f2ecSGreg Roach{
31*c9c6f2ecSGreg Roach    use ModuleMapLinkTrait;
32*c9c6f2ecSGreg Roach
33*c9c6f2ecSGreg Roach    /**
34*c9c6f2ecSGreg Roach     * Name of the map provider.
35*c9c6f2ecSGreg Roach     *
36*c9c6f2ecSGreg Roach     * @return string
37*c9c6f2ecSGreg Roach     */
38*c9c6f2ecSGreg Roach    protected function providerName(): string
39*c9c6f2ecSGreg Roach    {
40*c9c6f2ecSGreg Roach        return I18N::translate('OpenStreetMap™');
41*c9c6f2ecSGreg Roach    }
42*c9c6f2ecSGreg Roach
43*c9c6f2ecSGreg Roach    /**
44*c9c6f2ecSGreg Roach     * @return string
45*c9c6f2ecSGreg Roach     */
46*c9c6f2ecSGreg Roach    protected function icon(): string
47*c9c6f2ecSGreg Roach    {
48*c9c6f2ecSGreg Roach        return view('icons/openstreetmap');
49*c9c6f2ecSGreg Roach    }
50*c9c6f2ecSGreg Roach
51*c9c6f2ecSGreg Roach    /**
52*c9c6f2ecSGreg Roach     * @param \Fisharebest\Webtrees\Fact $fact
53*c9c6f2ecSGreg Roach     *
54*c9c6f2ecSGreg Roach     * @return string
55*c9c6f2ecSGreg Roach     */
56*c9c6f2ecSGreg Roach    protected function mapUrl(\Fisharebest\Webtrees\Fact $fact): string
57*c9c6f2ecSGreg Roach    {
58*c9c6f2ecSGreg Roach        $latitude  = $fact->latitude();
59*c9c6f2ecSGreg Roach        $longitude = $fact->longitude();
60*c9c6f2ecSGreg Roach
61*c9c6f2ecSGreg Roach        // mlat/mlon is the marker postion
62*c9c6f2ecSGreg Roach        return 'https://www.openstreetmap.org/?mlat=' . $latitude . '&mlon=' . $longitude . '#map=10/' . $latitude . '/' . $longitude;
63*c9c6f2ecSGreg Roach    }
64*c9c6f2ecSGreg Roach}
65