@abi-software/flatmap-viewer 2.5.4 → 2.5.5
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/interactions.js +32 -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.5.
|
|
41
|
+
* ``npm install @abi-software/flatmap-viewer@2.5.5``
|
|
42
42
|
|
|
43
43
|
Documentation
|
|
44
44
|
-------------
|
package/package.json
CHANGED
package/src/interactions.js
CHANGED
|
@@ -99,6 +99,9 @@ function expandBounds(bbox1, bbox2, padding)
|
|
|
99
99
|
|
|
100
100
|
function labelPosition(feature)
|
|
101
101
|
{
|
|
102
|
+
if (feature.geometry.type === 'Point') {
|
|
103
|
+
return feature.geometry.coordinates
|
|
104
|
+
}
|
|
102
105
|
const polygon = feature.geometry.coordinates;
|
|
103
106
|
// Rough heuristic. Area is in km^2; below appears to be good enough.
|
|
104
107
|
const precision = ('area' in feature.properties)
|
|
@@ -255,6 +258,9 @@ export class UserInteractions
|
|
|
255
258
|
}
|
|
256
259
|
}
|
|
257
260
|
|
|
261
|
+
// Initialise map annotation
|
|
262
|
+
this.__setupAnnotation()
|
|
263
|
+
|
|
258
264
|
// Add an initially hidden tool for drawing on the map.
|
|
259
265
|
this.#annotationDrawControl = new AnnotationDrawControl(flatmap, false)
|
|
260
266
|
this._map.addControl(this.#annotationDrawControl)
|
|
@@ -358,6 +364,32 @@ export class UserInteractions
|
|
|
358
364
|
}
|
|
359
365
|
}
|
|
360
366
|
|
|
367
|
+
__setupAnnotation()
|
|
368
|
+
//=================
|
|
369
|
+
{
|
|
370
|
+
// Relate external annotation identifiers to map (GeoJSON) ids
|
|
371
|
+
this.__featureIdToMapId = new Map([...this._flatmap.annotations.entries()]
|
|
372
|
+
.map(idAnn => [idAnn[1].id, idAnn[0]]))
|
|
373
|
+
// Flag features that have annotations
|
|
374
|
+
for (const mapId of this.__featureIdToMapId.values()) {
|
|
375
|
+
const feature = this.mapFeature(mapId)
|
|
376
|
+
if (feature !== undefined) {
|
|
377
|
+
this._map.setFeatureState(feature, { 'map-annotation': true })
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
setFeatureAnnotated(featureId)
|
|
383
|
+
//============================
|
|
384
|
+
{
|
|
385
|
+
// External feature id to map's GeoJSON id
|
|
386
|
+
const mapId = this.__featureIdToMapId.get(featureId)
|
|
387
|
+
const feature = this.mapFeature(mapId)
|
|
388
|
+
if (feature !== undefined) {
|
|
389
|
+
this._map.setFeatureState(feature, { 'annotated': true })
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
361
393
|
#setPaint(options)
|
|
362
394
|
//================
|
|
363
395
|
{
|