@abi-software/flatmap-viewer 2.2.2-beta.1 → 2.2.2-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.rst +1 -1
- package/package.json +1 -1
- package/src/flatmap-viewer.js +18 -4
- package/src/search.js +22 -3
- package/static/flatmap-viewer.css +4 -0
package/README.rst
CHANGED
|
@@ -38,7 +38,7 @@ The map server endpoint is specified as ``MAP_ENDPOINT`` in ``src/main.js``. It
|
|
|
38
38
|
Package Installation
|
|
39
39
|
====================
|
|
40
40
|
|
|
41
|
-
* ``npm install @abi-software/flatmap-viewer@2.2.2-beta.
|
|
41
|
+
* ``npm install @abi-software/flatmap-viewer@2.2.2-beta.3``
|
|
42
42
|
|
|
43
43
|
Documentation
|
|
44
44
|
-------------
|
package/package.json
CHANGED
package/src/flatmap-viewer.js
CHANGED
|
@@ -36,7 +36,7 @@ import '../static/flatmap-viewer.css';
|
|
|
36
36
|
import {MapServer} from './mapserver.js';
|
|
37
37
|
import {MinimapControl} from './minimap.js';
|
|
38
38
|
import {NavigationControl} from './controls.js';
|
|
39
|
-
import {SearchIndex} from './search.js';
|
|
39
|
+
import {SearchIndex, SearchResults} from './search.js';
|
|
40
40
|
import {UserInteractions} from './interactions.js';
|
|
41
41
|
|
|
42
42
|
import * as images from './images.js';
|
|
@@ -921,10 +921,24 @@ class FlatMap
|
|
|
921
921
|
|
|
922
922
|
//==========================================================================
|
|
923
923
|
|
|
924
|
-
|
|
925
|
-
|
|
924
|
+
/**
|
|
925
|
+
* Find features with labels or terms matching ``text``.
|
|
926
|
+
*
|
|
927
|
+
* @param {string} text The text to search
|
|
928
|
+
* @param {boolean} [auto=false] If ``true`` return suggestions of text to search for.
|
|
929
|
+
* @return Either a ``Searchresults`` object with fields of ``featureIds`` and ``results``,
|
|
930
|
+
* where ``results`` has ``featureId``, ``score``, ``terms`` and ``text`` fields,
|
|
931
|
+
* or a ``Suggestion`` object containing suggested matches
|
|
932
|
+
* (see https://lucaong.github.io/minisearch/modules/_minisearch_.html#suggestion).
|
|
933
|
+
*/
|
|
934
|
+
search(text, auto=false)
|
|
935
|
+
//======================
|
|
926
936
|
{
|
|
927
|
-
|
|
937
|
+
if (auto) {
|
|
938
|
+
return this.__searchIndex.auto_suggest(text);
|
|
939
|
+
} else {
|
|
940
|
+
return this.__searchIndex.search(text);
|
|
941
|
+
}
|
|
928
942
|
}
|
|
929
943
|
|
|
930
944
|
clearSearchResults()
|
package/src/search.js
CHANGED
|
@@ -173,6 +173,12 @@ export class SearchIndex
|
|
|
173
173
|
this._;
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
+
auto_suggest(text)
|
|
177
|
+
//================
|
|
178
|
+
{
|
|
179
|
+
return this._searchEngine.autoSuggest(text, {prefix: true});
|
|
180
|
+
}
|
|
181
|
+
|
|
176
182
|
search(text)
|
|
177
183
|
//==========
|
|
178
184
|
{
|
|
@@ -185,7 +191,14 @@ export class SearchIndex
|
|
|
185
191
|
} else if (text.length > 1) {
|
|
186
192
|
results = this._searchEngine.search(text, {prefix: true});
|
|
187
193
|
}
|
|
188
|
-
|
|
194
|
+
const featureResults = results.map(r => {
|
|
195
|
+
return {
|
|
196
|
+
featureId: this._featureIds[r.id],
|
|
197
|
+
score: r.score,
|
|
198
|
+
terms: r.terms,
|
|
199
|
+
text: r.text
|
|
200
|
+
}});
|
|
201
|
+
return new SearchResults(featureResults);
|
|
189
202
|
}
|
|
190
203
|
}
|
|
191
204
|
|
|
@@ -193,15 +206,21 @@ export class SearchIndex
|
|
|
193
206
|
|
|
194
207
|
class SearchResults
|
|
195
208
|
{
|
|
196
|
-
constructor(
|
|
209
|
+
constructor(results)
|
|
197
210
|
{
|
|
198
|
-
this.
|
|
211
|
+
this.__results = results.sort((a, b) => (b.score - a.score));
|
|
212
|
+
this.__featureIds = results.map(r => r.featureId);
|
|
199
213
|
}
|
|
200
214
|
|
|
201
215
|
get featureIds()
|
|
202
216
|
{
|
|
203
217
|
return this.__featureIds;
|
|
204
218
|
}
|
|
219
|
+
|
|
220
|
+
get results()
|
|
221
|
+
{
|
|
222
|
+
return this.__results;
|
|
223
|
+
}
|
|
205
224
|
}
|
|
206
225
|
|
|
207
226
|
//==============================================================================
|