Skip to content

Commit fc386c5

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 4b3a130 commit fc386c5

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
@@ -734,6 +734,18 @@ dlfViewer.prototype.createControl = function(controlName, layers) {
734734
}
735735
};
736736

737+
/**
738+
* Forwards the search to dlfUtils.searchFeatureCollectionForWords
739+
*
740+
* @param {Array.<ol.Feature>} stringFeatures - Array of features containing text information
741+
* @param {string} value - Search term
742+
* @returns {Array.<ol.Feature>|undefined} Array of OpenLayers features containing found words
743+
* @see dlfUtils.searchFeatureCollectionForWords
744+
*/
745+
dlfViewer.prototype.searchFeatures = function(stringFeatures, value) {
746+
return dlfUtils.searchFeatureCollectionForWords(stringFeatures, value);
747+
};
748+
737749
/**
738750
* Displays highlight words
739751
*/
@@ -786,23 +798,23 @@ dlfViewer.prototype.displayHighlightWord = function(highlightWords = null) {
786798
}
787799

788800
if (this.highlightWords !== null) {
789-
var self = this;
790-
var values = decodeURIComponent(this.highlightWords).split(';');
801+
const self = this;
802+
const values = decodeURIComponent(this.highlightWords).split(';');
791803

792804
$.when.apply($, this.fulltextsLoaded_)
793-
.done(function (fulltextData, fulltextDataImageTwo) {
794-
var stringFeatures = [];
805+
.done((fulltextData, fulltextDataImageTwo) => {
806+
const stringFeatures = [];
795807

796-
[fulltextData, fulltextDataImageTwo].forEach(function (data) {
808+
[fulltextData, fulltextDataImageTwo].forEach(data => {
797809
if (data !== undefined) {
798810
Array.prototype.push.apply(stringFeatures, data.getStringFeatures());
799811
}
800812
});
801813

802-
values.forEach(function(value) {
803-
var features = dlfUtils.searchFeatureCollectionForCoordinates(stringFeatures, value);
814+
values.forEach((value) => {
815+
const features = this.searchFeatures(stringFeatures, value);
804816
if (features !== undefined) {
805-
for (var i = 0; i < features.length; i++) {
817+
for (let i = 0; i < features.length; i++) {
806818
self.highlightLayer.getSource().addFeatures([features[i]]);
807819
}
808820
}

Resources/Public/JavaScript/PageView/Utility.js

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

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

0 commit comments

Comments
 (0)