Initial commit
This commit is contained in:
53
js/caprigis.js
Normal file
53
js/caprigis.js
Normal file
@@ -0,0 +1,53 @@
|
||||
'use strict';
|
||||
// Global leaflet
|
||||
/**
|
||||
* @namespace GIS
|
||||
*/
|
||||
const GIS = {};
|
||||
|
||||
const BASE_URL = location.href;
|
||||
|
||||
/**
|
||||
* @param {string} mapId
|
||||
* @param {number} zoomLevel
|
||||
* @returns {Map}
|
||||
*/
|
||||
GIS.initMap = function (mapId, zoomLevel = 15) {
|
||||
let map = L.map(mapId, {
|
||||
attributionControl: false,
|
||||
minZoom: 3
|
||||
}).setView([40.5492, 14.2317], zoomLevel);
|
||||
|
||||
// Il sistema di riferimento per i livelli geoJSON è EPSG3857
|
||||
map.crs = L.CRS.EPSG3857;
|
||||
|
||||
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
||||
}).addTo(map);
|
||||
|
||||
return map;
|
||||
}
|
||||
/**
|
||||
* @param {string} geoJSON
|
||||
* @param {Map} map
|
||||
*/
|
||||
GIS.loadLayer = async function (geoJSON, map, color = '#555') {
|
||||
const layer = await fetch(`${BASE_URL}/geojson/${geoJSON}`)
|
||||
.then(res => res.json())
|
||||
.catch(error => console.error(`Can't load layer ${geoJSON}. Reason: ${error}`));
|
||||
|
||||
L.geoJson(layer, {
|
||||
style: function (feature) {
|
||||
let style = {
|
||||
color: color,
|
||||
opacity: 0.4,
|
||||
weight: 2,
|
||||
fillColor: color,
|
||||
fillOpacity: 1
|
||||
};
|
||||
return style;
|
||||
}
|
||||
}).addTo(map);
|
||||
}
|
||||
|
||||
export default GIS;
|
||||
9
js/index.js
Normal file
9
js/index.js
Normal file
@@ -0,0 +1,9 @@
|
||||
import GIS from './caprigis.js';
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
let map = GIS.initMap('map');
|
||||
|
||||
// Layer vincoli
|
||||
GIS.loadLayer('vincoli.geojson', map);
|
||||
|
||||
});
|
||||
10
js/package.json
Normal file
10
js/package.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "caprigis",
|
||||
"version": "0.01",
|
||||
"main": "index.js",
|
||||
"author": "Nicolò P.",
|
||||
"license": "GPLv3",
|
||||
"dependencies": {
|
||||
"leaflet": "^1.9.4"
|
||||
}
|
||||
}
|
||||
8
js/yarn.lock
Normal file
8
js/yarn.lock
Normal file
@@ -0,0 +1,8 @@
|
||||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
leaflet@^1.9.4:
|
||||
version "1.9.4"
|
||||
resolved "https://registry.yarnpkg.com/leaflet/-/leaflet-1.9.4.tgz#23fae724e282fa25745aff82ca4d394748db7d8d"
|
||||
integrity sha512-nxS1ynzJOmOlHp+iL3FyWqK89GtNL8U8rvlMOsQdTTssxZwCXh8N2NB3GDQOL+YR3XnWyZAxwQixURb+FA74PA==
|
||||
Reference in New Issue
Block a user