'use strict'; /** * @namespace UI */ const UI = {}; const siteIcon = ` `; /** * Zoom and pan the map to a given layer position * @param {Map} map * @param {Layer} layer * @param {number} zoom Zoom level */ UI.zoomToPosition = function (map, layer, zoom = 20) { const center = layer.getCenter(); map.setView(center, zoom, {animate: true}); } /** * * @param {Map} map * @param {LatLng} coordinates * @param {string} popupContent */ UI.addSitesControl = function (map, coordinates, popupContent) { const popUpCoords = L.latLng(coordinates.lat + 0.0001, coordinates.lng); L.Control.SiteControl = L.Control.extend({ options: { position: 'topright' }, onAdd: function (map) { let controlDiv = L.DomUtil.create('div', 'leaflet-draw-toolbar leaflet-bar'); L.DomEvent .addListener(controlDiv, 'click', L.DomEvent.stopPropagation) .addListener(controlDiv, 'click', L.DomEvent.preventDefault) .addListener(controlDiv, 'click', function () { map.setView( coordinates, 19, {animate: true, duration: 1, easeLinearity: 0.25} ); L.popup() .setLatLng(popUpCoords) .setContent(popupContent) .openOn(map); }); let controlUI = L.DomUtil.create('a', 'leaflet-draw-edit-remove site-control', controlDiv); controlUI.title = 'Vai al sito'; controlUI.href = '#'; controlUI.innerHTML = siteIcon; return controlDiv; } }); let siteCtr = new L.Control.SiteControl(); map.addControl(siteCtr); } export default UI;