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