qgis / qwc2-demo-app

QWC2 demo application
Other
243 stars 155 forks source link

custom searchProvider does not navigate/zoom to feature #451

Closed w0pr closed 10 months ago

w0pr commented 1 year ago

I am using the docker services from https://github.com/qwc-services/qwc-docker

I implemented a custom searchProvider according to https://qwc-services.github.io/setup/viewer/qwc_configuration/#search-providers by adding searchProvider.js to volumes/qwc2/assets/, and configured the searchProvider in tenantConfig.json (in the defaultSearchProviders, in addition to the "coordinates" search provider).

The onSearch function does get called and I return a result like below with hardcoded values (callback gets called with results), which I later in full implementation will extract from the results of a filtered WMS query to the OGC service (this already works, although I still have to figure out where to dynamically get the list of layers for LAYERS, QUERYLAYERS and FILTER parameters without just passing them as cfgParams to onSearch via the entry in tenantConfig.json).

The getResultGeometry function never gets called (I hardcoded values there as well).

I uncommented the "geometry"property in items array for now, it also does not work with it.

image searchProviders.js.txt

But QWC2 client does not navigate/zoom to feature and the spinner in the search box just keeps spinning and shows no results.

Debugging into SearchBox.jsx shows that pendingSearches is never empty(line 470), and therefore single feature in result is never selected, there is an searchid entry "themes" that persists in pendingSearches, I guess this is from the selector provider from here "qwc2/selectors/searchproviders.js". I then set searchThemes = false in config.json, this will get rid of the "themes" provider, but still line 479 of SearchBox.jsx: this.selectProviderResult(uniqueResults[1][0].items[0], uniqueResult[0]);

will never be reached.

image

What am I doing wrong?

manisandro commented 1 year ago

Can you post the full search provider code (in copyable text) and your themes.json?

w0pr commented 1 year ago

There is no themes.json, I was under the impression that this would either be be generated by the themesConfig part of tenantConfig.json or not needed when using QGS projects from /scan folder. At the moment, I configured searchProvider in defaultSearchProviders part of tenentConfig.json.

searchProviders.js.txt tenantConfig.json.txt

manisandro commented 1 year ago

The themes.json can be obtained via http://localhost:8088/themes.json (resp. replace localhost:8088 with your viewer base address).

manisandro commented 1 year ago

Ok got it and comment deleted.

w0pr commented 1 year ago

While debugging into SearchBox.jsx, it seems that results are never shown, because this.state.searchSession is null (line 464). image

w0pr commented 1 year ago

While debugging into SearchBox.jsx, it seems that results are never shown, because this.state.searchSession is null (line 464). image

thanks, @manisandro for https://github.com/qgis/qwc2/commit/3661d032596c0c60c776f626a3f3cb17204b9a8a I'll give it another try and report back...

manisandro commented 10 months ago

There have been various fixes/improvements regarding custom search providers in the SearchBox, assuming fixed, please reopen if still relevant.