@@ -24,7 +24,6 @@ import ClientConfiguration from 'clientConfig';
24
24
import _groupBy from 'lodash/groupBy' ;
25
25
import _isNil from 'lodash/isNil' ;
26
26
27
- import { getUid } from 'ol' ;
28
27
import {
29
28
Extent as OlExtent
30
29
} from 'ol/extent' ;
@@ -50,6 +49,10 @@ import useMap from '@terrestris/react-geo/dist/Hook/useMap';
50
49
import SearchResultsPanel , {
51
50
Category as ResultCategory
52
51
} from '@terrestris/react-geo/dist/Panel/SearchResultsPanel/SearchResultsPanel' ;
52
+ import {
53
+ WmsLayer ,
54
+ isWmsLayer
55
+ } from '@terrestris/react-geo/dist/Util/typeUtils' ;
53
56
54
57
import {
55
58
SearchConfig
@@ -382,8 +385,26 @@ export const MultiSearch: React.FC<MultiSearchProps> = ({
382
385
if ( dataSearchResults ?. length > 0 ) {
383
386
384
387
const wktFormat = new OlFormatWKT ( ) ;
385
- // 1. group by category
386
- const categories = _groupBy ( dataSearchResults , res => res ?. category [ 0 ] ) ;
388
+
389
+ // 1. group by category or layer title
390
+ let categories ;
391
+ if ( ClientConfiguration . search ?. groupByCategory ) {
392
+ categories = _groupBy ( dataSearchResults , res => res ?. category [ 0 ] ) ;
393
+ } else {
394
+ const layers = map . getAllLayers ( ) . filter ( l => l . get ( 'searchable' ) ) ;
395
+ const resultsWithLayerName = dataSearchResults . map ( result => {
396
+ const layerTitle = layers . filter ( l => isWmsLayer ( l ) )
397
+ . find ( ( l ) => ( l as WmsLayer ) . getSource ( ) ?. getParams ( ) ?. LAYERS === result . featureType [ 0 ] )
398
+ ?. get ( 'name' ) ;
399
+
400
+ return {
401
+ layerTitle,
402
+ ...result
403
+ } as DataSearchResult ;
404
+ } ) ;
405
+ categories = _groupBy ( resultsWithLayerName , res => res ?. layerTitle ) ;
406
+ }
407
+
387
408
// 2. build features
388
409
Object . keys ( categories ) . forEach ( category => {
389
410
const features = categories [ category ] . map ( dsResult => {
0 commit comments