diff --git a/lib/layer/decorate.mjs b/lib/layer/decorate.mjs index 678d3b92a5..0922bcfbe0 100644 --- a/lib/layer/decorate.mjs +++ b/lib/layer/decorate.mjs @@ -60,7 +60,8 @@ export default async layer => { // Spread in defaults. ...params?.defaults, - ...layer.draw?.defaults}) + ...layer.draw?.defaults + }) }) // Check whether feature is loaded on MVT update. @@ -79,9 +80,9 @@ export default async layer => { setTimeout(checkFeature, 1000) function checkFeature() { - + let found = layer.features?.find(F => F.properties?.id === location.id) - + if (found) { layer.source.un('tileloadend', concatFeatures); @@ -134,7 +135,7 @@ export default async layer => { // Keep object theme. layer.style.theme = typeof layer.style.theme === 'object' - + ? layer.style.theme // Assign theme from key [string], or first theme. @@ -148,7 +149,7 @@ export default async layer => { layer.style.label = layer.style.labels[layer.style.theme.setLabel] } - // Warn if outdated layer.hover configuration is used. + // Warn if outdated layer.hover configuration is used. // Set layer.style.hover and remove layer.hover. if (layer.hover) { @@ -252,7 +253,7 @@ export default async layer => { // Or plugin method and provide the layer object as argument. typeof mapp.plugins[key] === 'function' && mapp.plugins[key]?.(layer); - // It is possible to have a plugin method of the same name as a layer method. + // It is possible to have a plugin method of the same name as a layer method. }); return layer; diff --git a/lib/location/decorate.mjs b/lib/location/decorate.mjs index d23d3f09ef..f7c0352ba0 100644 --- a/lib/location/decorate.mjs +++ b/lib/location/decorate.mjs @@ -109,16 +109,12 @@ async function syncFields(fields) { } function flyTo(maxZoom) { - const sourceVector = new ol.source.Vector(); - this.Layers.forEach(layer => { - - const source = layer.getSource() - - typeof source.getFeatures === 'function' - && sourceVector.addFeatures(source.getFeatures()) - }) + this.Layers.forEach((layer) => { + const source = layer.getSource(); + typeof source.getFeatures === 'function' && sourceVector.addFeatures(source.getFeatures()); + }); this.layer.mapview.fitView(sourceVector.getExtent(), { maxZoom diff --git a/lib/mapview/fitView.mjs b/lib/mapview/fitView.mjs index 92c08ca350..02704fa338 100644 --- a/lib/mapview/fitView.mjs +++ b/lib/mapview/fitView.mjs @@ -1,8 +1,8 @@ -export default function (extent, opt_options = {}){ +export default function (extent, options = {}){ /** * Fits the view to a given extent * @param {Array} extent - geo extent, array of 4 numbers, must be [minX, minY, maxX, maxY] - * @param {Object} opt_options - Defaults to empty object + * @param {Object} options - Defaults to empty object */ // Extent must be an array of finite values. @@ -11,13 +11,9 @@ export default function (extent, opt_options = {}){ return; } - this.Map.getView().fit( - extent, - Object.assign( - { - padding: [50, 50, 50, 50], - duration: 1000 - }, - opt_options) - ) + this.Map.getView().fit(extent, { + padding: [50, 50, 50, 50], + duration: 1000, + ...options + }) } \ No newline at end of file diff --git a/lib/ui/Gazetteer.mjs b/lib/ui/Gazetteer.mjs index 126935dfc1..e2a3fc2405 100644 --- a/lib/ui/Gazetteer.mjs +++ b/lib/ui/Gazetteer.mjs @@ -1,5 +1,16 @@ export default gazetteer => { + mapp.utils.merge(mapp.dictionaries, { + en: { + invalid_lat_long_range: 'Invalid coordinates: Latitude and longitude values must be within valid ranges.', + invalid_lat_lon: 'The provided Coordinates do not fall within the selected Locale.' + }, + de: { + invalid_lat_long_range: 'Falsche Eingabe von Latitude / Longitude.', + invalid_lat_lon: 'Koordinate liegt außerhalb der Lokale.' + } + }) + gazetteer.input = mapp.utils.html.node`` @@ -27,24 +38,35 @@ export default gazetteer => { // Get possible coordinates from input. let ll = e.target.value.split(',').map(parseFloat) - // Check whether coordinates are float values. - if (ll.length === 2 && ll.every(n => !isNaN(n))) { + // Check whether coordinates are valid float values. + if (ll.length === 2 && ll.every(n => typeof n === 'number' && !isNaN(n) && isFinite(n))) { + + // Check if both coordinates are within valid range (latitude: -90 to 90, longitude: -180 to 180). + const [lat, lng] = ll; - gazetteer.list.appendChild(mapp.utils.html.node` -
  • { + if (lat >= -90 && lat <= 90 && lng >= -180 && lng <= 180) { + gazetteer.list.appendChild(mapp.utils.html.node` +
  • { + mapp.utils.gazetteer.getLocation({ + label: `Latitude:${ll[0]}, Longitude:${ll[1]}`, + source: 'Coordinates', + lng: ll[1], + lat: ll[0] + }, gazetteer); + }}>Latitude:${ll[0]}, Longitude:${ll[1]}`); - mapp.utils.gazetteer.getLocation({ - label: `Latitude:${ll[0]}, Longitude:${ll[1]}`, - source: 'Coordinates', - lng: ll[1], - lat: ll[0] - }) + // Do not search if coordinates are provided. + return; - }}>Latitude:${ll[0]}, Longitude:${ll[1]}`) + } else { - // Do not search if coordinates are provided. - return; + // Handle the case where coordinates are not within valid ranges. + // Add the error as a list item + gazetteer.list.appendChild(mapp.utils.html.node` +
  • + ${mapp.dictionary.invalid_lat_long_range}`); + + } } // An external gazetteer provider is requested @@ -64,5 +86,5 @@ export default gazetteer => { // Request datasets gazetteer mapp.utils.gazetteer.datasets(e.target.value, gazetteer) } - + } \ No newline at end of file diff --git a/lib/utils/gazetteer.mjs b/lib/utils/gazetteer.mjs index a527c25b7b..93f5011e21 100644 --- a/lib/utils/gazetteer.mjs +++ b/lib/utils/gazetteer.mjs @@ -3,6 +3,9 @@ export function datasets(term, gazetteer) { if (!gazetteer.provider) { // The default gazetteer config is for a dataset search. + // Abort current dataset query. Onload will not be called. + gazetteer.xhr?.abort() + gazetteer.xhr = new XMLHttpRequest() gazetteer.qterm && search(gazetteer) } @@ -46,7 +49,7 @@ export function datasets(term, gazetteer) { console.warn('No table definition for gazetteer search.') return; }; - + dataset.xhr.open('GET', gazetteer.mapview.host + '/api/query?' + mapp.utils.paramString({ template: dataset.query || 'gaz_query', @@ -112,6 +115,17 @@ export function getLocation(location, gazetteer) { return; } + const coord = ol.proj.transform( + [location.lng, location.lat], + `EPSG:4326`, + `EPSG:${gazetteer.mapview.srid}` + ) + + if (!ol.extent.containsCoordinate(gazetteer.mapview.extent, coord)) { + alert(mapp.dictionary.invalid_lat_lon); + return; + } + Object.assign(location, { layer: { mapview: gazetteer.mapview