3 import { map_store } from '../lib/stores.js';
13 function map_link_to_osm(map) {
14 var zoom = map.getZoom();
15 var lat = map.getCenter().lat.toFixed(5);
16 var lng = map.getCenter().lng.toFixed(5);
17 return 'https://openstreetmap.org/#map=' + zoom + '/' + lat + '/' + lng;
20 function map_viewbox_as_string(map) {
21 var bounds = map.getBounds();
22 var west = bounds.getWest();
23 var east = bounds.getEast();
25 if ((east - west) >= 360) { // covers more than whole planet
26 west = map.getCenter().lng - 179.999;
27 east = map.getCenter().lng + 179.999;
29 east = L.latLng(77, east).wrap().lng;
30 west = L.latLng(77, west).wrap().lng;
33 west.toFixed(5), // left
34 bounds.getNorth().toFixed(5), // top
35 east.toFixed(5), // right
36 bounds.getSouth().toFixed(5) // bottom
40 function display_map_position(map, mouse_lat_lng) {
41 map_center = map.getCenter().lat.toFixed(5) + ',' + map.getCenter().lng.toFixed(5);
42 view_on_osm_link = map_link_to_osm(map);
43 map_zoom = map.getZoom();
44 map_viewbox = map_viewbox_as_string(map);
47 mouse_position = [mouse_lat_lng.lat.toFixed(5), mouse_lat_lng.lng.toFixed(5)].join(',');
49 if (last_click_latlng) {
50 last_click = [last_click_latlng.lat.toFixed(5), last_click_latlng.lng.toFixed(5)].join(',');
55 map_store.subscribe(map => {
58 map.on('move', function () {
59 display_map_position(map);
60 // update_viewbox_field();
63 map.on('mousemove', function (e) {
64 display_map_position(map, e.latlng);
67 map.on('click', function (e) {
68 last_click_latlng = e.latlng;
69 display_map_position(map);
72 map.on('load', function () {
73 display_map_position(map);
77 function handleHideClick() {
78 document.getElementById('map-position').style.display = 'none';
79 document.getElementById('show-map-position').style.display = 'block';
84 <div id="map-position">
85 <div id="map-position-inner">
86 map center: {map_center}
87 <a target="_blank" href="{view_on_osm_link}">view on osm.org</a>
91 viewbox: {map_viewbox}
93 last click: {last_click}
95 mouse position: {mouse_position}
97 <div id="map-position-close"><a href="#hide" on:click={handleHideClick}>hide</a></div>
110 background-color: rgba(255, 255, 255, 0.7);
114 #map-position-close {
121 @media (max-width: 768px) {