1d70512abSGreg Roach<?php 2d70512abSGreg Roach 3d70512abSGreg Roachuse Fisharebest\Webtrees\I18N; 4d70512abSGreg Roachuse Fisharebest\Webtrees\View; 5d70512abSGreg Roach 6d70512abSGreg Roach?> 7dd6b2bfcSGreg Roach 8dd6b2bfcSGreg Roach<?= view('components/breadcrumbs', ['links' => $breadcrumbs]) ?> 9dd6b2bfcSGreg Roach 10dd6b2bfcSGreg Roach<h1><?= $title ?></h1> 11dd6b2bfcSGreg Roach 12dd6b2bfcSGreg Roach<div class="form-group row"> 13*e340fe65SGreg Roach <div class="col-sm-12"> 140b4092edSGreg Roach <div id="osm-map" class="wt-ajax-load col-sm-12 osm-admin-map" dir="ltr"></div> 15dd6b2bfcSGreg Roach </div> 16dd6b2bfcSGreg Roach</div> 17dd6b2bfcSGreg Roach 18dd6b2bfcSGreg Roach<form method="post"> 19dd6b2bfcSGreg Roach <?= csrf_field() ?> 208af6bbf8SGreg Roach <input type="hidden" name="place_id" value="<?= e($place_id) ?>"> 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> 26*e340fe65SGreg Roach <div class="col-sm-3"> 2789d9f848SGreg Roach <input type="text" id="new_place_name" name="new_place_name" value="<?= e($location->locationName()) ?>" class="form-control" required> 28dd6b2bfcSGreg Roach </div> 29*e340fe65SGreg Roach 30*e340fe65SGreg Roach <input type="hidden" name="icon" id="icon" class="form-control" value="<?= e($location->icon()) ?>"> 31dd6b2bfcSGreg Roach </div> 32dd6b2bfcSGreg Roach 33dd6b2bfcSGreg Roach <div class="form-group row"> 3456a34df1SGreg Roach <label class="col-form-label col-sm-1" for="new_place_lati"> 35dd6b2bfcSGreg Roach <?= I18N::translate('Latitude') ?> 36dd6b2bfcSGreg Roach </label> 37dd6b2bfcSGreg Roach <div class="col-sm-3"> 38dd6b2bfcSGreg Roach <div class="input-group"> 39*e340fe65SGreg Roach <input type="text" dir="ltr" id="new_place_lati" class="editable form-control" name="new_place_lati" required placeholder="<?= I18N::translate('degrees') ?>" value="<?= e($location->latitude()) ?>" 40dd6b2bfcSGreg Roach > 41dd6b2bfcSGreg Roach </div> 42dd6b2bfcSGreg Roach </div> 43*e340fe65SGreg Roach </div> 44dd6b2bfcSGreg Roach 45*e340fe65SGreg Roach <div class="form-group row"> 4656a34df1SGreg Roach <label class="col-form-label col-sm-1" for="new_place_long"> 47dd6b2bfcSGreg Roach <?= I18N::translate('Longitude') ?> 48dd6b2bfcSGreg Roach </label> 49dd6b2bfcSGreg Roach <div class="col-sm-3"> 50dd6b2bfcSGreg Roach <div class="input-group"> 51*e340fe65SGreg Roach <input type="text" dir="ltr" id="new_place_long" class="editable form-control" name="new_place_long" required placeholder="<?= I18N::translate('degrees') ?>" value="<?= e($location->longitude()) ?>" 52dd6b2bfcSGreg Roach > 53dd6b2bfcSGreg Roach </div> 54dd6b2bfcSGreg Roach </div> 55*e340fe65SGreg Roach 56*e340fe65SGreg Roach <input type="hidden" id="new_zoom_factor" name="new_zoom_factor" value="<?= e($location->zoom()) ?>" class="form-control"> 57dd6b2bfcSGreg Roach </div> 58dd6b2bfcSGreg Roach 59dd6b2bfcSGreg Roach <div class="form-group row"> 60dd6b2bfcSGreg Roach <div class="col-sm-10 offset-sm-1"> 61dd6b2bfcSGreg Roach <button class="btn btn-primary" type="submit"> 62dd6b2bfcSGreg Roach <?= /* I18N: A button label. */ 63dd6b2bfcSGreg Roach I18N::translate('save') 64dd6b2bfcSGreg Roach ?> 65dd6b2bfcSGreg Roach </button> 66dd6b2bfcSGreg Roach <a class="btn btn-secondary" href="<?= e(route('map-data', ['parent_id' => $parent_id])) ?>"> 67dd6b2bfcSGreg Roach <?= I18N::translate('cancel') ?> 68dd6b2bfcSGreg Roach </a> 69dd6b2bfcSGreg Roach </div> 70dd6b2bfcSGreg Roach </div> 71dd6b2bfcSGreg Roach</form> 72dd6b2bfcSGreg Roach 73dd6b2bfcSGreg Roach<?php View::push('styles') ?> 74dd6b2bfcSGreg Roach<style> 75dd6b2bfcSGreg Roach .osm-admin-map { 76dd6b2bfcSGreg Roach height: 55vh; 77dd6b2bfcSGreg Roach border: 1px solid darkGrey 78dd6b2bfcSGreg Roach } 79dd6b2bfcSGreg Roach</style> 80dd6b2bfcSGreg Roach<?php View::endpush() ?> 81dd6b2bfcSGreg Roach 82dd6b2bfcSGreg Roach<?php View::push('javascript') ?> 8374b9ba3fSGreg Roach<script> 84caa53803SDavid Drury 'use strict'; 85dd6b2bfcSGreg Roach 86dd6b2bfcSGreg Roach window.WT_OSM_ADMIN = (function () { 87caa53803SDavid Drury const minZoom = 2; 882cbb0620SDavid Drury 892cbb0620SDavid Drury let provider = <?= json_encode($provider) ?>; 90dd6b2bfcSGreg Roach let map = null; 91caa53803SDavid Drury let add_place = <?= json_encode($place_id === 0) ?>; 92caa53803SDavid Drury 93caa53803SDavid Drury // map components 94dd6b2bfcSGreg Roach 9575e7614aSGreg Roach // postcss_image_inliner breaks the autodetection of image paths. 9675e7614aSGreg Roach L.Icon.Default.imagePath = <?= json_encode(asset('css/images/')) ?>; 9775e7614aSGreg Roach 98caa53803SDavid Drury // draggable marker 99*e340fe65SGreg Roach let marker = L.marker(<?= json_encode([$location->latitude(), $location->longitude()]) ?>, { 100caa53803SDavid Drury draggable: true, 101caa53803SDavid Drury }) 102caa53803SDavid Drury .on('dragend', function (e) { 103dd6b2bfcSGreg Roach let coords = marker.getLatLng(); 104dd6b2bfcSGreg Roach map.panTo(coords); 10562be603fSGreg Roach $('#new_place_lati').val(Number(coords.lat).toFixed(5)); 10662be603fSGreg Roach $('#new_place_long').val(Number(coords.lng).toFixed(5)); 10762be603fSGreg Roach $('#new_zoom_factor').val(Number(map.getZoom())); 108dd6b2bfcSGreg Roach }); 109dd6b2bfcSGreg Roach 110caa53803SDavid Drury //reset map to initial state 111caa53803SDavid Drury let resetControl = L.Control.extend({ 112caa53803SDavid Drury options: { 113caa53803SDavid Drury position: 'topleft' 114caa53803SDavid Drury }, 115caa53803SDavid Drury onAdd: function (map) { 116caa53803SDavid Drury let container = L.DomUtil.create('div', 'leaflet-bar leaflet-control leaflet-control-custom'); 117caa53803SDavid Drury container.onclick = function () { 118*e340fe65SGreg Roach map.fitBounds(<?= json_encode($location->boundingRectangle()) ?>); 119*e340fe65SGreg Roach marker.setLatLng(<?= json_encode([$location->latitude(), $location->longitude()]) ?>); 120caa53803SDavid Drury $('form').trigger('reset'); 121caa53803SDavid Drury return false; 122caa53803SDavid Drury }; 12347ca61d5SGreg Roach let reset = <?= json_encode(I18N::translate('Reset to initial map state')) ?>; 124caa53803SDavid Drury let anchor = L.DomUtil.create('a', 'leaflet-control-reset', container); 125caa53803SDavid Drury anchor.setAttribute('aria-label', reset); 126caa53803SDavid Drury anchor.href = '#'; 127caa53803SDavid Drury anchor.title = reset; 128caa53803SDavid Drury anchor.role = 'button'; 129caa53803SDavid Drury let image = L.DomUtil.create('i', 'fas fa-redo', anchor); 130caa53803SDavid Drury image.alt = reset; 131dd6b2bfcSGreg Roach 132caa53803SDavid Drury return container; 133caa53803SDavid Drury } 134caa53803SDavid Drury }); 135dd6b2bfcSGreg Roach 136caa53803SDavid Drury // zoom control with localised text 137caa53803SDavid Drury let zoomCtl = new L.control.zoom({ 138caa53803SDavid Drury zoomInTitle: <?= json_encode(I18N::translate('Zoom in')) ?>, 139caa53803SDavid Drury zoomOutTitle: <?= json_encode(I18N::translate('Zoom out')) ?>, 140caa53803SDavid Drury }); 141caa53803SDavid Drury 142caa53803SDavid Drury // Geocoder (place lookup) 143caa53803SDavid Drury let geocoder = new L.Control.geocoder({ 144caa53803SDavid Drury defaultMarkGeocode: false, 14522b076ddSGreg Roach expand: 'click', 146caa53803SDavid Drury showResultIcons: true, 147caa53803SDavid Drury query: '<?= e($location->locationName()) ?>', 148caa53803SDavid Drury placeholder: <?= json_encode(I18N::translate('Place')) ?>, 149caa53803SDavid Drury errorMessage: <?= json_encode(I18N::translate('Nothing found.')) ?>, 15047ca61d5SGreg Roach iconLabel: <?= json_encode(I18N::translate('Search')) ?> 151caa53803SDavid Drury }) 152caa53803SDavid Drury .on('markgeocode', function (result) { 153caa53803SDavid Drury let coords = result.geocode.center; 154caa53803SDavid Drury let place = result.geocode.name.split(',', 1); 155caa53803SDavid Drury marker.setLatLng(coords); 156caa53803SDavid Drury map.panTo(coords); 15762be603fSGreg Roach if (add_place) { 15862be603fSGreg Roach $('#new_place_name').val(place.shift()); 159caa53803SDavid Drury } 16062be603fSGreg Roach $('#new_place_lati').val(Number(coords.lat).toFixed(5)); 16162be603fSGreg Roach $('#new_place_long').val(Number(coords.lng).toFixed(5)); 16262be603fSGreg Roach $('#new_zoom_factor').val(Number(map.getZoom())); 16362be603fSGreg Roach }); 164caa53803SDavid Drury 165caa53803SDavid Drury /** 166caa53803SDavid Drury * 167caa53803SDavid Drury * @private 168caa53803SDavid Drury */ 169dd6b2bfcSGreg Roach $(function () { 170caa53803SDavid Drury // geocoder button tooltip 171caa53803SDavid Drury $('.leaflet-control-geocoder-icon') 17247ca61d5SGreg Roach .attr('title', <?= json_encode(I18N::translate('Search')) ?>); 173caa53803SDavid Drury 174caa53803SDavid Drury $('.editable').on('change', function (e) { 175caa53803SDavid Drury let lat = $('#new_place_lati').val(); 176caa53803SDavid Drury let lng = $('#new_place_long').val(); 177dd6b2bfcSGreg Roach marker.setLatLng([lat, lng]); 178dd6b2bfcSGreg Roach map.panTo([lat, lng]); 179dd6b2bfcSGreg Roach }); 180dd6b2bfcSGreg Roach }); 181dd6b2bfcSGreg Roach 182caa53803SDavid Drury // Create the map with all controls and layers 183caa53803SDavid Drury map = L.map('osm-map', { 184caa53803SDavid Drury minZoom: minZoom, // maxZoom set by leaflet-providers.js 185caa53803SDavid Drury zoomControl: false, // remove default 186caa53803SDavid Drury }) 187caa53803SDavid Drury .addControl(new resetControl()) 188caa53803SDavid Drury .addControl(zoomCtl) 189caa53803SDavid Drury .addControl(geocoder) 190caa53803SDavid Drury .addLayer(marker) 191caa53803SDavid Drury .addLayer(L.tileLayer(provider.url, provider.options)) 192*e340fe65SGreg Roach .fitBounds(<?= json_encode($location->boundingRectangle()) ?>) 193caa53803SDavid Drury .on('zoomend', function (e) { 194caa53803SDavid Drury $('#new_zoom_factor').val(map.getZoom()); 195caa53803SDavid Drury map.panTo(marker.getLatLng()); 196caa53803SDavid Drury }); 197dd6b2bfcSGreg Roach 198caa53803SDavid Drury return 'Leaflet map interface for webtrees-2'; 199dd6b2bfcSGreg Roach })(); 200dd6b2bfcSGreg Roach</script> 201dd6b2bfcSGreg Roach<?php View::endpush() ?> 202