xref: /webtrees/resources/views/admin/location-edit.phtml (revision 8af6bbf82759f6df0fe2b5b49cb4dd05118748d1)
1dd6b2bfcSGreg Roach<?php use Fisharebest\Webtrees\Functions\FunctionsEdit; ?>
2dd6b2bfcSGreg Roach<?php use Fisharebest\Webtrees\I18N; ?>
3dd6b2bfcSGreg Roach<?php use Fisharebest\Webtrees\View; ?>
4dd6b2bfcSGreg Roach
5dd6b2bfcSGreg Roach<?= view('components/breadcrumbs', ['links' => $breadcrumbs]) ?>
6dd6b2bfcSGreg Roach
7dd6b2bfcSGreg Roach<h1><?= $title ?></h1>
8dd6b2bfcSGreg Roach
9dd6b2bfcSGreg Roach<div class="form-group row">
10dd6b2bfcSGreg Roach    <div class="col-sm-10 offset-sm-1">
11dd6b2bfcSGreg Roach        <div id="osm-map" class="wt-ajax-load col-sm-12 osm-admin-map"></div>
12dd6b2bfcSGreg Roach    </div>
13dd6b2bfcSGreg Roach</div>
14dd6b2bfcSGreg Roach
15dd6b2bfcSGreg Roach<form method="post">
16dd6b2bfcSGreg Roach    <?= csrf_field() ?>
17*8af6bbf8SGreg Roach    <input type="hidden" name="place_id" value="<?= e($place_id) ?>">
18dd6b2bfcSGreg Roach    <input type="hidden" name="level" value="<?= count($hierarchy) ?>">
19*8af6bbf8SGreg Roach    <input type="hidden" name="place_long" value="<?= e($lng) ?>">
20*8af6bbf8SGreg Roach    <input type="hidden" name="place_lati" value="<?= e($lat) ?>">
21dd6b2bfcSGreg Roach
22dd6b2bfcSGreg Roach    <div class="form-group row">
23dd6b2bfcSGreg Roach        <label class="col-form-label col-sm-1" for="new_place_name">
24dd6b2bfcSGreg Roach            <?= I18N::translate('Place') ?>
25dd6b2bfcSGreg Roach        </label>
26dd6b2bfcSGreg Roach        <div class="col-sm-5">
27*8af6bbf8SGreg Roach            <input type="text" id="new_place_name" name="new_place_name" value="<?= e($location->locationName()) ?>"
28dd6b2bfcSGreg Roach            class="form-control" required>
29dd6b2bfcSGreg Roach        </div>
30dd6b2bfcSGreg Roach        <label class="col-form-label col-sm-1" for="icon">
31dd6b2bfcSGreg Roach            <?= I18N::translate('Flag') ?>
32dd6b2bfcSGreg Roach        </label>
33dd6b2bfcSGreg Roach        <div class="col-sm-4">
34dd6b2bfcSGreg Roach            <div class="input-group" dir="ltr">
35dd6b2bfcSGreg Roach                <?= FunctionsEdit::formControlFlag(
36*8af6bbf8SGreg Roach                    $location->icon(),
37dd6b2bfcSGreg Roach                    ['name' => 'icon', 'id' => 'icon', 'class' => 'form-control']
38dd6b2bfcSGreg Roach                )
39dd6b2bfcSGreg Roach?>
40dd6b2bfcSGreg Roach            </div>
41dd6b2bfcSGreg Roach        </div>
42dd6b2bfcSGreg Roach    </div>
43dd6b2bfcSGreg Roach
44dd6b2bfcSGreg Roach    <div class="form-group row">
45dd6b2bfcSGreg Roach        <label class="col-form-label col-sm-1">
46dd6b2bfcSGreg Roach            <?= I18N::translate('Latitude') ?>
47dd6b2bfcSGreg Roach        </label>
48dd6b2bfcSGreg Roach        <div class="col-sm-3">
49dd6b2bfcSGreg Roach            <div class="input-group">
500e7a2d23SGreg Roach                <input type="text" dir="ltr" id="new_place_lati" class="editable form-control" name="new_place_lati" required
51*8af6bbf8SGreg Roach                placeholder="<?= I18N::translate('degrees') ?>" value="<?= e($lat) ?>"
52dd6b2bfcSGreg Roach                >
53dd6b2bfcSGreg Roach            </div>
54dd6b2bfcSGreg Roach        </div>
55dd6b2bfcSGreg Roach
56dd6b2bfcSGreg Roach        <label class="col-form-label col-sm-1">
57dd6b2bfcSGreg Roach            <?= I18N::translate('Longitude') ?>
58dd6b2bfcSGreg Roach        </label>
59dd6b2bfcSGreg Roach        <div class="col-sm-3">
60dd6b2bfcSGreg Roach            <div class="input-group">
610e7a2d23SGreg Roach                <input type="text" dir="ltr" id="new_place_long" class="editable form-control" name="new_place_long" required
62*8af6bbf8SGreg Roach                placeholder="<?= I18N::translate('degrees') ?>" value="<?= e($lng) ?>"
63dd6b2bfcSGreg Roach                >
64dd6b2bfcSGreg Roach            </div>
65dd6b2bfcSGreg Roach        </div>
66dd6b2bfcSGreg Roach        <label class="col-form-label col-sm-1" for="new_zoom_factor">
67dd6b2bfcSGreg Roach            <?= I18N::translate('Zoom') ?>
68dd6b2bfcSGreg Roach        </label>
69dd6b2bfcSGreg Roach        <div class="col-sm-2">
70*8af6bbf8SGreg Roach            <input type="text" id="new_zoom_factor" name="new_zoom_factor" value="<?= e($location->zoom()) ?>"
71dd6b2bfcSGreg Roach            class="form-control" required readonly>
72dd6b2bfcSGreg Roach        </div>
73dd6b2bfcSGreg Roach    </div>
74dd6b2bfcSGreg Roach
75dd6b2bfcSGreg Roach    <div class="form-group row">
76dd6b2bfcSGreg Roach        <div class="col-sm-10 offset-sm-1">
77dd6b2bfcSGreg Roach            <button class="btn btn-primary" type="submit">
78dd6b2bfcSGreg Roach                <?= /* I18N: A button label. */
79dd6b2bfcSGreg Roach                I18N::translate('save')
80dd6b2bfcSGreg Roach                ?>
81dd6b2bfcSGreg Roach            </button>
82dd6b2bfcSGreg Roach            <a class="btn btn-secondary" href="<?= e(route('map-data', ['parent_id' => $parent_id])) ?>">
83dd6b2bfcSGreg Roach                <?= I18N::translate('cancel') ?>
84dd6b2bfcSGreg Roach            </a>
85dd6b2bfcSGreg Roach        </div>
86dd6b2bfcSGreg Roach    </div>
87dd6b2bfcSGreg Roach</form>
88dd6b2bfcSGreg Roach
89dd6b2bfcSGreg Roach<?php View::push('styles') ?>
90dd6b2bfcSGreg Roach<style>
91dd6b2bfcSGreg Roach    .osm-wrapper, .osm-user-map {
92dd6b2bfcSGreg Roach        height: 45vh
93dd6b2bfcSGreg Roach    }
94dd6b2bfcSGreg Roach
95dd6b2bfcSGreg Roach    .osm-admin-map {
96dd6b2bfcSGreg Roach        height: 55vh;
97dd6b2bfcSGreg Roach        border: 1px solid darkGrey
98dd6b2bfcSGreg Roach    }
99dd6b2bfcSGreg Roach
100dd6b2bfcSGreg Roach    .osm-sidebar {
101dd6b2bfcSGreg Roach        height: 100%;
102dd6b2bfcSGreg Roach        overflow-y: auto;
103dd6b2bfcSGreg Roach        padding: 0;
104dd6b2bfcSGreg Roach        margin: 0;
105dd6b2bfcSGreg Roach        border: 0;
106dd6b2bfcSGreg Roach        display: none;
107dd6b2bfcSGreg Roach        font-size: small;
108dd6b2bfcSGreg Roach    }
109dd6b2bfcSGreg Roach
110dd6b2bfcSGreg Roach    .osm-sidebar .gchart {
111dd6b2bfcSGreg Roach        margin: 1px;
112dd6b2bfcSGreg Roach        padding: 2px
113dd6b2bfcSGreg Roach    }
114dd6b2bfcSGreg Roach
115dd6b2bfcSGreg Roach    .osm-sidebar .gchart img {
116dd6b2bfcSGreg Roach        height: 15px;
117dd6b2bfcSGreg Roach        width: 25px
118dd6b2bfcSGreg Roach    }
119dd6b2bfcSGreg Roach
120dd6b2bfcSGreg Roach    .osm-sidebar .border-danger:hover {
121dd6b2bfcSGreg Roach        cursor: not-allowed
122dd6b2bfcSGreg Roach    }
123dd6b2bfcSGreg Roach
124dd6b2bfcSGreg Roach    [dir=rtl] .leaflet-right {
125dd6b2bfcSGreg Roach        right: auto;
126dd6b2bfcSGreg Roach        left: 0
127dd6b2bfcSGreg Roach    }
128dd6b2bfcSGreg Roach
129dd6b2bfcSGreg Roach    [dir=rtl] .leaflet-right .leaflet-control {
130dd6b2bfcSGreg Roach        margin-right: 0;
131dd6b2bfcSGreg Roach        margin-left: 10px
132dd6b2bfcSGreg Roach    }
133dd6b2bfcSGreg Roach
134dd6b2bfcSGreg Roach    [dir=rtl] .leaflet-left {
135dd6b2bfcSGreg Roach        left: auto;
136dd6b2bfcSGreg Roach        right: 0
137dd6b2bfcSGreg Roach    }
138dd6b2bfcSGreg Roach
139dd6b2bfcSGreg Roach    [dir=rtl] .leaflet-left .leaflet-control {
140dd6b2bfcSGreg Roach        margin-left: 0;
141dd6b2bfcSGreg Roach        margin-right: 10px
142dd6b2bfcSGreg Roach    }
143dd6b2bfcSGreg Roach</style>
144dd6b2bfcSGreg Roach<?php View::endpush() ?>
145dd6b2bfcSGreg Roach
146dd6b2bfcSGreg Roach<?php View::push('javascript') ?>
147dd6b2bfcSGreg Roach<script type="application/javascript">
148dd6b2bfcSGreg Roach  "use strict";
149dd6b2bfcSGreg Roach
150dd6b2bfcSGreg Roach  window.WT_OSM_ADMIN = (function () {
151dd6b2bfcSGreg Roach    let baseData = {
152dd6b2bfcSGreg Roach      minZoom:         2,
153dd6b2bfcSGreg Roach      providerName:    "OpenStreetMap.Mapnik",
154dd6b2bfcSGreg Roach      providerOptions: [],
155dd6b2bfcSGreg Roach      I18N:            {
156dd6b2bfcSGreg Roach        zoomInTitle: <?= json_encode(I18N::translate('Zoom in')) ?>,
157dd6b2bfcSGreg Roach        zoomOutTitle: <?= json_encode(I18N::translate('Zoom out')) ?>,
158dd6b2bfcSGreg Roach        reset: <?= json_encode(I18N::translate('Reset to initial map state')) ?>,
159dd6b2bfcSGreg Roach        noData: <?= json_encode(I18N::translate('No mappable items')) ?>,
160dd6b2bfcSGreg Roach        error: <?= json_encode(I18N::translate('An unknown error occurred')) ?>
161dd6b2bfcSGreg Roach      }
162dd6b2bfcSGreg Roach    };
163dd6b2bfcSGreg Roach
164dd6b2bfcSGreg Roach    let map      = null;
165dd6b2bfcSGreg Roach    let marker   = L.marker([0, 0], {
166dd6b2bfcSGreg Roach      draggable: true,
167dd6b2bfcSGreg Roach    });
168dd6b2bfcSGreg Roach    /**
169dd6b2bfcSGreg Roach     *
170dd6b2bfcSGreg Roach     * @private
171dd6b2bfcSGreg Roach     */
172dd6b2bfcSGreg Roach    let _drawMap = function () {
173dd6b2bfcSGreg Roach      map = L.map("osm-map", {
174dd6b2bfcSGreg Roach          center:      [0, 0],
175dd6b2bfcSGreg Roach          minZoom:     baseData.minZoom, // maxZoom set by leaflet-providers.js
176dd6b2bfcSGreg Roach          zoomControl: false, // remove default
177dd6b2bfcSGreg Roach        },
178dd6b2bfcSGreg Roach      );
179dd6b2bfcSGreg Roach      L.tileLayer.provider(baseData.providerName, baseData.providerOptions).addTo(map);
180dd6b2bfcSGreg Roach      L.control.zoom({ // Add zoom with localised text
181dd6b2bfcSGreg Roach        zoomInTitle:  baseData.I18N.zoomInTitle,
182dd6b2bfcSGreg Roach        zoomOutTitle: baseData.I18N.zoomOutTitle,
183dd6b2bfcSGreg Roach      }).addTo(map);
184dd6b2bfcSGreg Roach
185dd6b2bfcSGreg Roach      marker
186dd6b2bfcSGreg Roach        .on("dragend", function (e) {
187dd6b2bfcSGreg Roach          let coords = marker.getLatLng();
188dd6b2bfcSGreg Roach          map.panTo(coords);
189dd6b2bfcSGreg Roach          _update_Controls({
190dd6b2bfcSGreg Roach            place:  "",
191dd6b2bfcSGreg Roach            coords: coords,
192dd6b2bfcSGreg Roach            zoom:   map.getZoom(),
193dd6b2bfcSGreg Roach          });
194dd6b2bfcSGreg Roach        })
195dd6b2bfcSGreg Roach        .addTo(map);
196dd6b2bfcSGreg Roach      let searchControl = new window.GeoSearch.GeoSearchControl({
197dd6b2bfcSGreg Roach        provider:        new window.GeoSearch.OpenStreetMapProvider(),
198dd6b2bfcSGreg Roach        retainZoomLevel: true,
199dd6b2bfcSGreg Roach        autoClose:       true,
200dd6b2bfcSGreg Roach        showMarker:      false,
201dd6b2bfcSGreg Roach      });
202dd6b2bfcSGreg Roach
203dd6b2bfcSGreg Roach      map
204dd6b2bfcSGreg Roach        .addControl(searchControl)
205dd6b2bfcSGreg Roach        .on("geosearch/showlocation", function (result) {
206dd6b2bfcSGreg Roach          let lat   = result.location.y;
207dd6b2bfcSGreg Roach          let lng   = result.location.x;
208dd6b2bfcSGreg Roach          let place = result.location.label.split(",", 1);
209dd6b2bfcSGreg Roach
210dd6b2bfcSGreg Roach          marker.setLatLng([lat, lng]);
211dd6b2bfcSGreg Roach          map.panTo([lat, lng]);
212dd6b2bfcSGreg Roach
213dd6b2bfcSGreg Roach          _update_Controls({
214dd6b2bfcSGreg Roach            place:  place.shift(),
215dd6b2bfcSGreg Roach            coords: {
216dd6b2bfcSGreg Roach              "lat": lat,
217dd6b2bfcSGreg Roach              "lng": lng,
218dd6b2bfcSGreg Roach            },
219dd6b2bfcSGreg Roach            zoom:   map.getZoom(),
220dd6b2bfcSGreg Roach          });
221dd6b2bfcSGreg Roach        })
222dd6b2bfcSGreg Roach        .on("zoomend", function (e) {
223dd6b2bfcSGreg Roach          $("#new_zoom_factor").val(map.getZoom());
224dd6b2bfcSGreg Roach          map.panTo(marker.getLatLng());
225dd6b2bfcSGreg Roach        });
226dd6b2bfcSGreg Roach    };
227dd6b2bfcSGreg Roach
228dd6b2bfcSGreg Roach    let data = <?= json_encode($data) ?>;
229dd6b2bfcSGreg Roach
230dd6b2bfcSGreg Roach    /**
231dd6b2bfcSGreg Roach     *
232dd6b2bfcSGreg Roach     * @param newData
233dd6b2bfcSGreg Roach     * @private
234dd6b2bfcSGreg Roach     */
235dd6b2bfcSGreg Roach    let _update_Controls = function (newData) {
236dd6b2bfcSGreg Roach      let placeEl = $("#new_place_name");
237dd6b2bfcSGreg Roach      if (!placeEl.val().length && newData.place.length) {
238dd6b2bfcSGreg Roach        placeEl.val(newData.place);
239dd6b2bfcSGreg Roach      }
240dd6b2bfcSGreg Roach      $("#new_place_lati").val(Number(newData.coords.lat).toFixed(5)); // 5 decimal places (about 1 metre accuracy)
241dd6b2bfcSGreg Roach      $("#new_place_long").val(Number(newData.coords.lng).toFixed(5));
242dd6b2bfcSGreg Roach      $("#new_zoom_factor").val(Number(newData.zoom));
243dd6b2bfcSGreg Roach    };
244dd6b2bfcSGreg Roach
245dd6b2bfcSGreg Roach    $(function () {
246dd6b2bfcSGreg Roach      $(".editable").on("change", function (e) {
247dd6b2bfcSGreg Roach        let lat = $("#new_place_lati").val();
248dd6b2bfcSGreg Roach        let lng = $("#new_place_long").val();
249dd6b2bfcSGreg Roach        marker.setLatLng([lat, lng]);
250dd6b2bfcSGreg Roach        map.panTo([lat, lng]);
251dd6b2bfcSGreg Roach      });
252dd6b2bfcSGreg Roach    });
253dd6b2bfcSGreg Roach
254dd6b2bfcSGreg Roach    /**
255dd6b2bfcSGreg Roach     *
256dd6b2bfcSGreg Roach     * @param id
257dd6b2bfcSGreg Roach     */
258dd6b2bfcSGreg Roach    let initialize = function (id) {
259dd6b2bfcSGreg Roach      _drawMap();
260dd6b2bfcSGreg Roach
261dd6b2bfcSGreg Roach      marker.setLatLng(data.coordinates);
262dd6b2bfcSGreg Roach
263dd6b2bfcSGreg Roach      if (data.coordinates[0] === 0 && data.coordinates[1] === 0) {
264dd6b2bfcSGreg Roach        map.fitWorld();
265dd6b2bfcSGreg Roach      } else {
266dd6b2bfcSGreg Roach        map.setView(data.coordinates, data.zoom);
267dd6b2bfcSGreg Roach      }
268dd6b2bfcSGreg Roach    };
269dd6b2bfcSGreg Roach
270dd6b2bfcSGreg Roach    return {
271dd6b2bfcSGreg Roach      /**
272dd6b2bfcSGreg Roach       *
273dd6b2bfcSGreg Roach       * @param id
274dd6b2bfcSGreg Roach       */
275dd6b2bfcSGreg Roach      drawMap: function (id) {
276dd6b2bfcSGreg Roach        initialize(id);
277dd6b2bfcSGreg Roach      },
278dd6b2bfcSGreg Roach    };
279dd6b2bfcSGreg Roach  })();
280dd6b2bfcSGreg Roach
281dd6b2bfcSGreg Roach  WT_OSM_ADMIN.drawMap(<?= json_encode($ref) ?>);
282dd6b2bfcSGreg Roach</script>
283dd6b2bfcSGreg Roach<?php View::endpush() ?>
284