|
@@ -127,60 +127,79 @@ $(document).ready(function(){
|
|
|
|
|
|
|
|
// **** Leaflet: maps *****
|
|
// **** Leaflet: maps *****
|
|
|
|
|
|
|
|
- function showEventMap(mapDiv) {
|
|
|
|
|
|
|
+ function showMap(mapDiv) {
|
|
|
|
|
+
|
|
|
|
|
+ let mapId = $(mapDiv).attr("id");
|
|
|
|
|
+ if (!mapId) {
|
|
|
|
|
+ console.error('missing id attribute for map');
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// Collect the data from th map children <i>
|
|
// Collect the data from th map children <i>
|
|
|
- var events = [];
|
|
|
|
|
- mapDiv.children('.event-geodata').each(function () {
|
|
|
|
|
- let event_ = {
|
|
|
|
|
|
|
+ var items = [];
|
|
|
|
|
+ mapDiv.children('.item-geodata').each(function () {
|
|
|
|
|
+ let item = {
|
|
|
id: $(this).data('id'),
|
|
id: $(this).data('id'),
|
|
|
long: $(this).data('long'),
|
|
long: $(this).data('long'),
|
|
|
lat: $(this).data('lat'),
|
|
lat: $(this).data('lat'),
|
|
|
label: $(this).data('label')
|
|
label: $(this).data('label')
|
|
|
};
|
|
};
|
|
|
- events.push(event_);
|
|
|
|
|
|
|
+ items.push(item);
|
|
|
});
|
|
});
|
|
|
- if (events.length === 0) {
|
|
|
|
|
|
|
+ if (items.length === 0) {
|
|
|
|
|
+ console.error(mapId + ': no data to show');
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Instanciate the map object @see https://leafletjs.com/reference-1.6.0.html#map-factory
|
|
// Instanciate the map object @see https://leafletjs.com/reference-1.6.0.html#map-factory
|
|
|
var mapOptions = {scrollWheelZoom: false};
|
|
var mapOptions = {scrollWheelZoom: false};
|
|
|
var initialZoom = 13;
|
|
var initialZoom = 13;
|
|
|
- var eventMap = L.map('event-map', mapOptions);
|
|
|
|
|
- eventMap.setView([events[0].lat, events[0].long], initialZoom);
|
|
|
|
|
|
|
+ var map = L.map(mapId, mapOptions);
|
|
|
|
|
+ map.setView([items[0].lat, items[0].long], initialZoom);
|
|
|
|
|
|
|
|
// Add the tile layer
|
|
// 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(eventMap);
|
|
|
|
|
|
|
+ // 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);
|
|
|
|
|
|
|
|
// Collect the event geodata to create the markers
|
|
// Collect the event geodata to create the markers
|
|
|
- var markers = []
|
|
|
|
|
- events.forEach(function (event_) {
|
|
|
|
|
- var marker = L.marker([event_.lat, event_.long]).addTo(eventMap);
|
|
|
|
|
- marker.bindPopup(event_.label);
|
|
|
|
|
|
|
+ let markers = []
|
|
|
|
|
+ items.forEach(function (item) {
|
|
|
|
|
+ let marker = L.marker([item.lat, item.long]).addTo(map);
|
|
|
|
|
+ marker.bindPopup(item.label);
|
|
|
markers.push(marker);
|
|
markers.push(marker);
|
|
|
});
|
|
});
|
|
|
|
|
+ console.log(markers);
|
|
|
|
|
|
|
|
// Set the view
|
|
// Set the view
|
|
|
var markersGroup = new L.featureGroup(markers);
|
|
var markersGroup = new L.featureGroup(markers);
|
|
|
- eventMap.fitBounds(markersGroup.getBounds());
|
|
|
|
|
- eventMap.zoomSnap = 1;
|
|
|
|
|
- eventMap.zoomOut();
|
|
|
|
|
|
|
+ map.fitBounds(markersGroup.getBounds());
|
|
|
|
|
+ map.zoomSnap = 1;
|
|
|
|
|
+ map.zoomOut();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // Display map on events index page
|
|
|
if ($('.ot-all-events #event-map').length) {
|
|
if ($('.ot-all-events #event-map').length) {
|
|
|
- showEventMap($('#event-map').first());
|
|
|
|
|
|
|
+ showMap($('#event-map').first());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // Display map on event's details page
|
|
|
if ($('.ot-show-event #event-map').length) {
|
|
if ($('.ot-show-event #event-map').length) {
|
|
|
- showEventMap($('#event-map').first());
|
|
|
|
|
|
|
+ showMap($('#event-map').first());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Display map on network structures page
|
|
|
|
|
+ if ($('.ot-structures #structure-map').length) {
|
|
|
|
|
+ showMap($('#structure-map').first());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
});
|
|
});
|