Refactor to generate menu dynamically
This commit is contained in:
@@ -112,7 +112,7 @@ GIS.initMap = async function (mapId, zoomLevel = this.INIT_ZOOM) {
|
||||
let layerVincoli = await this.loadGeoJSON('vincoli.geojson', optionsVincoli);
|
||||
let layerPaesistici = await this.loadGeoJSON('paesistici.geojson', optionsPaesistici);
|
||||
|
||||
this.addLayerGroups(map);
|
||||
await this.addLayerGroups(map);
|
||||
|
||||
const archeo = {
|
||||
'Vincoli archeologici' : layerVincoli,
|
||||
@@ -127,22 +127,22 @@ GIS.initMap = async function (mapId, zoomLevel = this.INIT_ZOOM) {
|
||||
/**
|
||||
* Add layer groups to map
|
||||
*/
|
||||
GIS.addLayerGroups = function (map) {
|
||||
GIS.addLayerGroups = async function (map) {
|
||||
// Can be included in Promise.all
|
||||
// if it returns only one group...
|
||||
this.sites().then(data => {
|
||||
data.markers.addTo(map);
|
||||
data.geom.addTo(map);
|
||||
});
|
||||
Promise.all(
|
||||
const sites = await this.sites();
|
||||
sites.markers.addTo(map);
|
||||
sites.geom.addTo(map);
|
||||
|
||||
const groups = await Promise.all(
|
||||
[
|
||||
this.notConserved(),
|
||||
this.findings(),
|
||||
this.prehistoric(),
|
||||
this.underwater(),
|
||||
]
|
||||
)
|
||||
.then(groups => groups.forEach(group => group.addTo(map)));
|
||||
);
|
||||
groups.forEach(group => group.addTo(map));
|
||||
}
|
||||
/**
|
||||
* Create markers for sites
|
||||
@@ -195,13 +195,17 @@ GIS.notConserved = async function () {
|
||||
let notConserved = L.markerClusterGroup(clusterOptions);
|
||||
|
||||
for (let record of notConserData.records) {
|
||||
const marker = L.marker(record.coordinates, {icon: Icons.notConserved})
|
||||
const marker = L.marker(
|
||||
record.coordinates,
|
||||
{icon: Icons.notConserved, label: record.label}
|
||||
)
|
||||
.bindTooltip(record.denomination)
|
||||
.on('click', () => UI.openNotConserModal(record, '#not-conser-data'));
|
||||
|
||||
notConserved.addLayer(marker);
|
||||
// Populate app state for reuse and avoid window.Sites etc.
|
||||
const markerLabel = `${record.coordinates[0]} ${record.coordinates[1]}`;
|
||||
marker.options.municipality = record.municipality;
|
||||
GisState.markers.notConserved[markerLabel] = marker;
|
||||
}
|
||||
|
||||
@@ -222,7 +226,9 @@ GIS.findings = async function () {
|
||||
);
|
||||
|
||||
for (let record of findingsData) {
|
||||
const marker = L.marker(record.coordinates, {icon: Icons.finding}
|
||||
const marker = L.marker(
|
||||
record.coordinates,
|
||||
{icon: Icons.finding, label: record.label}
|
||||
).bindTooltip(record.object)
|
||||
.on(
|
||||
'click',
|
||||
@@ -231,6 +237,7 @@ GIS.findings = async function () {
|
||||
|
||||
findings.addLayer(marker);
|
||||
const markerLabel = `${record.coordinates[0]} ${record.coordinates[1]}`;
|
||||
marker.options.municipality = record.municipality;
|
||||
GisState.markers.findings[markerLabel] = marker;
|
||||
}
|
||||
|
||||
@@ -253,7 +260,7 @@ GIS.prehistoric = async function () {
|
||||
for (let record of data.records) {
|
||||
const marker = L.marker(
|
||||
record.coordinates,
|
||||
{icon: Icons.prehistoric}
|
||||
{icon: Icons.prehistoric, label: record.label}
|
||||
).bindTooltip(record.denomination)
|
||||
.on(
|
||||
'click',
|
||||
@@ -261,6 +268,7 @@ GIS.prehistoric = async function () {
|
||||
);
|
||||
|
||||
const markerLabel = `${record.coordinates[0]} ${record.coordinates[1]}`;
|
||||
marker.options.municipality = record.municipality;
|
||||
GisState.markers.prehistoric[markerLabel] = marker;
|
||||
|
||||
prehistoric.addLayer(marker);
|
||||
|
||||
Reference in New Issue
Block a user