@abi-software/flatmap-viewer 2.2.2-beta.2 → 2.2.2-beta.4

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 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.2``
41
+ * ``npm install @abi-software/flatmap-viewer@2.2.2-beta.4``
42
42
 
43
43
  Documentation
44
44
  -------------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abi-software/flatmap-viewer",
3
- "version": "2.2.2-beta.2",
3
+ "version": "2.2.2-beta.4",
4
4
  "description": "Flatmap viewer using Maplibre GL",
5
5
  "repository": "https://github.com/AnatomicMaps/flatmap-viewer.git",
6
6
  "main": "src/main.js",
@@ -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
- search(text)
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
- return this.__searchIndex.search(text);
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
- return new SearchResults(results.map(result => this._featureIds[result.id]));
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(featureIds)
209
+ constructor(results)
197
210
  {
198
- this.__featureIds = featureIds;
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
  //==============================================================================
package/src/styling.js CHANGED
@@ -225,7 +225,9 @@ export class FeatureBorderLayer extends VectorStyleLayer
225
225
  ...super.style(),
226
226
  'type': 'line',
227
227
  'filter': [
228
- '==', '$type', 'Polygon'
228
+ 'all',
229
+ ['==', '$type', 'Polygon'],
230
+ ['has', 'id']
229
231
  ],
230
232
  'paint': this.paintStyle(options)
231
233
  };
package/src/editor.js DELETED
@@ -1,198 +0,0 @@
1
- import { Bezier } from "bezier-js";
2
-
3
-
4
- class BezierCurve
5
- {
6
- constructor(id, ...points) {
7
- this.__id = id;
8
- this.__bezier = new Bezier(...points);
9
- }
10
-
11
- asGeoJSON(samples=100)
12
- {
13
- const coords = [];
14
- for (let ts = 0; ts <= samples; ts++) {
15
- const pt = this.__bezier.get(float(ts)/float(samples));
16
- coords.push([pt.x, pt.y]);
17
- }
18
- return {
19
- 'type': 'Feature',
20
- 'geometry': {
21
- 'type': 'LineString',
22
- 'coordinates': coords
23
- },
24
- 'properties': {
25
- 'bezier': this.__id
26
- }
27
- };
28
- }
29
-
30
- asPoints()
31
- {
32
- const geojson = [];
33
- for (const n of [0, 1, 2, 3]) {
34
- const pt = this.__bezier.points[n];
35
- geojson.push({
36
- 'type': 'Feature',
37
- 'geometry': {
38
- 'type': 'Point',
39
- 'coordinates': [pt.x, pt.y]
40
- },
41
- 'properties': {
42
- 'bezier': this.__id,
43
- 'point': n
44
- }
45
- });
46
- }
47
- return geojson;
48
- }
49
- }
50
-
51
-
52
- export class NetworkEditor
53
- {
54
- constructor(flatmap)
55
- {
56
- this.__map = flatmap.map;
57
- this.__canvas = this.__map.getCanvasContainer();
58
-
59
- this.__geojson = { // lines and points as separate sources???
60
- 'type': 'FeatureCollection',
61
- 'features': [
62
- {
63
- 'type': 'Feature',
64
- 'geometry': {
65
- 'type': 'Point',
66
- 'coordinates': [0, 0]
67
- },
68
- 'properties': {
69
- 'id': 0
70
- }
71
- }
72
- ]
73
- };
74
-
75
- // Add a single point to the map
76
- this.__map.addSource('curves', {
77
- 'type': 'geojson',
78
- 'data': this.__geojson
79
- });
80
-
81
- this.__map.addLayer({
82
- 'id': 'lines',
83
- 'type': 'line',
84
- 'source': 'curves',
85
- 'paint': {
86
- 'line-color': '#3887be'
87
- }
88
- });
89
- this.__map.addLayer({
90
- 'id': 'points',
91
- 'type': 'circle',
92
- 'source': 'curves',
93
- 'paint': {
94
- 'circle-radius': 10,
95
- 'circle-color': '#3887be'
96
- }
97
- });
98
-
99
- this.__currentPoint = null;
100
-
101
- this.__map.on('mouseenter', this.mouseEnter.bind(this));
102
- this.__map.on('mouseleave', this.mouseLeave.bind(this));
103
- this.__map.on('mousedown', this.mouseDown.bind(this));
104
- this.__map.on('touchstart', this.touchStart.bind(this));
105
- }
106
-
107
- addPoint(coords)
108
- {
109
- const nextId = this.__geojson.features.length;
110
- this.__geojson.features.push({
111
- 'type': 'Feature',
112
- 'geometry': {
113
- 'type': 'Point',
114
- 'coordinates': coords
115
- },
116
- 'properties': {
117
- 'id': nextId
118
- }
119
- });
120
- this.__map.getSource('curves').setData(this.__geojson);
121
- return nextId;
122
- }
123
-
124
- mouseEnter(e) {
125
- console.log('Mouse enter...');
126
-
127
- this.__map.setPaintProperty('lines', 'line-color', '#3bb2d0');
128
- this.__map.setPaintProperty('points', 'circle-color', '#3bb2d0');
129
- this.__canvas.style.cursor = 'move';
130
- }
131
-
132
-
133
- mouseLeave(e) {
134
- this.__map.setPaintProperty('lines', 'line-color', '#3887be');
135
- this.__map.setPaintProperty('points', 'circle-color', '#3887be');
136
- this.__canvas.style.cursor = '';
137
- }
138
-
139
-
140
- mouseDown(e) {
141
- console.log('Mouse down...')
142
- // Prevent the default map drag behavior.
143
- e.preventDefault();
144
-
145
-
146
- const features = this.__map.queryRenderedFeatures(e.point, {'layers': ['lines', 'points']});
147
- if (features.length === 0) {
148
- const coords = e.lngLat;
149
- this.__currentPoint = this.addPoint([coords.lng, coords.lat]);
150
- } else {
151
- const currentPoint = features[0].properties.id;
152
- if (this.__currentPoint === null) {
153
- this.__currentPoint = currentPoint;
154
- } else if (this.__currentPoint === currentPoint) {
155
- this.__currentPoint = null;
156
- }
157
- }
158
-
159
- this.__canvas.style.cursor = 'grab';
160
-
161
- this.__map.on('mousemove', this.onMove.bind(this));
162
- this.__map.once('mouseup', this.onUp.bind(this));
163
-
164
- }
165
-
166
- touchStart(e) {
167
- if (e.points.length !== 1) return;
168
-
169
- // Prevent the default map drag behavior.
170
- e.preventDefault();
171
-
172
- this.__map.on('touchmove', this.onMove.bind(this));
173
- this.__map.once('touchend', this.onUp.bind(this));
174
- }
175
-
176
- onMove(e) {
177
- console.log('Mouse move...')
178
-
179
- // Set a UI indicator for dragging.
180
- this.__canvas.style.cursor = 'grabbing'; // ????
181
-
182
- if (this.__currentPoint !== null) {
183
- const coords = e.lngLat;
184
- this.__geojson.features[this.__currentPoint].geometry.coordinates = [coords.lng, coords.lat];
185
- this.__map.getSource('curves').setData(this.__geojson);
186
- }
187
- }
188
-
189
- onUp(e) {
190
- console.log('End draw at', e.lngLat)
191
-
192
- this.__canvas.style.cursor = '';
193
-
194
- // Unbind mouse/touch events
195
- this.__map.off('mousemove', this.onMove.bind(this));
196
- this.__map.off('touchmove', this.onMove.bind(this));
197
- }
198
- }