From fc386c5a17d0ad8300cf09cb8c9a9e0e1f097984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Sch=C3=B6lzel?= Date: Wed, 22 Jan 2025 18:32:37 +0100 Subject: [PATCH] [BUGFIX] re-introduce search for coordinates in ol.Feature Array Rewrite displayHighlightWord to represent overwritable forward-function to utility.js --- .../Public/JavaScript/PageView/PageView.js | 28 +++++++++++++------ .../Public/JavaScript/PageView/Utility.js | 20 ++++++++++++- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/Resources/Public/JavaScript/PageView/PageView.js b/Resources/Public/JavaScript/PageView/PageView.js index 312d577d6..8837342a9 100644 --- a/Resources/Public/JavaScript/PageView/PageView.js +++ b/Resources/Public/JavaScript/PageView/PageView.js @@ -734,6 +734,18 @@ dlfViewer.prototype.createControl = function(controlName, layers) { } }; +/** + * Forwards the search to dlfUtils.searchFeatureCollectionForWords + * + * @param {Array.} stringFeatures - Array of features containing text information + * @param {string} value - Search term + * @returns {Array.|undefined} Array of OpenLayers features containing found words + * @see dlfUtils.searchFeatureCollectionForWords + */ +dlfViewer.prototype.searchFeatures = function(stringFeatures, value) { + return dlfUtils.searchFeatureCollectionForWords(stringFeatures, value); +}; + /** * Displays highlight words */ @@ -786,23 +798,23 @@ dlfViewer.prototype.displayHighlightWord = function(highlightWords = null) { } if (this.highlightWords !== null) { - var self = this; - var values = decodeURIComponent(this.highlightWords).split(';'); + const self = this; + const values = decodeURIComponent(this.highlightWords).split(';'); $.when.apply($, this.fulltextsLoaded_) - .done(function (fulltextData, fulltextDataImageTwo) { - var stringFeatures = []; + .done((fulltextData, fulltextDataImageTwo) => { + const stringFeatures = []; - [fulltextData, fulltextDataImageTwo].forEach(function (data) { + [fulltextData, fulltextDataImageTwo].forEach(data => { if (data !== undefined) { Array.prototype.push.apply(stringFeatures, data.getStringFeatures()); } }); - values.forEach(function(value) { - var features = dlfUtils.searchFeatureCollectionForCoordinates(stringFeatures, value); + values.forEach((value) => { + const features = this.searchFeatures(stringFeatures, value); if (features !== undefined) { - for (var i = 0; i < features.length; i++) { + for (let i = 0; i < features.length; i++) { self.highlightLayer.getSource().addFeatures([features[i]]); } } diff --git a/Resources/Public/JavaScript/PageView/Utility.js b/Resources/Public/JavaScript/PageView/Utility.js index c70b9d4d6..dad7da658 100644 --- a/Resources/Public/JavaScript/PageView/Utility.js +++ b/Resources/Public/JavaScript/PageView/Utility.js @@ -645,13 +645,31 @@ dlfUtils.scaleToImageSize = function (features, imageObj, width, height, optOffs return features; }; +/** + * Search a feature collection for a feature with the given coordinates + * @param {Array.} featureCollection + * @param {string} coordinates + * @return {Array.|undefined} + */ +dlfUtils.searchFeatureCollectionForCoordinates = function (featureCollection, coordinates) { + var features = []; + featureCollection.forEach(function (ft) { + if (ft.get('fulltext') !== undefined) { + if (ft.getId() === coordinates) { + features.push(ft); + } + } + }); + return features.length > 0 ? features : undefined; +}; + /** * Search a feature collection for a feature with the given word in its fulltext * @param {Array.} featureCollection * @param {string} word for highlighting * @returns {Array.|undefined} */ -dlfUtils.searchFeatureCollectionForCoordinates = function (featureCollection, word) { +dlfUtils.searchFeatureCollectionForWords = function (featureCollection, word) { var features = []; featureCollection.forEach(function (ft) { if (ft.values_.fulltext !== undefined) {