Fullstack Portal Created by the HCMR for the Marine Strategy Framework Directive Program in order to cover demands and aspects considering extendability and maintainability
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.2 KiB

2 years ago
// -- Display information on click --
// Add an event handler for the map "click" event
function wmsClick(e) {
console.debug(e);
let districtLayer = e.target._layers[112];
// Build the URL for a GetFeatureInfo
var url = getFeatureInfoUrl(
mapL,
districtLayer,
e.latlng,
{
'info_format': 'application/json',
'propertyName': 'NAME,AREA_CODE,DESCRIPTIO'
}
);
// Send the request and create a popup showing the response
reqwest({
url: url,
type: 'json',
}).then(function (data) {
var feature = data.features[0];
L.popup()
.setLatLng(e.latlng)
.setContent(L.Util.template("<h2>{NAME}</h2><p>{DESCRIPTIO}</p>", feature.properties))
.openOn(map);
});
}
/**
* Return the WMS GetFeatureInfo URL for the passed map, layer and coordinate.
* Specific parameters can be passed as params which will override the
* calculated parameters of the same name.
*/
function getFeatureInfoUrl(map, layer, latlng, params) {
var point = map.latLngToContainerPoint(latlng, map.getZoom()),
size = map.getSize(),
bounds = map.getBounds(),
sw = bounds.getSouthWest(),
ne = bounds.getNorthEast();
// sw = crs.projection._proj.forward([sw.lng, sw.lat]),
// ne = crs.projection._proj.forward([ne.lng, ne.lat]);
console.debug(sw, ne);
// var layer = activeLayerList["MSFD_NEW" + layerName];
var defaultParams = {
request: 'GetFeatureInfo',
service: 'WMS',
srs: layer._crs.code,
styles: '',
version: layer._wmsVersion,
format: layer.options.format,
bbox: [sw.join(','), ne.join(',')].join(','),
height: size.y,
width: size.x,
layers: layer.options.layers,
query_layers: layer.options.layers,
info_format: 'text/html'
};
params = L.Util.extend(defaultParams, params || {});
params[params.version === '1.3.0' ? 'i' : 'x'] = point.x;
params[params.version === '1.3.0' ? 'j' : 'y'] = point.y;
return layer._url + L.Util.getParamString(params, layer._url, true);
}