diff --git a/webgis/index.html b/webgis/index.html
index 1501ae6..d0f3db8 100644
--- a/webgis/index.html
+++ b/webgis/index.html
@@ -13,13 +13,14 @@
-
+
+
diff --git a/webgis/js/gis.js b/webgis/js/gis.js
index 3b09dd8..1da4301 100644
--- a/webgis/js/gis.js
+++ b/webgis/js/gis.js
@@ -9,16 +9,15 @@ import { GisState } from "./state.js";
const MAPBOX_TOKEN = 'pk.eyJ1Ijoibmljb3BhIiwiYSI6ImNseWNwZjJjbjFidzcya3BoYTU0bHg4NnkifQ.3036JnCXZTEMt6jVgMzVRw';
const BASE_URL = location.href;
-let API_URL = '';
-if (BASE_URL.includes('localhost')) {
+let API_URL = API_CONFIG.prod;
+
+if (!BASE_URL.includes('cnr.it')) {
API_URL = API_CONFIG.dev;
-} else {
- API_URL = API_CONFIG.prod;
}
GisState.apiUrl = API_URL;
-// Global leaflet
+// Global leaflet and proj4
/**
* @namespace GIS
*/
@@ -124,6 +123,21 @@ GIS.initMap = async function (mapId, zoomLevel = this.INIT_ZOOM) {
GisState.map = map;
+ // DEBUG - Test reprojected WMS
+ const reprojectedWMSLayer = GIS.reprojectWMS();
+ const wmsLayer = new reprojectedWMSLayer(
+ 'https://wms.cartografia.agenziaentrate.gov.it/inspire/wms/ows01.php?',
+ {
+ layers: 'fabbricati',
+ format: 'image/png',
+ transparent: true,
+ version: '1.1.1',
+ attribution: '© Agenzia Entrate',
+ }
+ );
+
+ wmsLayer.addTo(map);
+
return map;
}
/**
@@ -159,7 +173,7 @@ GIS.getImageOverlay = async function (imageId) {
`/webgis/img/geo/${imageData.filename}`,
bounds,
{
- opacity: 0.8,
+ opacity: 0.6,
alt: `Immagine georeferita (${imageData.label})`,
label: `geoimage:${imageData.id}:${imageData.label}`,
}
@@ -558,6 +572,51 @@ GIS.featurePopup = function (layerName, feature) {
return content[layerName];
}
+/**
+ * Reproject WMS layer to map's CRS
+ * @todo Parametrize CRS?
+ * @returns {L.TileLayer.WMS}
+ */
+GIS.reprojectWMS = function (crs = 'EPSG:4258') {
+ // Define EPSG:4258
+ proj4.defs('EPSG:4258', "+proj=longlat +ellps=GRS80 +no_defs +type=crs");
+
+ const reprojectedWMSLayer = L.TileLayer.WMS.extend({
+ getTileUrl(tilePoint) {
+ const map = GisState.map;
+ const crs = map.options.crs;
+ const tileSize = this.getTileSize();
+
+ //const geoPoint = L.point(tilePoint.x, tilePoint.y);
+ const nwPoint = L.point(
+ tilePoint.x * tileSize.x,
+ tilePoint.y * tileSize.y,
+ )
+ const sePoint = nwPoint.add(L.point(tileSize));
+
+ const nw = crs.project(map.unproject(nwPoint, tilePoint.z));
+ const se = crs.project(map.unproject(sePoint, tilePoint.z));
+
+ const [minX, minY] = proj4('EPSG:4326', 'EPSG:4258', [nw.x, se.y]);
+ const [maxX, maxY] = proj4('EPSG:4326', 'EPSG:4258', [se.x, nw.y]);
+
+ const bbox = [minX, minY, maxX, maxY].join(',');
+
+ return this._url + L.Util.getParamString({
+ ...this.wmsParams,
+ bbox,
+ width: tileSize.x,
+ height: tileSize.y,
+ srs: 'EPSG:4258'
+ },
+ this._url,
+ true
+ );
+ }
+ });
+
+ return reprojectedWMSLayer;
+}
/**
* Fetch data from API
* @param {string} recordUri The URI to be appendend to the API's base URL
diff --git a/webgis/js/package.json b/webgis/js/package.json
index 48bf6e4..7ded68e 100644
--- a/webgis/js/package.json
+++ b/webgis/js/package.json
@@ -12,6 +12,7 @@
"fontawesome-free": "^1.0.4",
"leaflet": "^1.9.4",
"leaflet.markercluster": "^1.5.3",
+ "proj4": "^2.9.4",
"spotlight.js": "^0.7.8"
},
"devDependencies": {}
diff --git a/webgis/js/yarn.lock b/webgis/js/yarn.lock
index 2bd0266..8b12f7d 100644
--- a/webgis/js/yarn.lock
+++ b/webgis/js/yarn.lock
@@ -39,6 +39,19 @@ leaflet@^1.9.4:
resolved "https://registry.yarnpkg.com/leaflet/-/leaflet-1.9.4.tgz#23fae724e282fa25745aff82ca4d394748db7d8d"
integrity sha512-nxS1ynzJOmOlHp+iL3FyWqK89GtNL8U8rvlMOsQdTTssxZwCXh8N2NB3GDQOL+YR3XnWyZAxwQixURb+FA74PA==
+mgrs@1.0.0:
+ version "1.0.0"
+ resolved "https://registry.yarnpkg.com/mgrs/-/mgrs-1.0.0.tgz#fb91588e78c90025672395cb40b25f7cd6ad1829"
+ integrity sha512-awNbTOqCxK1DBGjalK3xqWIstBZgN6fxsMSiXLs9/spqWkF2pAhb2rrYCFSsr1/tT7PhcDGjZndG8SWYn0byYA==
+
+proj4@^2.9.4:
+ version "2.19.4"
+ resolved "https://registry.yarnpkg.com/proj4/-/proj4-2.19.4.tgz#38cf347309f523309ead94d565788de94f07098f"
+ integrity sha512-1l6JiJ2ZOzXIoo6k64diOQVOvHIF0IACMrHTaFHrEQmuo1tY1vb73mrWfTSyPH+muc0Lut4zuj5encvB1Ccuhg==
+ dependencies:
+ mgrs "1.0.0"
+ wkt-parser "^1.5.1"
+
spotlight.js@^0.7.8:
version "0.7.8"
resolved "https://registry.yarnpkg.com/spotlight.js/-/spotlight.js-0.7.8.tgz#0620371701508222d736e0658e8db3fbe9ddc53b"
@@ -48,3 +61,8 @@ three@^0.169.0:
version "0.169.0"
resolved "https://registry.yarnpkg.com/three/-/three-0.169.0.tgz#4a62114988ad9728d73526d1f1de6760c56b4adc"
integrity sha512-Ed906MA3dR4TS5riErd4QBsRGPcx+HBDX2O5yYE5GqJeFQTPU+M56Va/f/Oph9X7uZo3W3o4l2ZhBZ6f6qUv0w==
+
+wkt-parser@^1.5.1:
+ version "1.5.2"
+ resolved "https://registry.yarnpkg.com/wkt-parser/-/wkt-parser-1.5.2.tgz#a8eaf86ac2cc1d0a2e6a8082a930f5c7ebdb5771"
+ integrity sha512-1ZUiV1FTwSiSrgWzV9KXJuOF2BVW91KY/mau04BhnmgOdroRQea7Q0s5TVqwGLm0D2tZwObd/tBYXW49sSxp3Q==