Skip to content

Commit

Permalink
[BUGFIX] re-introduce search for coordinates in ol.Feature Array
Browse files Browse the repository at this point in the history
Rewrite displayHighlightWord to represent overwritable forward-function to utility.js
  • Loading branch information
fschoelzel committed Jan 22, 2025
1 parent 4b3a130 commit fc386c5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
28 changes: 20 additions & 8 deletions Resources/Public/JavaScript/PageView/PageView.js
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,18 @@ dlfViewer.prototype.createControl = function(controlName, layers) {
}
};

/**
* Forwards the search to dlfUtils.searchFeatureCollectionForWords
*
* @param {Array.<ol.Feature>} stringFeatures - Array of features containing text information
* @param {string} value - Search term
* @returns {Array.<ol.Feature>|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
*/
Expand Down Expand Up @@ -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]]);
}
}
Expand Down
20 changes: 19 additions & 1 deletion Resources/Public/JavaScript/PageView/Utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,13 +645,31 @@ dlfUtils.scaleToImageSize = function (features, imageObj, width, height, optOffs
return features;
};

/**

Check warning on line 648 in Resources/Public/JavaScript/PageView/Utility.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Resources/Public/JavaScript/PageView/Utility.js#L648

Missing JSDoc @returns declaration.
* Search a feature collection for a feature with the given coordinates
* @param {Array.<ol.Feature>} featureCollection
* @param {string} coordinates
* @return {Array.<ol.Feature>|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.<ol.Feature>} featureCollection
* @param {string} word for highlighting
* @returns {Array.<ol.Feature>|undefined}
*/
dlfUtils.searchFeatureCollectionForCoordinates = function (featureCollection, word) {
dlfUtils.searchFeatureCollectionForWords = function (featureCollection, word) {
var features = [];
featureCollection.forEach(function (ft) {
if (ft.values_.fulltext !== undefined) {
Expand Down

0 comments on commit fc386c5

Please sign in to comment.