1 //= require maplibre.map
2 //= require maplibre/map
3 //= require maplibre/controls
4 //= require maplibre/dom_util
9 function updateFormFieldsFromMarkerPosition() {
10 const lngLat = marker.getLngLat();
11 $("#latitude").val(lngLat.lat);
12 $("#longitude").val(lngLat.lng);
15 function setLocation(e) {
16 const coords = e.lngLat.wrap();
18 marker.setLngLat(coords);
20 marker = new OSM.MapLibre.Marker({ draggable: true })
22 .setPopup(new OSM.MapLibre.Popup().setHTML(OSM.i18n.t("diary_entries.edit.marker_text")))
24 marker.on("dragend", updateFormFieldsFromMarkerPosition);
26 updateFormFieldsFromMarkerPosition();
29 $("#usemap").click(function (e) {
35 const params = $("#map").data();
36 map = new OSM.MapLibre.SecondaryMap({
37 center: [params.lon, params.lat],
41 const position = $("html").attr("dir") === "rtl" ? "top-left" : "top-right";
42 const navigationControl = new OSM.MapLibre.NavigationControl();
43 map.addControl(navigationControl, position);
45 // Create marker if coordinates exist when map is shown
46 if ($("#latitude").val() && $("#longitude").val()) {
47 const lngLat = new maplibregl.LngLat($("#longitude").val(), $("#latitude").val());
48 setLocation({ lngLat });
49 map.setCenter(lngLat);
52 map.on("click", setLocation);