Style layers and features; add jsdoc and fonts

This commit is contained in:
Nicolò P 2024-03-21 13:03:56 +01:00
parent 2b6f80e9c0
commit 6364228c89
19 changed files with 137 additions and 36 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

57
fonts/fonts.css Normal file
View File

@ -0,0 +1,57 @@
/*! Generated by Font Squirrel (https://www.fontsquirrel.com) on September 18, 2023 */
@font-face {
font-family: 'din_next_w1gregular';
src: url('dinnextw1g-regular-webfont.woff2') format('woff2'),
url('dinnextw1g-regular-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'din_next_w1gbold';
src: url('dinnextw1g-bold-webfont.woff2') format('woff2'),
url('dinnextw1g-bold-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'din_next_w1gbold_italic';
src: url('dinnextw1g-bolditalic-webfont.woff2') format('woff2'),
url('dinnextw1g-bolditalic-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'din_next_w1gitalic';
src: url('dinnextw1g-italic-webfont.woff2') format('woff2'),
url('dinnextw1g-italic-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'din_next_w1glight';
src: url('dinnextw1g-light-webfont.woff2') format('woff2'),
url('dinnextw1g-light-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'din_next_w1glight_italic';
src: url('dinnextw1g-lightitalic-webfont.woff2') format('woff2'),
url('dinnextw1g-lightitalic-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'din_next_w1gmedium';
src: url('dinnextw1g-medium-webfont.woff2') format('woff2'),
url('dinnextw1g-medium-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'din_next_w1gmedium_italic';
src: url('dinnextw1g-mediumitalic-webfont.woff2') format('woff2'),
url('dinnextw1g-mediumitalic-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
}

View File

@ -5,18 +5,58 @@
*/ */
const GIS = {}; const GIS = {};
const BASE_URL = location.href; const optionsVincoli = {
color: '#222',
opacity: 0.8,
weight: 1,
fillColor: '#987db7',
fillOpacity: 0.8
};
const optionsSiti = {
color: '#800040',
opacity: 1,
weight: 2.5,
fillColor: '#800040',
fillOpacity: 0.8
};
const optionsPaesistici = {
color: '#222',
opacity: 1,
weight: 1.5,
fillColor: '#ff8000',
fillOpacity: 0.8
};
const BASE_URL = location.href;
/**
*
* @param {?string} text
*/
function capitalize(text) {
let capital = text;
if (text) {
let words = text.split(' ');
capital = '';
for (let w of words) {
w = w[0].toUpperCase() + w.slice(1);
capital += w + ' ';
}
capital.trimEnd();
}
return capital;
}
/** /**
* @param {string} mapId * @param {string} mapId
* @param {number} zoomLevel * @param {number} zoomLevel
* @returns {Map} * @returns {Map}
*/ */
GIS.initMap = async function (mapId, zoomLevel = 15) { GIS.initMap = async function (mapId, zoomLevel = 15) {
let layerSiti = await this.loadLayer('siti.geojson', '#800040'); let layerVincoli = await this.loadLayer('vincoli.geojson', optionsVincoli);
let layerVincoli = await this.loadLayer('vincoli.geojson'); let layerSiti = await this.loadLayer('siti.geojson', optionsSiti, false);
// TODO named parameters?? // TODO named parameters??
let layerPaesistici = await this.loadLayer('paesistici.geojson', '#222', '#ff8000'); let layerPaesistici = await this.loadLayer('paesistici.geojson', optionsPaesistici);
let osmap = new L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', { let osmap = new L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxNativeZoom : 22, maxNativeZoom : 22,
maxZoom: 22, maxZoom: 22,
@ -40,37 +80,28 @@ GIS.initMap = async function (mapId, zoomLevel = 15) {
}; };
let layerControl = L.control.layers(baseMap, archeo).addTo(map); let layerControl = L.control.layers(baseMap, archeo).addTo(map);
//DEBUG
// Il sistema di riferimento per i livelli geoJSON è EPSG3857
} }
/** /**
* @todo Distinguere tipo di geojson per contenuto popup * @todo Distinguere tipo di geojson per contenuto popup
* @param {string} geoJSON * @param {string} geoJSON
* @param {Map} map * @param {{color, opacity, weight, fillColor, fillOpacity}} options Style options for features
* @param {boolean} popup Should the features have a popup?
*/ */
GIS.loadLayer = async function (geoJSON, color = '#222', fillColor = '#987db7') { GIS.loadLayer = async function (geoJSON, options, popup = true) {
const data = await fetch(`${BASE_URL}/geojson/${geoJSON}`) const data = await fetch(`${BASE_URL}/geojson/${geoJSON}`)
.then(res => res.json()) .then(res => res.json())
.catch(error => console.error(`Can't load layer ${geoJSON}. Reason: ${error}`)); .catch(error => console.error(`Can't load layer ${geoJSON}. Reason: ${error}`));
// DEBUG
console.log(data.features);
// Show data from feature in popUp? // Show data from feature in popUp?
const layer = new L.geoJson(data, { const layer = new L.geoJson(data, {
style: function (feature) { style: function (feature) {
let style = { let style = options;
color: color,
opacity: 0.8,
weight: 1,
fillColor: fillColor,
fillOpacity: 0.8
};
return style; return style;
}, },
onEachFeature: function (feature, layer) { onEachFeature: function (feature, layer) {
layer.bindPopup(GIS.featurePopup(geoJSON, feature)); if (popup) {
layer.bindPopup(GIS.featurePopup(geoJSON, feature));
}
} }
}); });
@ -85,23 +116,17 @@ GIS.loadLayer = async function (geoJSON, color = '#222', fillColor = '#987db7')
* @returns {string} The popup's content * @returns {string} The popup's content
*/ */
GIS.featurePopup = function (layerName, feature) { GIS.featurePopup = function (layerName, feature) {
const html = `
<table class="table m-2">
<tr><td class="text-bold">Oggetto</td><td>${feature.properties.OGGETTO}</td></tr>
<tr><td class="text-bold">Anno</td><td>${feature.properties.ANNO}</td></tr>
<tr><td class="text-bold">Comune</td><td>${capitalize(feature.properties.COMUNE)}</td></tr>
<tr><td class="text-bold">Proprietà</td><td>${capitalize(feature.properties.PROPRIETA)}</td></tr>
</table>
`;
const content = { const content = {
'vincoli.geojson' : ` 'vincoli.geojson' : html,
<table class="table m-2"> 'paesistici.geojson' : html,
<tr><td class="text-bold">Oggetto</td><td>${feature.properties.OGGETTO}</td></tr>
<tr><td class="text-bold">Anno</td><td>${feature.properties.ANNO}</td></tr>
<tr><td class="text-bold">Comune</td><td>${feature.properties.COMUNE}</td></tr>
<tr><td class="text-bold">Proprietà</td><td>${feature.properties.PROPRIETA}</td></tr>
</table>
`,
'paesistici.geojson' : `
<table class="table m-2">
<tr><td class="text-bold">Oggetto</td><td>${feature.properties.OGGETTO}</td></tr>
<tr><td class="text-bold">Anno</td><td>${feature.properties.ANNO}</td></tr>
<tr><td class="text-bold">Comune</td><td>${feature.properties.COMUNE}</td></tr>
<tr><td class="text-bold">Proprietà</td><td>${feature.properties.PROPRIETA}</td></tr>
</table>
`,
}; };
return content[layerName]; return content[layerName];

19
js/jsdoc.json Normal file
View File

@ -0,0 +1,19 @@
{
"source": {
"include": ["caprigis.js", "index.js"],
"includePattern": ".js$",
"excludePattern": "(vendor/|docs)"
},
"plugins": ["plugins/markdown"],
"opts": {
"encoding": "utf8",
"destination": "docs/",
"recurse": true,
"verbose": true,
"theme_opts": {
"theme": "light"
}
}
}