|
|
@@ -168,8 +168,9 @@ $(document).ready(function(){
|
|
|
});
|
|
|
|
|
|
// **** Leaflet: maps *****
|
|
|
+ var map;
|
|
|
|
|
|
- function showMap(mapDiv) {
|
|
|
+ function showMap(mapDiv, zoomToItems=true) {
|
|
|
|
|
|
let mapId = $(mapDiv).attr("id");
|
|
|
if (!mapId) {
|
|
|
@@ -190,24 +191,15 @@ $(document).ready(function(){
|
|
|
});
|
|
|
|
|
|
// Instanciate the map object @see https://leafletjs.com/reference-1.6.0.html#map-factory
|
|
|
- var mapOptions = {scrollWheelZoom: false};
|
|
|
- var initialZoom = 13;
|
|
|
- var map = L.map(mapId, mapOptions);
|
|
|
- if (items.length > 0) {
|
|
|
- map.setView([items[0].lat, items[0].long], initialZoom);
|
|
|
+ const mapOptions = {scrollWheelZoom: false, zoomSnap: 0.25};
|
|
|
+ map = L.map(mapId, mapOptions);
|
|
|
+ if (zoomToItems && items.length > 0) {
|
|
|
+ map.setView([items[0].lat, items[0].long], 13);
|
|
|
} else {
|
|
|
- map.setView([46.3399276, 2.6067229], 5);
|
|
|
+ map.setView([46.71, 2.14], 6);
|
|
|
}
|
|
|
|
|
|
// Add the tile layer
|
|
|
- // L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}', {
|
|
|
- // maxZoom: 18,
|
|
|
- // id: 'mapbox/streets-v11',
|
|
|
- // tileSize: 512,
|
|
|
- // // zoomOffset: -1,
|
|
|
- // attribution: 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
|
|
|
- // accessToken: 'pk.eyJ1Ijoib2xpdmllci1tYXNzb3QiLCJhIjoiY2s5OGl1M2cxMWNpajNscnV4Zm5maWY3eSJ9.YDESFgB-JuAhplTzXI6hGQ',
|
|
|
- // }).addTo(map);
|
|
|
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
|
|
|
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
|
|
|
}).addTo(map);
|
|
|
@@ -221,11 +213,19 @@ $(document).ready(function(){
|
|
|
});
|
|
|
|
|
|
// Set the view
|
|
|
- if (items.length > 0) {
|
|
|
- var markersGroup = new L.featureGroup(markers);
|
|
|
- map.fitBounds(markersGroup.getBounds());
|
|
|
- map.zoomSnap = 1;
|
|
|
- map.zoomOut();
|
|
|
+ let bounds = null;
|
|
|
+ if (zoomToItems && items.length > 0) {
|
|
|
+ const markersGroup = new L.featureGroup(markers);
|
|
|
+ bounds = markersGroup.getBounds()
|
|
|
+ } else {
|
|
|
+ bounds = L.latLngBounds(
|
|
|
+ L.latLng(51.03, -5.78),
|
|
|
+ L.latLng(41.2, 9.70)
|
|
|
+ );
|
|
|
+ }
|
|
|
+ if (bounds !== null) {
|
|
|
+ map.fitBounds(bounds);
|
|
|
+ // map.zoomOut();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -242,9 +242,18 @@ $(document).ready(function(){
|
|
|
|
|
|
// Display map on network structures page
|
|
|
if ($('.ot-structures #structure-map').length) {
|
|
|
- showMap($('#structure-map').first());
|
|
|
+ showMap($('#structure-map').first(), false);
|
|
|
}
|
|
|
|
|
|
+ // Goto commands
|
|
|
+ $('img[data-map-fit]').on('click', function(e) {
|
|
|
+ let goto = $(this).data('map-fit');
|
|
|
+ let corners = goto.split(";");
|
|
|
+ let p1 = corners[0].split(",");
|
|
|
+ let p2 = corners[1].split(",");
|
|
|
+ let bounds = L.latLngBounds(L.latLng(p1[0], p1[1]), L.latLng(p2[0], p2[1]));
|
|
|
+ map.fitBounds(bounds);
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
|