Skip to content

Commit 5aa6fea

Browse files
committed
[BUGFIX] re-introduce search for coordinates in ol.Feature Array
Rewrite displayHighlightWord to represent overwritable forward-function to utility.js
1 parent 715c91c commit 5aa6fea

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

Resources/Public/JavaScript/PageView/PageView.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,18 @@ dlfViewer.prototype.createControl = function(controlName, layers) {
439439
}
440440
};
441441

442+
/**
443+
* Forwards the search to dlfUtils.searchFeatureCollectionForWords
444+
*
445+
* @param {Array.<ol.Feature>} stringFeatures - Array of features containing text information
446+
* @param {string} value - Search term
447+
* @returns {Array.<ol.Feature>|undefined} Array of OpenLayers features containing found words
448+
* @see dlfUtils.searchFeatureCollectionForWords
449+
*/
450+
dlfViewer.prototype.searchFeatures = function(stringFeatures, value) {
451+
return dlfUtils.searchFeatureCollectionForWords(stringFeatures, value);
452+
};
453+
442454
/**
443455
* Displays highlight words
444456
*/
@@ -491,23 +503,23 @@ dlfViewer.prototype.displayHighlightWord = function(highlightWords = null) {
491503
}
492504

493505
if (this.highlightWords !== null) {
494-
var self = this;
495-
var values = decodeURIComponent(this.highlightWords).split(';');
506+
const self = this;
507+
const values = decodeURIComponent(this.highlightWords).split(';');
496508

497509
$.when.apply($, this.fulltextsLoaded_)
498-
.done(function (fulltextData, fulltextDataImageTwo) {
499-
var stringFeatures = [];
510+
.done((fulltextData, fulltextDataImageTwo) => {
511+
const stringFeatures = [];
500512

501-
[fulltextData, fulltextDataImageTwo].forEach(function (data) {
513+
[fulltextData, fulltextDataImageTwo].forEach(data => {
502514
if (data !== undefined) {
503515
Array.prototype.push.apply(stringFeatures, data.getStringFeatures());
504516
}
505517
});
506518

507-
values.forEach(function(value) {
508-
var features = dlfUtils.searchFeatureCollectionForCoordinates(stringFeatures, value);
519+
values.forEach((value) => {
520+
const features = this.searchFeatures(stringFeatures, value);
509521
if (features !== undefined) {
510-
for (var i = 0; i < features.length; i++) {
522+
for (let i = 0; i < features.length; i++) {
511523
self.highlightLayer.getSource().addFeatures([features[i]]);
512524
}
513525
}

Resources/Public/JavaScript/PageView/Utility.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,13 +646,31 @@ dlfUtils.scaleToImageSize = function (features, imageObj, width, height, optOffs
646646
return features;
647647
};
648648

649+
/**
650+
* Search a feature collection for a feature with the given coordinates
651+
* @param {Array.<ol.Feature>} featureCollection
652+
* @param {string} coordinates
653+
* @return {Array.<ol.Feature>|undefined}
654+
*/
655+
dlfUtils.searchFeatureCollectionForCoordinates = function (featureCollection, coordinates) {
656+
var features = [];
657+
featureCollection.forEach(function (ft) {
658+
if (ft.get('fulltext') !== undefined) {
659+
if (ft.getId() === coordinates) {
660+
features.push(ft);
661+
}
662+
}
663+
});
664+
return features.length > 0 ? features : undefined;
665+
};
666+
649667
/**
650668
* Search a feature collection for a feature with the given word in its fulltext
651669
* @param {Array.<ol.Feature>} featureCollection
652670
* @param {string} word for highlighting
653671
* @returns {Array.<ol.Feature>|undefined}
654672
*/
655-
dlfUtils.searchFeatureCollectionForCoordinates = function (featureCollection, word) {
673+
dlfUtils.searchFeatureCollectionForWords = function (featureCollection, word) {
656674
var features = [];
657675
featureCollection.forEach(function (ft) {
658676
if (ft.values_.fulltext !== undefined) {

0 commit comments

Comments
 (0)