@abi-software/flatmap-viewer 2.5.8 → 2.5.10
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/controls/annotation.js +34 -3
- package/src/flatmap-viewer.js +34 -1
- package/src/interactions.js +32 -5
- package/src/main.js +1 -1
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.5.
|
|
41
|
+
* ``npm install @abi-software/flatmap-viewer@2.5.10``
|
|
42
42
|
|
|
43
43
|
Documentation
|
|
44
44
|
-------------
|
package/package.json
CHANGED
|
@@ -78,6 +78,7 @@ export class AnnotationDrawControl
|
|
|
78
78
|
keybindings: true
|
|
79
79
|
})
|
|
80
80
|
this.__map = null
|
|
81
|
+
this.__inDrawing = false
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
onAdd(map)
|
|
@@ -96,10 +97,11 @@ export class AnnotationDrawControl
|
|
|
96
97
|
e.preventDefault();
|
|
97
98
|
}
|
|
98
99
|
}, false)
|
|
99
|
-
map.on('draw.modechange', this.
|
|
100
|
+
map.on('draw.modechange', this.modeChangedEvent.bind(this))
|
|
100
101
|
map.on('draw.create', this.createdFeature.bind(this))
|
|
101
102
|
map.on('draw.delete', this.deletedFeature.bind(this))
|
|
102
103
|
map.on('draw.update', this.updatedFeature.bind(this))
|
|
104
|
+
map.on('draw.selectionchange', this.selectionChangedEvent.bind(this))
|
|
103
105
|
this.show(this.__visible)
|
|
104
106
|
return this.__container
|
|
105
107
|
}
|
|
@@ -189,6 +191,8 @@ export class AnnotationDrawControl
|
|
|
189
191
|
{
|
|
190
192
|
const feature = this.#cleanFeature(event)
|
|
191
193
|
if (feature) {
|
|
194
|
+
// specify updated callback type, either `move` or `change_coordinates`
|
|
195
|
+
feature.action = event.action
|
|
192
196
|
if (this.__uncommittedFeatureIds.has(feature.id)) {
|
|
193
197
|
// Ignore updates on an uncommitted create or update
|
|
194
198
|
} else {
|
|
@@ -197,13 +201,27 @@ export class AnnotationDrawControl
|
|
|
197
201
|
}
|
|
198
202
|
}
|
|
199
203
|
|
|
200
|
-
|
|
201
|
-
|
|
204
|
+
modeChangedEvent(event)
|
|
205
|
+
//=====================
|
|
202
206
|
{
|
|
203
207
|
// Used as a flag to indicate the feature mode
|
|
208
|
+
this.__inDrawing = (event.mode.startsWith('draw'))
|
|
204
209
|
this.#sendEvent('modeChanged', event)
|
|
205
210
|
}
|
|
206
211
|
|
|
212
|
+
selectionChangedEvent(event)
|
|
213
|
+
//==========================
|
|
214
|
+
{
|
|
215
|
+
// Used to indicate a feature is selected or deselected
|
|
216
|
+
this.#sendEvent('selectionChanged', event)
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
inDrawingMode()
|
|
220
|
+
//=============
|
|
221
|
+
{
|
|
222
|
+
return this.__inDrawing
|
|
223
|
+
}
|
|
224
|
+
|
|
207
225
|
commitEvent(event)
|
|
208
226
|
//================
|
|
209
227
|
{
|
|
@@ -252,6 +270,12 @@ export class AnnotationDrawControl
|
|
|
252
270
|
this.__draw.deleteAll()
|
|
253
271
|
}
|
|
254
272
|
|
|
273
|
+
trashFeature()
|
|
274
|
+
//============
|
|
275
|
+
{
|
|
276
|
+
this.__draw.trash()
|
|
277
|
+
}
|
|
278
|
+
|
|
255
279
|
addFeature(feature)
|
|
256
280
|
//=================
|
|
257
281
|
{
|
|
@@ -266,6 +290,13 @@ export class AnnotationDrawControl
|
|
|
266
290
|
{
|
|
267
291
|
return this.__draw.get(feature.id) || null
|
|
268
292
|
}
|
|
293
|
+
|
|
294
|
+
changeMode(type)
|
|
295
|
+
//===============
|
|
296
|
+
{
|
|
297
|
+
// Change the mode directly without listening to modes callback
|
|
298
|
+
this.__draw.changeMode(type.mode, type.options)
|
|
299
|
+
}
|
|
269
300
|
}
|
|
270
301
|
|
|
271
302
|
//==============================================================================
|
package/src/flatmap-viewer.js
CHANGED
|
@@ -1025,7 +1025,11 @@ class FlatMap
|
|
|
1025
1025
|
'models',
|
|
1026
1026
|
'source',
|
|
1027
1027
|
'taxons',
|
|
1028
|
-
'hyperlinks'
|
|
1028
|
+
'hyperlinks',
|
|
1029
|
+
'completeness',
|
|
1030
|
+
'missing-nodes',
|
|
1031
|
+
'alert',
|
|
1032
|
+
'biological-sex'
|
|
1029
1033
|
];
|
|
1030
1034
|
const jsonProperties = [
|
|
1031
1035
|
'hyperlinks'
|
|
@@ -1122,6 +1126,17 @@ class FlatMap
|
|
|
1122
1126
|
}
|
|
1123
1127
|
}
|
|
1124
1128
|
|
|
1129
|
+
/**
|
|
1130
|
+
* Fire trash to enter `updated` or `deleted` feature event.
|
|
1131
|
+
*/
|
|
1132
|
+
trashAnnotationFeature()
|
|
1133
|
+
//======================
|
|
1134
|
+
{
|
|
1135
|
+
if (this._userInteractions) {
|
|
1136
|
+
this._userInteractions.trashAnnotationFeature()
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1125
1140
|
/**
|
|
1126
1141
|
* Add a drawn feature to the annotation drawing tool.
|
|
1127
1142
|
*
|
|
@@ -1155,6 +1170,24 @@ class FlatMap
|
|
|
1155
1170
|
}
|
|
1156
1171
|
}
|
|
1157
1172
|
|
|
1173
|
+
/**
|
|
1174
|
+
* Changes draw to another mode. The mode argument must be one of the following:
|
|
1175
|
+
* `simple_select`, `direct_select`, `draw_line_string`,
|
|
1176
|
+
* `draw_polygon` or `draw_point`. Options is accepted in first three modes.
|
|
1177
|
+
* More details in mapbox-gl-draw github repository.
|
|
1178
|
+
*
|
|
1179
|
+
* @param type {Object} The object
|
|
1180
|
+
* @param type.mode {string} Either ``simple_select``, ``direct_select``, etc
|
|
1181
|
+
* @param type.options {Object} Feature id(s) object.
|
|
1182
|
+
*/
|
|
1183
|
+
changeAnnotationDrawMode(type)
|
|
1184
|
+
//============================
|
|
1185
|
+
{
|
|
1186
|
+
if (this._userInteractions) {
|
|
1187
|
+
this._userInteractions.changeAnnotationDrawMode(type)
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1158
1191
|
/**
|
|
1159
1192
|
* Generate a callback as a result of some event with a flatmap feature.
|
|
1160
1193
|
*
|
package/src/interactions.js
CHANGED
|
@@ -333,6 +333,14 @@ export class UserInteractions
|
|
|
333
333
|
}
|
|
334
334
|
}
|
|
335
335
|
|
|
336
|
+
inDrawingAnnotationMode()
|
|
337
|
+
//=======================
|
|
338
|
+
{
|
|
339
|
+
if (this.#annotationDrawControl) {
|
|
340
|
+
return this.#annotationDrawControl.inDrawingMode()
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
336
344
|
commitAnnotationEvent(event)
|
|
337
345
|
//==========================
|
|
338
346
|
{
|
|
@@ -365,6 +373,14 @@ export class UserInteractions
|
|
|
365
373
|
}
|
|
366
374
|
}
|
|
367
375
|
|
|
376
|
+
trashAnnotationFeature()
|
|
377
|
+
//======================
|
|
378
|
+
{
|
|
379
|
+
if (this.#annotationDrawControl) {
|
|
380
|
+
this.#annotationDrawControl.trashFeature()
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
368
384
|
addAnnotationFeature(feature)
|
|
369
385
|
//===========================
|
|
370
386
|
{
|
|
@@ -381,6 +397,14 @@ export class UserInteractions
|
|
|
381
397
|
}
|
|
382
398
|
}
|
|
383
399
|
|
|
400
|
+
changeAnnotationDrawMode(type)
|
|
401
|
+
//=============================
|
|
402
|
+
{
|
|
403
|
+
if (this.#annotationDrawControl) {
|
|
404
|
+
this.#annotationDrawControl.changeMode(type)
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
384
408
|
__setupAnnotation()
|
|
385
409
|
//=================
|
|
386
410
|
{
|
|
@@ -1185,22 +1209,25 @@ export class UserInteractions
|
|
|
1185
1209
|
this.unselectFeatures();
|
|
1186
1210
|
return;
|
|
1187
1211
|
}
|
|
1188
|
-
const
|
|
1189
|
-
const clickedDrawnFeature = clickedFeatures.filter((f)
|
|
1212
|
+
const inDrawing = this.inDrawingAnnotationMode()
|
|
1213
|
+
const clickedDrawnFeature = clickedFeatures.filter((f) => !f.id)[0];
|
|
1214
|
+
const clickedFeature = clickedFeatures.filter((f) => f.id)[0];
|
|
1190
1215
|
this.selectionEvent_(event.originalEvent, clickedFeature);
|
|
1191
1216
|
if (this._modal) {
|
|
1192
1217
|
// Remove tooltip, reset active features, etc
|
|
1193
1218
|
this.__resetFeatureDisplay();
|
|
1194
1219
|
this.unselectFeatures();
|
|
1195
1220
|
this.__clearModal();
|
|
1196
|
-
} else if (
|
|
1221
|
+
} else if (clickedDrawnFeature && !inDrawing) {
|
|
1222
|
+
// When feature and drawn feature are coinciding, click on annotation layer by default
|
|
1223
|
+
// While in drawing, DISABLE 'click' event on annotation layer
|
|
1224
|
+
this.__featureEvent('click', clickedDrawnFeature);
|
|
1225
|
+
} else if (clickedFeature) {
|
|
1197
1226
|
this.__lastClickLngLat = event.lngLat;
|
|
1198
1227
|
this.__featureEvent('click', clickedFeature);
|
|
1199
1228
|
if ('properties' in clickedFeature && 'hyperlink' in clickedFeature.properties) {
|
|
1200
1229
|
window.open(clickedFeature.properties.hyperlink, '_blank');
|
|
1201
1230
|
}
|
|
1202
|
-
} else if (clickedDrawnFeature !== undefined) {
|
|
1203
|
-
this.__featureEvent('click', clickedDrawnFeature);
|
|
1204
1231
|
}
|
|
1205
1232
|
}
|
|
1206
1233
|
|
package/src/main.js
CHANGED
|
@@ -64,7 +64,7 @@ class DrawControl
|
|
|
64
64
|
//================
|
|
65
65
|
{
|
|
66
66
|
console.log(event)
|
|
67
|
-
if (this._idField) {
|
|
67
|
+
if (this._idField && event.type !== 'modeChanged' && event.type !== 'selectionChanged') {
|
|
68
68
|
this._idField.innerText = `Annotation ${event.type}, Id: ${event.feature.id}`
|
|
69
69
|
this._lastEvent = event
|
|
70
70
|
}
|