diff --git a/js/caprigis.js b/js/caprigis.js
index ef347aa..1f76b23 100644
--- a/js/caprigis.js
+++ b/js/caprigis.js
@@ -60,10 +60,44 @@ function capitalize(text) {
* @returns {{map: Map, sites: Layer}}
*/
GIS.initMap = async function (mapId, zoomLevel = this.INIT_ZOOM) {
- let layerVincoli = await this.loadLayer('vincoli.geojson', optionsVincoli);
+ L.LayerGroup.include({
+ customGetLayer : function (id) {
+ for (let l in this._layers) {
+ if (this._layers[l].id === id) {
+ return this._layers[l];
+ }
+ }
+ }
+ });
+
+ let map = L.map(mapId, {
+ attributionControl: false,
+ minZoom: 11,
+ }).setView(this.CENTER_COORDS, zoomLevel);
+
+ map.crs = L.CRS.EPSG4326;
+
+ const {baseMap, archeo, sitesGroup} = await this.initLayers(map);
+
+ L.control.layers(
+ baseMap,
+ archeo,
+ {collapsed: false}
+ )
+ .addTo(map);
+
+ // TODO Horrible?
+ return {map: map, sites: sitesGroup};
+}
+GIS.initLayers = async function(map) {
let layerMater = await this.loadLayer('matermania.geojson', optionsSiti, false);
let layerArsenale = await this.loadLayer('arsenale_planim.geojson', optionsSiti, false);
let layerGradola = await this.loadLayer('gradola.geojson', optionsSiti, false);
+
+ layerMater.id = 'matermania';
+ layerGradola.id = 'gradola';
+ layerArsenale.id = 'arsenale_planim';
+ let layerVincoli = await this.loadLayer('vincoli.geojson', optionsVincoli);
// TODO named parameters??
let layerPaesistici = await this.loadLayer('paesistici.geojson', optionsPaesistici);
let osmap = new L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
@@ -71,14 +105,11 @@ GIS.initMap = async function (mapId, zoomLevel = this.INIT_ZOOM) {
maxZoom: 22,
attribution: '© OpenStreetMap contributors'
});
- let map = L.map(mapId, {
- attributionControl: false,
- minZoom: 11,
- layers: [osmap, layerVincoli, layerMater, layerGradola, layerArsenale, layerPaesistici]
- }).setView(this.CENTER_COORDS, zoomLevel);
-
- map.crs = L.CRS.EPSG4326;
+ const sitesGroup = new L.LayerGroup([layerMater, layerGradola, layerArsenale]);
+ const baseGroup = new L.LayerGroup([osmap, layerVincoli, layerPaesistici]);
+ baseGroup.addTo(map);
+ sitesGroup.addTo(map);
const baseMap = {
"Mappa di base (OpenStreetMap)" : osmap
};
@@ -90,15 +121,7 @@ GIS.initMap = async function (mapId, zoomLevel = this.INIT_ZOOM) {
"Vincoli paesistici" : layerPaesistici,
};
- let layerControl = L.control.layers(
- baseMap,
- archeo,
- {collapsed: false}
- )
- .addTo(map);
-
- // TODO Horrible?
- return {map: map, sites: archeo};
+ return {baseMap, archeo, sitesGroup};
}
/**
* @todo Distinguere tipo di geojson per contenuto popup
diff --git a/js/index.js b/js/index.js
index 4179fdf..1806ad4 100644
--- a/js/index.js
+++ b/js/index.js
@@ -7,6 +7,7 @@ document.addEventListener('DOMContentLoaded', async () => {
UI.addCenterMapControl(map, GIS.CENTER_COORDS, GIS.INIT_ZOOM);
UI.toggleMenu('siti');
+ UI.sitesMenu('.menu-list', map, sites);
/*
for (let site of Object.keys(sites)) {
diff --git a/js/ui.js b/js/ui.js
index 6a254b8..e53ed36 100644
--- a/js/ui.js
+++ b/js/ui.js
@@ -24,24 +24,6 @@ const centerIcon = `
`;
-const siteIcon = ``;
/**
* Add a control to center the map
@@ -74,47 +56,6 @@ UI.addCenterMapControl = function (map, centerCoords, zoom) {
let centerCtr = new L.Control.CenterControl();
map.addControl(centerCtr);
}
-/**
- *
- * @param {Map} map
- * @param {LatLng} coordinates
- * @param {string} popupContent The site's name
- */
-UI.addSitesControl = function (map, coordinates, popupContent, initZoom = 15) {
- 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.setZoom(initZoom);
- 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 a ${popupContent}`;
- controlUI.href = '#';
- controlUI.innerHTML = siteIcon;
- return controlDiv;
- }
- });
-
- let siteCtr = new L.Control.SiteControl();
- map.addControl(siteCtr);
-}
/**
*
* @param {string} triggerId The ID of the trigger element
@@ -150,5 +91,25 @@ UI.openModal = async function (data) {
closeModal();
});
}
+/**
+ * @param {string} menuListSel Menu list selector
+ * @param {L.Map} map
+ * @param {L.LayerGroup} sites
+ */
+UI.sitesMenu = function (menuListSel, map, sites) {
+ const menu = document.querySelector(menuListSel);
+
+ menu.addEventListener('click', event => {
+ if (event.target.nodeName === 'A') {
+ // zoom to layer...
+ const layer = sites.customGetLayer(event.target.id);
+ map.setView(
+ layer.getBounds().getCenter(),
+ 19,
+ {animate: true, duration: 1, easeLinearity: 0.25}
+ );
+ }
+ });
+}
export default UI;
\ No newline at end of file