@geogirafe/lib-geoportal 1.0.2194808337 → 1.0.2201757187
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/assets/i18n/de.json +5 -0
- package/assets/i18n/en.json +5 -0
- package/assets/i18n/fr.json +5 -0
- package/assets/i18n/it.json +5 -0
- package/assets/icons/arrow.svg +1 -1
- package/components/drawing/drawingFeature.js +3 -8
- package/components/drawing/olDrawing.d.ts +1 -2
- package/components/drawing/olDrawing.js +16 -33
- package/components/main.d.ts +1 -0
- package/components/main.js +1 -0
- package/components/map/component.d.ts +2 -1
- package/components/map/component.js +19 -12
- package/components/selectiongrid/component.js +1 -0
- package/components/selectiongrid/tools/formatgridgeomvalue.js +3 -3
- package/components/selectiontool/component.d.ts +50 -0
- package/components/selectiontool/component.js +243 -0
- package/models/main.d.ts +1 -0
- package/models/selection.d.ts +12 -0
- package/models/selection.js +14 -0
- package/package.json +1 -1
- package/templates/index.html +11 -0
- package/templates/public/about.json +1 -1
- package/tools/app/geogirafeapp.js +2 -0
- package/tools/localfile/localfilemanager.js +2 -2
- package/tools/main.d.ts +2 -2
- package/tools/main.js +2 -2
- package/tools/share/serializers/selectionserializer.spec.js +2 -2
- package/tools/state/graphicalInterface.d.ts +1 -0
- package/tools/state/graphicalInterface.js +1 -0
- package/tools/state/mapManager.js +2 -2
- package/tools/state/objectselection.d.ts +4 -0
- package/tools/state/objectselection.js +3 -0
- package/tools/utils/olutils.d.ts +14 -2
- package/tools/utils/olutils.js +60 -3
- package/tools/utils/olutils.spec.js +3 -3
- package/tools/utils/utils.d.ts +10 -0
- package/tools/utils/utils.js +44 -11
package/assets/i18n/de.json
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
"about-panel": "About",
|
|
8
8
|
"Activate / Deactivate": "Aktivieren / Deaktivieren",
|
|
9
9
|
"Activate batch creation mode to draw multiple features without needing to reselect the tool": "Aktiviere den Batch-Modus um mehrere Formen zu zeichnen ohne das Werkzeug neu auszuwählen",
|
|
10
|
+
"add": "Hinzufügen",
|
|
10
11
|
"Add bookmark": "Lesezeichen hinzufügen",
|
|
11
12
|
"Add selected": "Auswahl hinzufügen",
|
|
12
13
|
"Add your first items": "Fügen Sie Inhalte hinzu:",
|
|
@@ -322,6 +323,7 @@
|
|
|
322
323
|
"recenter_map": "Karte neu zentrieren",
|
|
323
324
|
"record_video": "Video aufnehmen",
|
|
324
325
|
"Rectangle": "Rechteck",
|
|
326
|
+
"remove": "Entfernen",
|
|
325
327
|
"Remove all layers": "Alle Layer entfernen",
|
|
326
328
|
"Remove filter": "Filter entfernen",
|
|
327
329
|
"Remove group": "Gruppe entfernen",
|
|
@@ -329,6 +331,7 @@
|
|
|
329
331
|
"Remove Shape": "Zeichnung entfernen",
|
|
330
332
|
"Remove theme": "Thema entfernen",
|
|
331
333
|
"Remove Vertex": "Eckpunkt entfernen",
|
|
334
|
+
"replace": "Ersetzen",
|
|
332
335
|
"Report an error": "Einen Fehler melden",
|
|
333
336
|
"Request secure access": "Sicheren Zugang anfordern",
|
|
334
337
|
"Reset All": "Alle zurücksetzen",
|
|
@@ -363,6 +366,8 @@
|
|
|
363
366
|
"selectHighlightFillColor": "Auswahl Highlight Füllfarbe",
|
|
364
367
|
"selectHighlightStrokeColor": "Auswahl Highlight Strichfarbe",
|
|
365
368
|
"Selection": "Auswahl",
|
|
369
|
+
"selection-mode": "Selektionsmodus",
|
|
370
|
+
"selection-tool-panel": "Selektions-Tool",
|
|
366
371
|
"selectionComponent": "Komponente für Kartenauswahl",
|
|
367
372
|
"selectStrokeColor": "Auswahl Strichfarbe",
|
|
368
373
|
"Send": "Senden",
|
package/assets/i18n/en.json
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
"about-panel": "About",
|
|
8
8
|
"Activate / Deactivate": "Activate / Deactivate",
|
|
9
9
|
"Activate batch creation mode to draw multiple features without needing to reselect the tool": "Activate batch creation mode to draw multiple features without the needing to reselect the tool",
|
|
10
|
+
"add": "Add",
|
|
10
11
|
"Add bookmark": "Add bookmark",
|
|
11
12
|
"Add selected": "Add selected",
|
|
12
13
|
"Add your first items": "Add your first items",
|
|
@@ -323,6 +324,7 @@
|
|
|
323
324
|
"recenter_map": "Recenter the map",
|
|
324
325
|
"record_video": "Record video",
|
|
325
326
|
"Rectangle": "Rectangle",
|
|
327
|
+
"remove": "Remove",
|
|
326
328
|
"Remove all layers": "Remove all layers",
|
|
327
329
|
"Remove filter": "Remove filter",
|
|
328
330
|
"Remove group": "Remove group",
|
|
@@ -330,6 +332,7 @@
|
|
|
330
332
|
"Remove Shape": "Remove Shape",
|
|
331
333
|
"Remove theme": "Remove theme",
|
|
332
334
|
"Remove Vertex": "Remove vertex",
|
|
335
|
+
"replace": "Replace",
|
|
333
336
|
"Report an error": "Report an error",
|
|
334
337
|
"Request secure access": "Request secure access",
|
|
335
338
|
"Reset All": "Reset All",
|
|
@@ -364,6 +367,8 @@
|
|
|
364
367
|
"selectHighlightFillColor": "Selection highlight fill color",
|
|
365
368
|
"selectHighlightStrokeColor": "Selection highlight stroke color",
|
|
366
369
|
"Selection": "Selection",
|
|
370
|
+
"selection-mode": "Selection Mode",
|
|
371
|
+
"selection-tool-panel": "Selection Tool",
|
|
367
372
|
"selectionComponent": "Selection component",
|
|
368
373
|
"selectStrokeColor": "Selection stroke color",
|
|
369
374
|
"Send": "Send",
|
package/assets/i18n/fr.json
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
"about-panel": "À propos",
|
|
8
8
|
"Activate / Deactivate": "Activer / Désactiver",
|
|
9
9
|
"Activate batch creation mode to draw multiple features without needing to reselect the tool": "Activez le mode batch pour dessiner plusieurs entités sans avoir besoin de resélectionner l'outil",
|
|
10
|
+
"add": "Ajouter",
|
|
10
11
|
"Add bookmark": "Ajouter un favori",
|
|
11
12
|
"Add selected": "Ajouter la sélection",
|
|
12
13
|
"Add your first items": "Ajoutez vos premiers éléments",
|
|
@@ -322,6 +323,7 @@
|
|
|
322
323
|
"recenter_map": "Recentrer la carte",
|
|
323
324
|
"record_video": "Enregistrer une vidéo",
|
|
324
325
|
"Rectangle": "Rectangle",
|
|
326
|
+
"remove": "Supprimer",
|
|
325
327
|
"Remove all layers": "Supprimer toutes les couches",
|
|
326
328
|
"Remove filter": "Supprimer le filtre",
|
|
327
329
|
"Remove group": "Supprimer le groupe",
|
|
@@ -329,6 +331,7 @@
|
|
|
329
331
|
"Remove Shape": "Supprimer la forme",
|
|
330
332
|
"Remove theme": "Supprimer le thème",
|
|
331
333
|
"Remove Vertex": "Supprimer le sommet",
|
|
334
|
+
"replace": "Remplacer",
|
|
332
335
|
"Report an error": "Signaler un problème",
|
|
333
336
|
"Request secure access": "Demander un accès sécurisé",
|
|
334
337
|
"Reset All": "Réinitialiser tout",
|
|
@@ -363,6 +366,8 @@
|
|
|
363
366
|
"selectHighlightFillColor": "Couleur de remplissage de surbrillance",
|
|
364
367
|
"selectHighlightStrokeColor": "Couleur du trait de surbrillance",
|
|
365
368
|
"Selection": "Sélection",
|
|
369
|
+
"selection-mode": "Mode de Sélection",
|
|
370
|
+
"selection-tool-panel": "Outil de Sélection",
|
|
366
371
|
"selectionComponent": "Composant pour la sélection des cartes",
|
|
367
372
|
"selectStrokeColor": "Couleur du trait de sélection",
|
|
368
373
|
"Send": "Envoyer",
|
package/assets/i18n/it.json
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
"about-panel": "Informazioni",
|
|
8
8
|
"Activate / Deactivate": "Attiva / Disattiva",
|
|
9
9
|
"Activate batch creation mode to draw multiple features without needing to reselect the tool": "Attiva la modalità di creazione batch per disegnare più feature senza la necessità di riselezionare lo strumento",
|
|
10
|
+
"add": "Aggiungi",
|
|
10
11
|
"Add bookmark": "Aggiungi segnalibro",
|
|
11
12
|
"Add selected": "Agguingi selezione",
|
|
12
13
|
"Add your first items": "Aggiungi i tuoi primi elementi",
|
|
@@ -322,6 +323,7 @@
|
|
|
322
323
|
"recenter_map": "Ricentra la mappa",
|
|
323
324
|
"record_video": "Registrare un video",
|
|
324
325
|
"Rectangle": "Rettangolo",
|
|
326
|
+
"remove": "Rimuovi",
|
|
325
327
|
"Remove all layers": "Rimuovi tutti i layer",
|
|
326
328
|
"Remove filter": "Rimuovi filtro",
|
|
327
329
|
"Remove group": "Rimuovi gruppo",
|
|
@@ -329,6 +331,7 @@
|
|
|
329
331
|
"Remove Shape": "Rimuovi forma",
|
|
330
332
|
"Remove theme": "Rimuovi tema",
|
|
331
333
|
"Remove Vertex": "Rimuovi vertice",
|
|
334
|
+
"replace": "Sostituire",
|
|
332
335
|
"Report an error": "Segnala un errore",
|
|
333
336
|
"Request secure access": "Richiedi accesso sicuro",
|
|
334
337
|
"Reset All": "Azzeramento di tutti",
|
|
@@ -363,6 +366,8 @@
|
|
|
363
366
|
"selectHighlightFillColor": "Colore di riempimento dell'evidenziazione",
|
|
364
367
|
"selectHighlightStrokeColor": "Colore del tratto di evidenziazione della selezione",
|
|
365
368
|
"Selection": "Selezione",
|
|
369
|
+
"selection-mode": "Modalità di Selezione",
|
|
370
|
+
"selection-tool-panel": "Strumento di Selezione",
|
|
366
371
|
"selectionComponent": "Componente per la selezione della carta",
|
|
367
372
|
"selectStrokeColor": "Colore del tratto di selezione",
|
|
368
373
|
"Send": "Invia",
|
package/assets/icons/arrow.svg
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg"
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" class="svg-icon" style="width:1em;height:1em;vertical-align:middle;fill:currentColor;overflow:hidden" viewBox="0 0 1024 1024"><path fill="#000" d="M598.187 955.733h-.444a17.12 17.12 0 0 1-15.24-10.325L476.86 699.733h-50.193a17.067 17.067 0 1 1 0-34.133h35.532L325.666 348.075a17.067 17.067 0 0 1 22.409-22.409L665.6 462.2v-35.532a17.067 17.067 0 1 1 34.133 0v50.159l245.64 104.806a17.084 17.084 0 0 1 .922 30.976L796.81 687.36l153.924 153.924a17.05 17.05 0 0 1 0 24.133l-85.334 85.333a17.05 17.05 0 0 1-24.132 0L687.411 796.894l-73.933 149.35a17.07 17.07 0 0 1-15.291 9.49"/><path d="M682.667 750.933a17.07 17.07 0 0 1 12.066 5l158.6 158.601 61.201-61.2-158.6-158.601a17.015 17.015 0 0 1 4.437-27.324l137.677-68.83-222.037-94.737-.103-.034-301.977-129.877 129.86 301.994.034.069 95.454 222.02 68.096-137.575a17.07 17.07 0 0 1 15.292-9.506m-341.334-51.2H256a17.067 17.067 0 1 1 0-34.133h85.333a17.067 17.067 0 1 1 0 34.133m-170.666 0H85.333a17.067 17.067 0 0 1-17.066-17.066v-85.334a17.067 17.067 0 1 1 34.133 0V665.6h68.267a17.067 17.067 0 1 1 0 34.133M85.333 529.067A17.067 17.067 0 0 1 68.267 512v-85.333a17.067 17.067 0 0 1 34.133 0V512a17.067 17.067 0 0 1-17.067 17.067M682.667 358.4a17.067 17.067 0 0 1-17.067-17.067V256a17.067 17.067 0 1 1 34.133 0v85.333a17.067 17.067 0 0 1-17.066 17.067m-597.334 0a17.067 17.067 0 0 1-17.066-17.067V256a17.067 17.067 0 0 1 34.133 0v85.333A17.067 17.067 0 0 1 85.333 358.4m597.334-170.667a17.067 17.067 0 0 1-17.067-17.066V102.4h-68.267a17.067 17.067 0 1 1 0-34.133h85.334a17.067 17.067 0 0 1 17.066 17.066v85.334a17.067 17.067 0 0 1-17.066 17.066m-597.334 0a17.067 17.067 0 0 1-17.066-17.066V85.333a17.067 17.067 0 0 1 17.066-17.066h85.334a17.067 17.067 0 0 1 0 34.133H102.4v68.267a17.067 17.067 0 0 1-17.067 17.066M512 102.4h-85.333a17.067 17.067 0 0 1 0-34.133H512a17.067 17.067 0 1 1 0 34.133m-170.667 0H256a17.067 17.067 0 0 1 0-34.133h85.333a17.067 17.067 0 0 1 0 34.133"/></svg>
|
|
@@ -2,6 +2,7 @@ import { v4 as uuidv4 } from 'uuid';
|
|
|
2
2
|
import { Fill, RegularShape, Stroke, Style } from 'ol/style';
|
|
3
3
|
import { toRadians } from 'ol/math';
|
|
4
4
|
import GeoJSON from 'ol/format/GeoJSON';
|
|
5
|
+
import { getAreaAsMetricText, getLengthAsMetricText } from '../../tools/utils/olutils';
|
|
5
6
|
export var DrawingShape;
|
|
6
7
|
(function (DrawingShape) {
|
|
7
8
|
DrawingShape[DrawingShape["Point"] = 0] = "Point";
|
|
@@ -187,16 +188,10 @@ export default class DrawingFeature {
|
|
|
187
188
|
};
|
|
188
189
|
}
|
|
189
190
|
getLengthText(length) {
|
|
190
|
-
|
|
191
|
-
return length > 100 ? (length / 1000).toFixed(2) + ' km' : length.toFixed(2) + ' m';
|
|
192
|
-
}
|
|
193
|
-
return '';
|
|
191
|
+
return getLengthAsMetricText(this.displayMeasure ? length : undefined);
|
|
194
192
|
}
|
|
195
193
|
getAreaText(area) {
|
|
196
|
-
|
|
197
|
-
return area > 10000 ? (area / 1000000).toFixed(2) + ' km²' : area.toFixed(2) + ' m²';
|
|
198
|
-
}
|
|
199
|
-
return '';
|
|
194
|
+
return getAreaAsMetricText(this.displayMeasure ? area : undefined);
|
|
200
195
|
}
|
|
201
196
|
getCoordText(coord) {
|
|
202
197
|
if (!this.displayMeasure) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import DrawingFeature, { DrawingShape } from './drawingFeature';
|
|
2
2
|
import MapComponent from '../map/component';
|
|
3
3
|
import { Collection, Feature } from 'ol';
|
|
4
|
-
import { Geometry,
|
|
4
|
+
import { Geometry, SimpleGeometry } from 'ol/geom';
|
|
5
5
|
import { SketchCoordType } from 'ol/interaction/Draw';
|
|
6
6
|
import { Style } from 'ol/style';
|
|
7
7
|
import { Draw, Modify, Snap, Translate } from 'ol/interaction';
|
|
@@ -104,7 +104,6 @@ export default class OlDrawing {
|
|
|
104
104
|
addDrawInteraction(tool: DrawingShape): void;
|
|
105
105
|
centerViewOnFeature(drawingFeature: DrawingFeature): void;
|
|
106
106
|
getStyle(dFeature: DrawingFeature, olFeature: Feature<Geometry>): Style[];
|
|
107
|
-
ensurePolygonIsProperlyClosed(polygon: Polygon): Coordinate[];
|
|
108
107
|
private removeDrawInteraction;
|
|
109
108
|
private removeModifyInteraction;
|
|
110
109
|
private removeSnapInteraction;
|
|
@@ -9,7 +9,7 @@ import VectorLayer from 'ol/layer/Vector';
|
|
|
9
9
|
import GeoJSON from 'ol/format/GeoJSON';
|
|
10
10
|
import { getPointResolution } from 'ol/proj';
|
|
11
11
|
import { never, primaryAction } from 'ol/events/condition';
|
|
12
|
-
import {
|
|
12
|
+
import { ensurePolygonIsProperlyClosed, getAreaOfPolygon, getDistance, getHalfPoint, getLabelStyle, getRadiusDataForCircle } from '../../tools/utils/olutils';
|
|
13
13
|
import { ContextMenu, EntryInteractionType } from '../map/tools/contextmenu';
|
|
14
14
|
import { formatCoordinates } from '../../tools/geometrytools';
|
|
15
15
|
import { v4 as uuidv4 } from 'uuid';
|
|
@@ -28,9 +28,6 @@ function getLineStroke(strokeType, lineWidth) {
|
|
|
28
28
|
return [0.01, 5 * lineWidth];
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
function getHalfPoint(coordinates) {
|
|
32
|
-
return new Point(new LineString(coordinates).getCoordinateAt(0.5));
|
|
33
|
-
}
|
|
34
31
|
function extractVerticesFromGeometry(geometry) {
|
|
35
32
|
let vertices = [];
|
|
36
33
|
// Extract coordinates depending on coordinate array depth
|
|
@@ -683,11 +680,9 @@ export default class OlDrawing {
|
|
|
683
680
|
});
|
|
684
681
|
const styles = [defaultStyle];
|
|
685
682
|
const addLabel = (position, text) => {
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
style.getText().setText(text);
|
|
690
|
-
styles.push(style);
|
|
683
|
+
const labelStyleToAdd = getLabelStyle(position, text, labelStyle);
|
|
684
|
+
if (labelStyleToAdd) {
|
|
685
|
+
styles.push(labelStyleToAdd);
|
|
691
686
|
}
|
|
692
687
|
};
|
|
693
688
|
// If the shape is being constructed (ex. it is a polygon for which only two points are placed yet)
|
|
@@ -759,25 +754,22 @@ export default class OlDrawing {
|
|
|
759
754
|
}
|
|
760
755
|
else if (dFeature.type == DrawingShape.Polygon) {
|
|
761
756
|
const polygon = geometry;
|
|
762
|
-
const segments =
|
|
757
|
+
const segments = ensurePolygonIsProperlyClosed(polygon);
|
|
763
758
|
new LineString(segments).forEachSegment((a, b) => addLabel(getHalfPoint([a, b]), dFeature.getLengthText(getDistance([a, b], this.state.projection))));
|
|
764
|
-
addLabel(polygon.getInteriorPoint(), dFeature.getAreaText(
|
|
759
|
+
addLabel(polygon.getInteriorPoint(), dFeature.getAreaText(getAreaOfPolygon(polygon, this.state.projection)));
|
|
765
760
|
}
|
|
766
761
|
else if (dFeature.type == DrawingShape.Disk) {
|
|
767
|
-
const
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
radiusLineStyle.setGeometry(dFeature.displayMeasure ? new LineString(radiusLine) : new LineString([]));
|
|
774
|
-
styles.push(radiusLineStyle);
|
|
775
|
-
addLabel(getHalfPoint(radiusLine), dFeature.getLengthText(radius));
|
|
762
|
+
const radiusDataForCircle = getRadiusDataForCircle(geometry, defaultStyle, new Stroke({ color: measureColor, width: dFeature.strokeWidth }));
|
|
763
|
+
if (!dFeature.displayMeasure) {
|
|
764
|
+
radiusDataForCircle.style.setGeometry(new LineString([]));
|
|
765
|
+
}
|
|
766
|
+
styles.push(radiusDataForCircle.style);
|
|
767
|
+
addLabel(getHalfPoint(radiusDataForCircle.radiusLine), dFeature.getLengthText(radiusDataForCircle.radius));
|
|
776
768
|
}
|
|
777
769
|
else if (dFeature.type == DrawingShape.FreehandPolygon) {
|
|
778
770
|
const polygon = geometry;
|
|
779
|
-
|
|
780
|
-
addLabel(polygon.getInteriorPoint(), dFeature.getAreaText(
|
|
771
|
+
ensurePolygonIsProperlyClosed(polygon);
|
|
772
|
+
addLabel(polygon.getInteriorPoint(), dFeature.getAreaText(getAreaOfPolygon(polygon, this.state.projection)));
|
|
781
773
|
addLabel(new Point(polygon.getCoordinates()[0][0]), dFeature.getLengthText(getDistance(polygon.getCoordinates()[0], this.state.projection)));
|
|
782
774
|
}
|
|
783
775
|
else if (dFeature.type == DrawingShape.FreehandPolyline) {
|
|
@@ -790,13 +782,13 @@ export default class OlDrawing {
|
|
|
790
782
|
const segment2 = [rect.getCoordinates()[0][1], rect.getCoordinates()[0][2]];
|
|
791
783
|
addLabel(getHalfPoint(segment1), dFeature.getLengthText(getDistance(segment1, this.state.projection)));
|
|
792
784
|
addLabel(getHalfPoint(segment2), dFeature.getLengthText(getDistance(segment2, this.state.projection)));
|
|
793
|
-
addLabel(rect.getInteriorPoint(), dFeature.getAreaText(
|
|
785
|
+
addLabel(rect.getInteriorPoint(), dFeature.getAreaText(getAreaOfPolygon(rect, this.state.projection)));
|
|
794
786
|
}
|
|
795
787
|
else if (dFeature.type == DrawingShape.Square) {
|
|
796
788
|
const square = geometry;
|
|
797
789
|
const segment = [square.getCoordinates()[0][0], square.getCoordinates()[0][1]];
|
|
798
790
|
addLabel(getHalfPoint(segment), dFeature.getLengthText(getDistance(segment, this.state.projection)));
|
|
799
|
-
addLabel(square.getInteriorPoint(), dFeature.getAreaText(
|
|
791
|
+
addLabel(square.getInteriorPoint(), dFeature.getAreaText(getAreaOfPolygon(square, this.state.projection)));
|
|
800
792
|
}
|
|
801
793
|
if (dFeature.selected && this.rotateAndScale == null) {
|
|
802
794
|
const vertexStyle = dFeature.getVertexStyle();
|
|
@@ -840,15 +832,6 @@ export default class OlDrawing {
|
|
|
840
832
|
}
|
|
841
833
|
return styles;
|
|
842
834
|
}
|
|
843
|
-
ensurePolygonIsProperlyClosed(polygon) {
|
|
844
|
-
const coordinates = polygon.getCoordinates()[0];
|
|
845
|
-
let segments = [...coordinates];
|
|
846
|
-
if (coordinates.length > 2 && coordinates[0][0] != coordinates[coordinates.length - 1][0]) {
|
|
847
|
-
segments = [...coordinates, coordinates[0]];
|
|
848
|
-
polygon.setCoordinates([segments]);
|
|
849
|
-
}
|
|
850
|
-
return segments;
|
|
851
|
-
}
|
|
852
835
|
removeDrawInteraction() {
|
|
853
836
|
if (this.draw) {
|
|
854
837
|
this.map.olMap.removeInteraction(this.draw);
|
package/components/main.d.ts
CHANGED
|
@@ -36,6 +36,7 @@ export { default as SearchComponent } from './search/component';
|
|
|
36
36
|
export { default as MobileSearchComponent } from './search-mobile/component';
|
|
37
37
|
export { default as SelectionGridComponent } from './selectiongrid/component';
|
|
38
38
|
export { default as SelectionPanelMobile, getLinkFriendlyString } from './selectionpanel-mobile/component';
|
|
39
|
+
export { default as SelectionToolComponent } from './selectiontool/component';
|
|
39
40
|
export { default as SelectionWindowComponent } from './selectionwindow/component';
|
|
40
41
|
export { default as ShareComponent } from './share/component';
|
|
41
42
|
export { default as SwipeUpPanelMobile } from './swipe-up-panel-mobile/component';
|
package/components/main.js
CHANGED
|
@@ -36,6 +36,7 @@ export { default as SearchComponent } from './search/component';
|
|
|
36
36
|
export { default as MobileSearchComponent } from './search-mobile/component';
|
|
37
37
|
export { default as SelectionGridComponent } from './selectiongrid/component';
|
|
38
38
|
export { default as SelectionPanelMobile, getLinkFriendlyString } from './selectionpanel-mobile/component';
|
|
39
|
+
export { default as SelectionToolComponent } from './selectiontool/component';
|
|
39
40
|
export { default as SelectionWindowComponent } from './selectionwindow/component';
|
|
40
41
|
export { default as ShareComponent } from './share/component';
|
|
41
42
|
export { default as SwipeUpPanelMobile } from './swipe-up-panel-mobile/component';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Collection, Feature, Map, MapBrowserEvent, MapEvent } from 'ol';
|
|
2
2
|
import { ProjectionLike } from 'ol/proj';
|
|
3
3
|
import VectorSource from 'ol/source/Vector';
|
|
4
4
|
import VectorLayer from 'ol/layer/Vector';
|
|
@@ -76,6 +76,7 @@ export default class MapComponent extends GirafeHTMLElement {
|
|
|
76
76
|
onClick(e: MapBrowserEvent<PointerEvent>): void;
|
|
77
77
|
onDragSelection(_e: DragBoxEvent): void;
|
|
78
78
|
select(extent: number[]): void;
|
|
79
|
+
selectNone(): void;
|
|
79
80
|
onSelectFeatures(selectionParams: SelectionParam[]): Promise<void>;
|
|
80
81
|
connectedCallback(): void;
|
|
81
82
|
onCustomGirafeEvent(details: {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { html as uHtml } from 'uhtml';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { Collection, Feature } from 'ol';
|
|
3
|
+
import { Circle, Fill, RegularShape, Stroke, Style } from 'ol/style';
|
|
4
4
|
import VectorSource from 'ol/source/Vector';
|
|
5
5
|
import VectorLayer from 'ol/layer/Vector';
|
|
6
|
-
import { platformModifierKeyOnly } from 'ol/events/condition';
|
|
7
6
|
import { DragBox } from 'ol/interaction';
|
|
8
7
|
import { ScaleLine } from 'ol/control';
|
|
9
8
|
import { GeometryCollection, Point } from 'ol/geom';
|
|
@@ -39,7 +38,9 @@ import CircleStyle from 'ol/style/Circle';
|
|
|
39
38
|
import { parseCoordinates } from '../../tools/geometrytools';
|
|
40
39
|
import CircleGeom from 'ol/geom/Circle';
|
|
41
40
|
import WfsFilter from '../../tools/wfs/wfsfilter';
|
|
42
|
-
import { applyOpacityToLayers } from '../../tools/utils/utils';
|
|
41
|
+
import { applyFeaturesToSelection, applyOpacityToLayers } from '../../tools/utils/utils';
|
|
42
|
+
import { SelectionMode } from '../../models/selection';
|
|
43
|
+
import { platformModifierKeyOnly } from 'ol/events/condition';
|
|
43
44
|
export default class MapComponent extends GirafeHTMLElement {
|
|
44
45
|
template = () => {
|
|
45
46
|
return uHtml `<style>
|
|
@@ -390,10 +391,13 @@ export default class MapComponent extends GirafeHTMLElement {
|
|
|
390
391
|
this.select(extent);
|
|
391
392
|
}
|
|
392
393
|
select(extent) {
|
|
393
|
-
// Reset current selection
|
|
394
|
-
this.state.selection.
|
|
395
|
-
|
|
396
|
-
|
|
394
|
+
// Reset current selection if SelectionMode is Replace
|
|
395
|
+
if (this.state.selection.selectionMode === SelectionMode.Replace) {
|
|
396
|
+
this.selectNone();
|
|
397
|
+
}
|
|
398
|
+
else if (this.state.selection.selectionMode === SelectionMode.Add) {
|
|
399
|
+
this.state.selection.selectionParameters = [];
|
|
400
|
+
}
|
|
397
401
|
// Layers selectable today are WMS, WMTS (with wms layer) and Local files
|
|
398
402
|
// Use batch for changes to prevent multiple selection of objects
|
|
399
403
|
this.context.stateManager.batchChanges(() => {
|
|
@@ -402,6 +406,11 @@ export default class MapComponent extends GirafeHTMLElement {
|
|
|
402
406
|
this.context.localFileManager.selectFeatures(extent);
|
|
403
407
|
});
|
|
404
408
|
}
|
|
409
|
+
selectNone() {
|
|
410
|
+
this.state.selection.selectedFeatures = [];
|
|
411
|
+
this.state.selection.selectionParameters = [];
|
|
412
|
+
this.state.selection.highlightedFeatures = [];
|
|
413
|
+
}
|
|
405
414
|
async onSelectFeatures(selectionParams) {
|
|
406
415
|
if (selectionParams.length === 0) {
|
|
407
416
|
return;
|
|
@@ -418,8 +427,7 @@ export default class MapComponent extends GirafeHTMLElement {
|
|
|
418
427
|
const wfsPromises = selectionParams.map((param) => {
|
|
419
428
|
const wfsGetFeatureInfoSelectionParam = param.clone((l) => l.wfsQueryable);
|
|
420
429
|
const client = this.context.wfsManager.getClient(wfsGetFeatureInfoSelectionParam._ogcServer);
|
|
421
|
-
|
|
422
|
-
return features;
|
|
430
|
+
return client.getFeature(wfsGetFeatureInfoSelectionParam);
|
|
423
431
|
});
|
|
424
432
|
const wmsGmlFeatures = (await Promise.all(wmsPromises)).flat();
|
|
425
433
|
const wfsGmlFeatures = (await Promise.all(wfsPromises)).flat();
|
|
@@ -428,8 +436,7 @@ export default class MapComponent extends GirafeHTMLElement {
|
|
|
428
436
|
this.state.interface.selectionComponentVisible = false;
|
|
429
437
|
}
|
|
430
438
|
else {
|
|
431
|
-
this.state
|
|
432
|
-
this.state.interface.selectionComponentVisible = true;
|
|
439
|
+
applyFeaturesToSelection(gmlFeatures, this.state);
|
|
433
440
|
}
|
|
434
441
|
}
|
|
435
442
|
finally {
|
|
@@ -84,6 +84,7 @@ class SelectionGridComponent extends GirafeResizableElement {
|
|
|
84
84
|
closePanel() {
|
|
85
85
|
this.state.interface.selectionComponentVisible = false;
|
|
86
86
|
this.state.selection.selectedFeatures = [];
|
|
87
|
+
this.state.selection.selectionParameters = [];
|
|
87
88
|
this.state.selection.highlightedFeatures = [];
|
|
88
89
|
this.resultsSelected = false;
|
|
89
90
|
this.state.selection.gridSelected = false;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Circle, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon } from 'ol/geom';
|
|
2
2
|
import { getCenter } from 'ol/extent';
|
|
3
|
-
import {
|
|
3
|
+
import { getAreaOfPolygon, getDistance, polygonFromCircle } from '../../../tools/utils/olutils';
|
|
4
4
|
import { formatCoordinates } from '../../../tools/geometrytools';
|
|
5
5
|
/**
|
|
6
6
|
* Generates HTML string containing icons based on the provided geometry.
|
|
@@ -106,11 +106,11 @@ export default class FormatGridGeomValue {
|
|
|
106
106
|
let geoArea = 0;
|
|
107
107
|
if (geometry instanceof MultiPolygon) {
|
|
108
108
|
for (const polygon of geometry.getPolygons()) {
|
|
109
|
-
geoArea +=
|
|
109
|
+
geoArea += getAreaOfPolygon(polygon, this.projection);
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
else {
|
|
113
|
-
geoArea =
|
|
113
|
+
geoArea = getAreaOfPolygon(geometry, this.projection);
|
|
114
114
|
}
|
|
115
115
|
const area = (Math.round(geoArea * 100) / 100).toLocaleString(this.locale, { minimumFractionDigits: 2 });
|
|
116
116
|
icons += `<span>${area} m<sup>2</sup></span>`;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import GirafeHTMLElement from '../../base/GirafeHTMLElement';
|
|
2
|
+
import { SelectionMode, SelectionTool } from '../../models/selection';
|
|
3
|
+
import { Draw, Interaction } from 'ol/interaction';
|
|
4
|
+
import MapComponent from '../map/component';
|
|
5
|
+
import { Style } from 'ol/style';
|
|
6
|
+
import { FeatureLike } from 'ol/Feature';
|
|
7
|
+
export default class SelectionToolComponent extends GirafeHTMLElement {
|
|
8
|
+
template: () => import("uhtml").Hole;
|
|
9
|
+
visible: boolean;
|
|
10
|
+
renderedOnce: boolean;
|
|
11
|
+
buttons: {
|
|
12
|
+
id: string;
|
|
13
|
+
tool: SelectionTool;
|
|
14
|
+
}[];
|
|
15
|
+
toolSelected: Element | null;
|
|
16
|
+
selectionMode: SelectionMode;
|
|
17
|
+
canExecuteSelect: () => boolean;
|
|
18
|
+
get drawing(): {
|
|
19
|
+
defaultFillColor: string;
|
|
20
|
+
defaultStrokeColor: string;
|
|
21
|
+
defaultStrokeWidth: number;
|
|
22
|
+
defaultTextSize: number;
|
|
23
|
+
defaultFont: string;
|
|
24
|
+
defaultVertexRadius: number;
|
|
25
|
+
defaultVertexFillColor: string;
|
|
26
|
+
defaultVertexStrokeWidth: number;
|
|
27
|
+
};
|
|
28
|
+
get map(): import("ol").Map;
|
|
29
|
+
get mapComponent(): MapComponent;
|
|
30
|
+
private defaultStyle;
|
|
31
|
+
private labelStyle;
|
|
32
|
+
styleFunction: (featureLike: FeatureLike) => Style[];
|
|
33
|
+
selectPoint: Interaction;
|
|
34
|
+
selectRectangle: Draw;
|
|
35
|
+
selectPolygon: Draw;
|
|
36
|
+
selectFreehandPolygon: Draw;
|
|
37
|
+
selectCircle: Draw;
|
|
38
|
+
selectInteractions: Record<SelectionTool, Interaction | undefined>;
|
|
39
|
+
lastSelectInteraction: Interaction | undefined;
|
|
40
|
+
constructor(name?: string);
|
|
41
|
+
private addSelectionHandlers;
|
|
42
|
+
render(): void;
|
|
43
|
+
renderComponent(): void;
|
|
44
|
+
setTool(tool: SelectionTool | null): void;
|
|
45
|
+
connectedCallback(): void;
|
|
46
|
+
togglePanel(visible: boolean): void;
|
|
47
|
+
registerEvents(): void;
|
|
48
|
+
unregisterEvents(): void;
|
|
49
|
+
onSelectionModeChanged(event: Event): void;
|
|
50
|
+
}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { html as uHtml } from 'uhtml';
|
|
2
|
+
import GirafeHTMLElement from '../../base/GirafeHTMLElement';
|
|
3
|
+
import { SelectionMode, SelectionTool } from '../../models/selection';
|
|
4
|
+
import { Draw, Interaction } from 'ol/interaction';
|
|
5
|
+
import MapComponent from '../map/component';
|
|
6
|
+
import { createBox } from 'ol/interaction/Draw';
|
|
7
|
+
import { Circle, Fill, RegularShape, Stroke, Style, Text } from 'ol/style';
|
|
8
|
+
import { LineString, Point } from 'ol/geom';
|
|
9
|
+
import { ensurePolygonIsProperlyClosed, getAreaOfPolygon, getAreaAsMetricText, getDistance, getHalfPoint, getLabelStyle, getLengthAsMetricText, getRadiusDataForCircle, getAreaOfCircle } from '../../tools/utils/olutils';
|
|
10
|
+
const defaultFill = new Fill({
|
|
11
|
+
color: 'rgba(255, 255, 255, 0.5)'
|
|
12
|
+
});
|
|
13
|
+
const defaultStroke = new Stroke({
|
|
14
|
+
color: 'rgba(0, 153, 255, 1)',
|
|
15
|
+
width: 3
|
|
16
|
+
});
|
|
17
|
+
export default class SelectionToolComponent extends GirafeHTMLElement {
|
|
18
|
+
template = () => {
|
|
19
|
+
return uHtml `<style>
|
|
20
|
+
*{font-family:Arial,sans-serif}.hidden{display:none!important}.gg-rotate90{transform:rotate(90deg)}.gg-rotate180{transform:rotate(180deg)}.gg-rotate270{transform:rotate(270deg)}img{filter:var(--svg-filter)}img.legend-image{filter:var(--svg-map-filter);background:var(--svg-legend-bkg)}div{scrollbar-width:thin}a,a:visited{color:var(--link-color)}@keyframes spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}}@keyframes spin-wait{0%{transform:rotate(0)}7%{transform:rotate(360deg)}to{transform:rotate(360deg)}}.gg-spin{animation-name:spin;animation-duration:2s;animation-timing-function:linear;animation-iteration-count:infinite}.gg-spin-wait{animation-name:spin-wait;animation-duration:10s;animation-timing-function:linear;animation-iteration-count:infinite}::-webkit-scrollbar{width:5px}::-webkit-scrollbar-thumb{background:#999}.gg-button,.gg-select,.gg-input,.gg-textarea{background-color:var(--bkg-color);color:var(--text-color);border:var(--app-standard-border);box-sizing:border-box;cursor:pointer;border-radius:3px;outline:0;margin:0;padding:0 0 0 .5rem;display:inline-block}.gg-label{background-color:var(--bkg-color);color:var(--text-color);border:none;align-items:center;margin:0;padding:0;display:flex}.gg-button,.gg-select,.gg-input,.gg-label{min-height:calc(var(--app-standard-height)/1.5)}.gg-textarea{max-height:initial;resize:vertical;height:6rem;padding:.5rem;line-height:1.3rem}.gg-input{cursor:text}.gg-checkbox{accent-color:var(--text-color);width:1.2rem}.gg-range{accent-color:var(--text-color)}.gg-button{padding:0 .5rem}.gg-button.active{border:solid 1px var(--text-color-grad2);background-color:var(--text-color-grad2);color:var(--bkg-color)}.gg-button:disabled{color:gray;cursor:not-allowed;background-color:#d3d3d3;border:none}.gg-input:disabled,.gg-select:disabled,.gg-textarea:disabled{color:gray;cursor:not-allowed;background-color:#d3d3d3}.gg-button>img{vertical-align:middle}.gg-icon-button{color:var(--text-color);cursor:pointer;background-color:#0000;border:none;flex-direction:column;justify-content:center;align-items:center;padding:0;display:flex}.gg-big,.gg-big-withtext{min-width:var(--app-standard-height);min-height:var(--app-standard-height);max-height:var(--app-standard-height)}.gg-big img,.gg-big-withtext img{width:calc(var(--app-standard-height) - 1.5rem);margin:0}.gg-big-withtext span{font-variant:small-caps;padding:0 1rem;font-size:.9rem}.gg-medium,.gg-medium-withtext{min-width:calc(var(--app-standard-height)/1.2);min-height:calc(var(--app-standard-height)/1.2);max-height:calc(var(--app-standard-height)/1.2);flex-direction:row}.gg-medium img{width:calc(var(--app-standard-height)/2.4);margin:0}.gg-medium-withtext img{width:calc(var(--app-standard-height)/2.4);margin-left:.5rem}.gg-medium-withtext span{padding:0 1rem 0 .5rem;font-size:.9rem}.gg-small,.gg-small-withtext{min-width:calc(var(--app-standard-height)/2);min-height:calc(var(--app-standard-height)/2);max-height:calc(var(--app-standard-height)/2);flex-direction:row}.gg-small img{width:calc(var(--app-standard-height)/3);margin:0}.gg-small-withtext img{width:calc(var(--app-standard-height)/3);margin-left:.5rem}.gg-small-withtext span{padding:0 .5rem 0 .3rem;font-size:.9rem}.gg-button:hover,.gg-select:hover,.gg-input:hover,.gg-textarea:hover,.gg-icon-button:hover{background-color:var(--bkg-color-grad1)}.gg-opacity{opacity:.5}.gg-opacity:hover{opacity:1;background-color:#0000}.gg-tabs{cursor:pointer;grid-auto-flow:column;padding-bottom:1rem;font-size:1rem;display:grid}.gg-tab{border:none;border-bottom:var(--app-standard-border);cursor:pointer;color:var(--text-color);background:0 0;padding:.5rem}.gg-tab.active{border-bottom:solid 1px var(--text-color)}.girafe-button-big,.girafe-button-large,.girafe-button-small,.girafe-button-tiny{color:var(--text-color);background-color:#0000;border:none;flex-direction:column;display:flex}.girafe-button-big:hover,.girafe-button-large:hover,.girafe-button-small:hover,.girafe-button-tiny:hover{background-color:var(--bkg-color-grad1);cursor:pointer}.girafe-button-big.dark,.girafe-button-large.dark,.girafe-button-small.dark,.girafe-button-tiny.dark{background-color:var(--bkg-color);filter:invert()}.girafe-button-big{width:var(--app-standard-height);height:var(--app-standard-height);align-items:center;padding:1rem}.girafe-button-big img{overflow:hidden}.girafe-button-large{flex-direction:row}.girafe-button-large img{height:2rem;margin:.3rem}.girafe-button-large span{height:2rem;margin:.3rem;line-height:2rem}.girafe-button-small{min-width:calc(var(--app-standard-height)/2);height:calc(var(--app-standard-height)/2);align-items:center;padding:.5rem}.girafe-button-small img{overflow:hidden}.girafe-button-small span{text-align:left;text-overflow:ellipsis;width:100%;overflow:hidden}.girafe-button-tiny{align-items:center;width:1rem;height:1rem;padding:0}.girafe-button-tiny img{overflow:hidden}
|
|
21
|
+
</style><style>
|
|
22
|
+
#panel{height:100%;color:var(--text-color);flex-direction:column;display:flex}#panel>div{padding:1rem}#toolbar{flex-wrap:wrap;display:flex}.toolParameters{grid-template-columns:auto auto 60px auto;justify-content:left;align-items:center;margin-top:10px;display:grid}.toolParameters>.toolParameter{flex-direction:column;padding-bottom:8px;display:flex}input{border:1px solid var(--bkg-color-grad1);width:inherit;background-color:var(--bkg-color-input);padding-right:0}input:focus{border:1px solid var(--lt-color-gray-900)}button{border:solid 1px var(--bkg-color);color:var(--text-color);background-color:var(--bkg-color);cursor:pointer;padding:0}button:hover{border:solid 1px var(--text-color-grad2)}button.selected{border:solid 1px var(--text-color-grad2);background-color:var(--bkg-color-grad1);color:var(--bkg-color)}
|
|
23
|
+
</style>
|
|
24
|
+
<div id="panel"><div><div id="toolbar"><button id="point" tip="Point" class="gg-icon-button gg-medium"><img alt="point icon" src="icons/point.svg"></button> <button id="polygon" tip="Polygon" class="gg-icon-button gg-medium"><img alt="polygon icon" src="icons/polygon.svg"></button> <button id="rectangle" tip="Rectangle" class="gg-icon-button gg-medium"><img alt="rectangle icon" src="icons/rectangle.svg"></button> <button id="circle" tip="Circle" class="gg-icon-button gg-medium"><img alt="circle icon" src="icons/circle.svg"></button> <button id="freepolygon" tip="Freehand polygon" class="gg-icon-button gg-medium"><img alt="polygon-free icon" src="icons/polygon-free.svg"></button></div><div class="toolParameters"><div class="toolParameter"><label for="selection-mode" class="gg-label" i18n="selection-mode">selection-mode</label> ${uHtml ` <select id="selection-mode" class="gg-select" onchange="${(event) => this.onSelectionModeChanged(event)}"><option value="${SelectionMode.Replace}" ?selected="${this.selectionMode === SelectionMode.Replace}" i18n="replace">replace<option value="${SelectionMode.Add}" ?selected="${this.selectionMode === SelectionMode.Add}" i18n="add">add<option value="${SelectionMode.Remove}" ?selected="${this.selectionMode === SelectionMode.Remove}" i18n="remove">replace</select> `}</div></div></div></div>`;
|
|
25
|
+
};
|
|
26
|
+
visible = false;
|
|
27
|
+
renderedOnce = false;
|
|
28
|
+
buttons = [
|
|
29
|
+
{ id: 'point', tool: SelectionTool.Point },
|
|
30
|
+
{ id: 'rectangle', tool: SelectionTool.Rectangle },
|
|
31
|
+
{ id: 'polygon', tool: SelectionTool.Polygon },
|
|
32
|
+
{ id: 'circle', tool: SelectionTool.Disk },
|
|
33
|
+
{ id: 'freepolygon', tool: SelectionTool.FreehandPolygon }
|
|
34
|
+
];
|
|
35
|
+
toolSelected = null;
|
|
36
|
+
selectionMode = SelectionMode.Replace;
|
|
37
|
+
canExecuteSelect = () => this.context.userInteractionManager.canListenerExecute('map.select', this.name);
|
|
38
|
+
get drawing() {
|
|
39
|
+
return this.context.configManager.Config.drawing;
|
|
40
|
+
}
|
|
41
|
+
get map() {
|
|
42
|
+
return this.context.mapManager.getMap();
|
|
43
|
+
}
|
|
44
|
+
get mapComponent() {
|
|
45
|
+
return this.context.componentManager.getComponents(MapComponent)[0];
|
|
46
|
+
}
|
|
47
|
+
defaultStyle;
|
|
48
|
+
labelStyle;
|
|
49
|
+
styleFunction = (featureLike) => {
|
|
50
|
+
const styles = [this.defaultStyle];
|
|
51
|
+
if (featureLike.getGeometry()?.getType() == 'Polygon') {
|
|
52
|
+
const polygon = featureLike.getGeometry();
|
|
53
|
+
const segments = ensurePolygonIsProperlyClosed(polygon);
|
|
54
|
+
new LineString(segments).forEachSegment((a, b) => {
|
|
55
|
+
styles.push(getLabelStyle(getHalfPoint([a, b]), getLengthAsMetricText(getDistance([a, b], this.state.projection)), this.labelStyle));
|
|
56
|
+
});
|
|
57
|
+
styles.push(getLabelStyle(polygon.getInteriorPoint(), getAreaAsMetricText(getAreaOfPolygon(polygon, this.state.projection)), this.labelStyle));
|
|
58
|
+
}
|
|
59
|
+
else if (featureLike.getGeometry()?.getType() == 'Circle') {
|
|
60
|
+
const circle = featureLike.getGeometry();
|
|
61
|
+
const radiusDataForCircle = getRadiusDataForCircle(circle, this.defaultStyle, new Stroke({ color: 'rgba(0, 0, 0, 0.4)', width: this.drawing.defaultStrokeWidth }));
|
|
62
|
+
styles.push(radiusDataForCircle.style, getLabelStyle(getHalfPoint(radiusDataForCircle.radiusLine), getLengthAsMetricText(radiusDataForCircle.radius), this.labelStyle), getLabelStyle(new Point(circle.getCenter()), getAreaAsMetricText(getAreaOfCircle(circle, this.state.projection)), this.labelStyle));
|
|
63
|
+
}
|
|
64
|
+
return styles.filter((style) => !!style);
|
|
65
|
+
};
|
|
66
|
+
selectPoint = new Interaction({
|
|
67
|
+
handleEvent: (event) => {
|
|
68
|
+
if (event.type == 'singleclick') {
|
|
69
|
+
this.state.selection.selectionGeometry = undefined;
|
|
70
|
+
this.mapComponent.onClick(event);
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
selectRectangle = new Draw({
|
|
77
|
+
type: 'Circle',
|
|
78
|
+
geometryFunction: createBox(),
|
|
79
|
+
freehand: false,
|
|
80
|
+
stopClick: true,
|
|
81
|
+
condition: this.canExecuteSelect,
|
|
82
|
+
style: this.styleFunction
|
|
83
|
+
});
|
|
84
|
+
selectPolygon = new Draw({
|
|
85
|
+
type: 'Polygon',
|
|
86
|
+
freehand: false,
|
|
87
|
+
stopClick: true,
|
|
88
|
+
condition: this.canExecuteSelect,
|
|
89
|
+
style: this.styleFunction
|
|
90
|
+
});
|
|
91
|
+
selectFreehandPolygon = new Draw({
|
|
92
|
+
type: 'Polygon',
|
|
93
|
+
freehand: true,
|
|
94
|
+
stopClick: true,
|
|
95
|
+
condition: this.canExecuteSelect
|
|
96
|
+
});
|
|
97
|
+
selectCircle = new Draw({
|
|
98
|
+
type: 'Circle',
|
|
99
|
+
freehand: false,
|
|
100
|
+
condition: this.canExecuteSelect,
|
|
101
|
+
style: this.styleFunction
|
|
102
|
+
});
|
|
103
|
+
selectInteractions = {
|
|
104
|
+
[SelectionTool.Point]: this.selectPoint,
|
|
105
|
+
[SelectionTool.Rectangle]: this.selectRectangle,
|
|
106
|
+
[SelectionTool.Polygon]: this.selectPolygon,
|
|
107
|
+
[SelectionTool.Disk]: this.selectCircle,
|
|
108
|
+
[SelectionTool.FreehandPolygon]: this.selectFreehandPolygon
|
|
109
|
+
};
|
|
110
|
+
lastSelectInteraction = undefined;
|
|
111
|
+
constructor(name = 'selection-tool') {
|
|
112
|
+
super(name);
|
|
113
|
+
this.addSelectionHandlers();
|
|
114
|
+
}
|
|
115
|
+
addSelectionHandlers() {
|
|
116
|
+
for (const drawInteraction of Object.values(this.selectInteractions).filter((selectInteraction) => selectInteraction instanceof Draw)) {
|
|
117
|
+
drawInteraction?.on('drawend', (event) => {
|
|
118
|
+
console.log('drawend', event.feature.getStyleFunction());
|
|
119
|
+
this.state.selection.selectionGeometry = event.feature.getGeometry();
|
|
120
|
+
this.mapComponent.select(event.feature.getGeometry().getExtent());
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
render() {
|
|
125
|
+
super.render();
|
|
126
|
+
this.selectionMode = this.state.selection.selectionMode;
|
|
127
|
+
if (this.visible) {
|
|
128
|
+
this.renderComponent();
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
this.hide();
|
|
132
|
+
}
|
|
133
|
+
super.girafeTranslate();
|
|
134
|
+
}
|
|
135
|
+
renderComponent() {
|
|
136
|
+
this.show();
|
|
137
|
+
if (!this.renderedOnce) {
|
|
138
|
+
this.renderedOnce = true;
|
|
139
|
+
for (const button of this.buttons) {
|
|
140
|
+
this.getById(button.id).addEventListener('pointerup', () => {
|
|
141
|
+
this.setTool(button.tool);
|
|
142
|
+
if (button.tool) {
|
|
143
|
+
this.refreshRender();
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
this.setTool(SelectionTool.Point);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
setTool(tool) {
|
|
151
|
+
if (this.toolSelected !== null) {
|
|
152
|
+
this.toolSelected.classList.remove('selected');
|
|
153
|
+
}
|
|
154
|
+
if (tool != null) {
|
|
155
|
+
this.toolSelected = this.getById(this.buttons.find((x) => x.tool == tool).id);
|
|
156
|
+
this.toolSelected.classList.add('selected');
|
|
157
|
+
}
|
|
158
|
+
if (this.lastSelectInteraction) {
|
|
159
|
+
this.map.removeInteraction(this.lastSelectInteraction);
|
|
160
|
+
this.lastSelectInteraction = undefined;
|
|
161
|
+
}
|
|
162
|
+
if (tool != null) {
|
|
163
|
+
const interaction = this.selectInteractions[tool];
|
|
164
|
+
if (interaction) {
|
|
165
|
+
this.map.addInteraction(interaction);
|
|
166
|
+
this.lastSelectInteraction = interaction;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
connectedCallback() {
|
|
171
|
+
super.connectedCallback();
|
|
172
|
+
this.render();
|
|
173
|
+
this.subscribe('interface.selectionToolPanelVisible', (_, newValue) => this.togglePanel(newValue));
|
|
174
|
+
this.defaultStyle = new Style({
|
|
175
|
+
image: new Circle({
|
|
176
|
+
fill: defaultFill,
|
|
177
|
+
stroke: defaultStroke,
|
|
178
|
+
radius: 5
|
|
179
|
+
}),
|
|
180
|
+
fill: defaultFill,
|
|
181
|
+
stroke: defaultStroke,
|
|
182
|
+
text: new Text({
|
|
183
|
+
text: '',
|
|
184
|
+
font: this.drawing.defaultFont,
|
|
185
|
+
textBaseline: 'bottom',
|
|
186
|
+
offsetY: 1.2 * this.drawing.defaultTextSize,
|
|
187
|
+
fill: new Fill({ color: '#000000' }),
|
|
188
|
+
overflow: true
|
|
189
|
+
})
|
|
190
|
+
});
|
|
191
|
+
this.labelStyle = new Style({
|
|
192
|
+
text: new Text({
|
|
193
|
+
font: this.drawing.defaultFont,
|
|
194
|
+
padding: [2, 2, 2, 2],
|
|
195
|
+
textBaseline: 'bottom',
|
|
196
|
+
offsetY: -1 * this.drawing.defaultTextSize,
|
|
197
|
+
fill: new Fill({ color: '#000000' })
|
|
198
|
+
}),
|
|
199
|
+
image: new RegularShape({
|
|
200
|
+
radius: 6,
|
|
201
|
+
points: 3,
|
|
202
|
+
angle: Math.PI,
|
|
203
|
+
displacement: [0, 8],
|
|
204
|
+
fill: new Fill({ color: 'rgba(0, 0, 0, 0.4)' })
|
|
205
|
+
})
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
togglePanel(visible) {
|
|
209
|
+
if (this.visible == visible)
|
|
210
|
+
return;
|
|
211
|
+
this.visible = visible;
|
|
212
|
+
if (this.visible) {
|
|
213
|
+
this.setTool(SelectionTool.Point);
|
|
214
|
+
this.registerEvents();
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
this.state.selection.selectionGeometry = undefined;
|
|
218
|
+
this.state.selection.selectionMode = SelectionMode.Replace;
|
|
219
|
+
this.setTool(null);
|
|
220
|
+
this.unregisterEvents();
|
|
221
|
+
}
|
|
222
|
+
this.render();
|
|
223
|
+
}
|
|
224
|
+
registerEvents() {
|
|
225
|
+
this.registerInteractionListener('map.select', true);
|
|
226
|
+
}
|
|
227
|
+
unregisterEvents() {
|
|
228
|
+
this.unregisterInteractionListeners('map.select');
|
|
229
|
+
}
|
|
230
|
+
onSelectionModeChanged(event) {
|
|
231
|
+
const selectionModeAsString = (event?.target).value;
|
|
232
|
+
if (selectionModeAsString === '1') {
|
|
233
|
+
this.selectionMode = SelectionMode.Add;
|
|
234
|
+
}
|
|
235
|
+
else if (selectionModeAsString === '2') {
|
|
236
|
+
this.selectionMode = SelectionMode.Remove;
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
this.selectionMode = SelectionMode.Replace;
|
|
240
|
+
}
|
|
241
|
+
this.state.selection.selectionMode = this.selectionMode;
|
|
242
|
+
}
|
|
243
|
+
}
|
package/models/main.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ export type { TimeAwareLayer } from './layers/timeawarelayer';
|
|
|
33
33
|
export { isTimeAwareLayer } from './layers/timeawarelayer';
|
|
34
34
|
export type { GeometryResult, GeometryCollectionResult, AllSearchResults } from './searchresult';
|
|
35
35
|
export { default as SearchResult } from './searchresult';
|
|
36
|
+
export type { SelectionTool, SelectionMode } from './selection';
|
|
36
37
|
export { default as SelectionParam } from './selectionparam';
|
|
37
38
|
export { default as ServerOgc } from './serverogc';
|
|
38
39
|
export type { HttpMethod, OgcApiLinksResponse } from './serverogcapi';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export var SelectionTool;
|
|
2
|
+
(function (SelectionTool) {
|
|
3
|
+
SelectionTool[SelectionTool["Point"] = 0] = "Point";
|
|
4
|
+
SelectionTool[SelectionTool["Polygon"] = 1] = "Polygon";
|
|
5
|
+
SelectionTool[SelectionTool["Rectangle"] = 2] = "Rectangle";
|
|
6
|
+
SelectionTool[SelectionTool["Disk"] = 3] = "Disk";
|
|
7
|
+
SelectionTool[SelectionTool["FreehandPolygon"] = 4] = "FreehandPolygon";
|
|
8
|
+
})(SelectionTool || (SelectionTool = {}));
|
|
9
|
+
export var SelectionMode;
|
|
10
|
+
(function (SelectionMode) {
|
|
11
|
+
SelectionMode[SelectionMode["Replace"] = 0] = "Replace";
|
|
12
|
+
SelectionMode[SelectionMode["Add"] = 1] = "Add";
|
|
13
|
+
SelectionMode[SelectionMode["Remove"] = 2] = "Remove";
|
|
14
|
+
})(SelectionMode || (SelectionMode = {}));
|
package/package.json
CHANGED
package/templates/index.html
CHANGED
|
@@ -128,6 +128,10 @@
|
|
|
128
128
|
slot="main"
|
|
129
129
|
data-toggle-path="interface.drawingPanelVisible"
|
|
130
130
|
data-title="drawing-panel"></girafe-drawing>
|
|
131
|
+
<girafe-selection-tool
|
|
132
|
+
slot="main"
|
|
133
|
+
data-toggle-path="interface.selectionToolPanelVisible"
|
|
134
|
+
data-title="selection-tool-panel"></girafe-selection-tool>
|
|
131
135
|
<girafe-print
|
|
132
136
|
slot="main"
|
|
133
137
|
data-toggle-path="interface.printPanelVisible"
|
|
@@ -183,6 +187,13 @@
|
|
|
183
187
|
onclick="document.geogirafe.state.interface.drawingPanelVisible = !document.geogirafe.state.interface.drawingPanelVisible">
|
|
184
188
|
<img alt="draw-icon" src="icons/draw.svg" />
|
|
185
189
|
</button>
|
|
190
|
+
<button
|
|
191
|
+
tip="selection-tool-panel"
|
|
192
|
+
slot="menu-content"
|
|
193
|
+
class="gg-icon-button gg-big"
|
|
194
|
+
onclick="document.geogirafe.state.interface.selectionToolPanelVisible = !document.geogirafe.state.interface.selectionToolPanelVisible">
|
|
195
|
+
<img alt="draw-icon" src="icons/arrow.svg" />
|
|
196
|
+
</button>
|
|
186
197
|
<button
|
|
187
198
|
tip="external-entry"
|
|
188
199
|
slot="menu-content"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"1.0.
|
|
1
|
+
{"version":"1.0.2201757187", "build":"2201757187", "date":"08/12/2025"}
|
|
@@ -43,6 +43,7 @@ import VideoRecordComponent from '../../components/videorecord/component';
|
|
|
43
43
|
import { DrawingState } from '../../components/drawing/drawingFeature';
|
|
44
44
|
import DrawingSerializer from '../../components/drawing/drawingSerializer';
|
|
45
45
|
import { ShareState, ShareStateSerializer } from '../../components/share/sharestate';
|
|
46
|
+
import SelectionToolComponent from '../../components/selectiontool/component';
|
|
46
47
|
export default class GeoGirafeApp {
|
|
47
48
|
readyPromise;
|
|
48
49
|
resolveReady;
|
|
@@ -117,6 +118,7 @@ export default class GeoGirafeApp {
|
|
|
117
118
|
customElements.define('girafe-edit-form', EditFromComponent);
|
|
118
119
|
customElements.define('girafe-scale', ScaleComponent);
|
|
119
120
|
customElements.define('girafe-search', SearchComponent);
|
|
121
|
+
customElements.define('girafe-selection-tool', SelectionToolComponent);
|
|
120
122
|
customElements.define('girafe-selection-grid', SelectionGridComponent);
|
|
121
123
|
customElements.define('girafe-selection-window', SelectionWindowComponent);
|
|
122
124
|
customElements.define('girafe-share', ShareComponent);
|
|
@@ -5,6 +5,7 @@ import { Vector as VectorLayer } from 'ol/layer.js';
|
|
|
5
5
|
import { Vector as VectorSource } from 'ol/source.js';
|
|
6
6
|
import LayerLocalFile from '../../models/layers/layerlocalfile';
|
|
7
7
|
import { extend, intersects } from 'ol/extent';
|
|
8
|
+
import { applyFeaturesToSelection } from '../utils/utils';
|
|
8
9
|
class LocalFileManager extends GirafeSingleton {
|
|
9
10
|
map;
|
|
10
11
|
name;
|
|
@@ -156,8 +157,7 @@ Verify that those features can be displayed within the maximal extent configured
|
|
|
156
157
|
for (const activeLayer of Object.values(this.activeLayers)) {
|
|
157
158
|
const features = activeLayer.olayer.getSource()?.getFeaturesInExtent(extent);
|
|
158
159
|
if (features && features.length > 0) {
|
|
159
|
-
this.context.stateManager.state
|
|
160
|
-
this.context.stateManager.state.interface.selectionComponentVisible = true;
|
|
160
|
+
applyFeaturesToSelection(features, this.context.stateManager.state);
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
}
|
package/tools/main.d.ts
CHANGED
|
@@ -100,11 +100,11 @@ export { default as UserDataManager } from './userdata/userdatamanager';
|
|
|
100
100
|
export { default as ColumnAliasHelper } from './utils/aliases';
|
|
101
101
|
export { debounce } from './utils/debounce';
|
|
102
102
|
export { default as GirafeColorPicker } from './utils/girafecolorpicker';
|
|
103
|
-
export { unByKeyAll, getOlayerByName, removeUnwantedOlParams, polygonFromCircle, getDistance,
|
|
103
|
+
export { unByKeyAll, getOlayerByName, removeUnwantedOlParams, polygonFromCircle, getDistance, getAreaOfPolygon, getAreaOfCircle, isCoordinateInDegrees, getSelectionBoxFromMapClick, reprojectGeometry, ensurePolygonIsProperlyClosed, getHalfPoint, getLabelStyle, getRadiusDataForCircle, getLengthAsMetricText, getAreaAsMetricText } from './utils/olutils';
|
|
104
104
|
export { getPropertyByPath, setPropertyByPath, createObjectFromPath, deletePropertyByPath, mergeObjects } from './utils/pathUtils';
|
|
105
105
|
export { generateQrCode } from './utils/qrcode';
|
|
106
106
|
export { default as ServiceWorkerHelper } from './utils/swhelper';
|
|
107
|
-
export { systemIsInDarkMode, isSafari, isFirefox, getValidIndex, minMax, hexToRgbaArray, rgbStrToRgbaArray, colorToRgbaArray, isValidEmail, applyOpacityToLayers } from './utils/utils';
|
|
107
|
+
export { systemIsInDarkMode, isSafari, isFirefox, getValidIndex, minMax, hexToRgbaArray, rgbStrToRgbaArray, colorToRgbaArray, isValidEmail, applyOpacityToLayers, applyFeaturesToSelection } from './utils/utils';
|
|
108
108
|
export { default as VendorSpecificOgcServerManager } from './vendorspecificogcservermanager';
|
|
109
109
|
export type { WfsClientOptions, WfsClientOptionalOptions, QueryableLayerWms, GetFeatureOptionalOptions } from './wfs/wfsclient';
|
|
110
110
|
export { default as WfsClient, WfsClientMapServer, WfsClientQgis, WfsClientGeorama, WfsClientDefault, WfsClientGeoServer } from './wfs/wfsclient';
|
package/tools/main.js
CHANGED
|
@@ -78,11 +78,11 @@ export { default as UserDataManager } from './userdata/userdatamanager';
|
|
|
78
78
|
export { default as ColumnAliasHelper } from './utils/aliases';
|
|
79
79
|
export { debounce } from './utils/debounce';
|
|
80
80
|
export { default as GirafeColorPicker } from './utils/girafecolorpicker';
|
|
81
|
-
export { unByKeyAll, getOlayerByName, removeUnwantedOlParams, polygonFromCircle, getDistance,
|
|
81
|
+
export { unByKeyAll, getOlayerByName, removeUnwantedOlParams, polygonFromCircle, getDistance, getAreaOfPolygon, getAreaOfCircle, isCoordinateInDegrees, getSelectionBoxFromMapClick, reprojectGeometry, ensurePolygonIsProperlyClosed, getHalfPoint, getLabelStyle, getRadiusDataForCircle, getLengthAsMetricText, getAreaAsMetricText } from './utils/olutils';
|
|
82
82
|
export { getPropertyByPath, setPropertyByPath, createObjectFromPath, deletePropertyByPath, mergeObjects } from './utils/pathUtils';
|
|
83
83
|
export { generateQrCode } from './utils/qrcode';
|
|
84
84
|
export { default as ServiceWorkerHelper } from './utils/swhelper';
|
|
85
|
-
export { systemIsInDarkMode, isSafari, isFirefox, getValidIndex, minMax, hexToRgbaArray, rgbStrToRgbaArray, colorToRgbaArray, isValidEmail, applyOpacityToLayers } from './utils/utils';
|
|
85
|
+
export { systemIsInDarkMode, isSafari, isFirefox, getValidIndex, minMax, hexToRgbaArray, rgbStrToRgbaArray, colorToRgbaArray, isValidEmail, applyOpacityToLayers, applyFeaturesToSelection } from './utils/utils';
|
|
86
86
|
export { default as VendorSpecificOgcServerManager } from './vendorspecificogcservermanager';
|
|
87
87
|
export { default as WfsClient, WfsClientMapServer, WfsClientQgis, WfsClientGeorama, WfsClientDefault, WfsClientGeoServer } from './wfs/wfsclient';
|
|
88
88
|
export { default as WfsFilter, wfsOperatorsStrList, isWfsOperator, mapAttributeTypeToFilterOperators } from './wfs/wfsfilter';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest';
|
|
2
2
|
import MockHelper from '../../tests/mockhelper';
|
|
3
3
|
import ObjectSelection from '../../state/objectselection';
|
|
4
4
|
import SelectionSerializer from './selectionserializer';
|
|
@@ -40,7 +40,7 @@ describe('SelectionSerializer.serialize', () => {
|
|
|
40
40
|
}
|
|
41
41
|
}));
|
|
42
42
|
});
|
|
43
|
-
it('should return empty string if no selection parameters', () => {
|
|
43
|
+
it('should return empty string if no selection parameters (and default SelectionMode)', () => {
|
|
44
44
|
const selection = new ObjectSelection();
|
|
45
45
|
const serialized = serializer.brainSerialize(selection);
|
|
46
46
|
expect(serialized).toBe('');
|
|
@@ -15,8 +15,8 @@ export default class MapManager extends GirafeSingleton {
|
|
|
15
15
|
/** Make Map pan on Wheel/Middle-Button Click */
|
|
16
16
|
new DragPan({
|
|
17
17
|
condition: function (mapBrowserEvent) {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
const event = mapBrowserEvent.originalEvent;
|
|
19
|
+
return event.isPrimary && event.button < 2 && !event.shiftKey;
|
|
20
20
|
}
|
|
21
21
|
})
|
|
22
22
|
])
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Feature } from 'ol';
|
|
2
2
|
import SelectionParam from '../../models/selectionparam';
|
|
3
3
|
import WfsFilter from '../wfs/wfsfilter';
|
|
4
|
+
import { SelectionMode } from '../../models/selection';
|
|
5
|
+
import { Geometry } from 'ol/geom';
|
|
4
6
|
export default class ObjectSelection {
|
|
5
7
|
initialSelectionBox?: number[];
|
|
6
8
|
initialSelectionQuery?: InitialSelectionQuery;
|
|
@@ -9,6 +11,8 @@ export default class ObjectSelection {
|
|
|
9
11
|
focusedFeatures: Feature[] | null;
|
|
10
12
|
highlightedFeatures: Feature[];
|
|
11
13
|
gridSelected: boolean;
|
|
14
|
+
selectionMode: SelectionMode;
|
|
15
|
+
selectionGeometry?: Geometry;
|
|
12
16
|
}
|
|
13
17
|
export type InitialSelectionQuery = {
|
|
14
18
|
query: WfsFilter[];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SelectionMode } from '../../models/selection';
|
|
1
2
|
export default class ObjectSelection {
|
|
2
3
|
initialSelectionBox;
|
|
3
4
|
initialSelectionQuery;
|
|
@@ -6,4 +7,6 @@ export default class ObjectSelection {
|
|
|
6
7
|
focusedFeatures = null;
|
|
7
8
|
highlightedFeatures = [];
|
|
8
9
|
gridSelected = false;
|
|
10
|
+
selectionMode = SelectionMode.Replace;
|
|
11
|
+
selectionGeometry;
|
|
9
12
|
}
|
package/tools/utils/olutils.d.ts
CHANGED
|
@@ -4,8 +4,9 @@ import type BaseLayer from 'ol/layer/Base';
|
|
|
4
4
|
import type Feature from 'ol/Feature';
|
|
5
5
|
import { Coordinate } from 'ol/coordinate';
|
|
6
6
|
import { ProjectionLike } from 'ol/proj';
|
|
7
|
-
import { Circle, Geometry, Polygon } from 'ol/geom';
|
|
7
|
+
import { Circle, Geometry, Point, Polygon } from 'ol/geom';
|
|
8
8
|
import { Pixel } from 'ol/pixel';
|
|
9
|
+
import { Stroke, Style } from 'ol/style';
|
|
9
10
|
/**
|
|
10
11
|
* Unsubscribe to all OpenLayer listeners.
|
|
11
12
|
*/
|
|
@@ -32,7 +33,18 @@ export declare const getDistance: (coordinates: Coordinate[], projection: string
|
|
|
32
33
|
* @param polygon ol Polygon
|
|
33
34
|
* @returns the area of a polygon, considering the current map projection (projected or geographic)
|
|
34
35
|
*/
|
|
35
|
-
export declare const
|
|
36
|
+
export declare const getAreaOfPolygon: (polygon: Polygon, projection: string) => number;
|
|
37
|
+
export declare const getAreaOfCircle: (circle: Circle, projection: string) => number;
|
|
36
38
|
export declare const isCoordinateInDegrees: (coordinate: Coordinate) => boolean;
|
|
37
39
|
export declare const getSelectionBoxFromMapClick: (eventCoordinate: Pixel | [number, number], olMap: Map, pixelTolerance: number) => number[];
|
|
38
40
|
export declare const reprojectGeometry: (geometry: Geometry, sourceProjection: ProjectionLike, destinationProjection: ProjectionLike) => Geometry;
|
|
41
|
+
export declare const ensurePolygonIsProperlyClosed: (polygon: Polygon) => Coordinate[];
|
|
42
|
+
export declare const getHalfPoint: (coordinates: Coordinate[]) => Point;
|
|
43
|
+
export declare const getLabelStyle: (position: Point, text: string, labelStyle: Style) => Style | undefined;
|
|
44
|
+
export declare const getRadiusDataForCircle: (circle: Circle, defaultStyle: Style, stroke: Stroke) => {
|
|
45
|
+
style: Style;
|
|
46
|
+
radius: number;
|
|
47
|
+
radiusLine: Coordinate[];
|
|
48
|
+
};
|
|
49
|
+
export declare const getLengthAsMetricText: (length?: number) => string;
|
|
50
|
+
export declare const getAreaAsMetricText: (area?: number) => string;
|
package/tools/utils/olutils.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { fromCircle } from 'ol/geom/Polygon.js';
|
|
2
2
|
import { get as getProjection } from 'ol/proj';
|
|
3
|
-
import {
|
|
3
|
+
import { getArea as getSphericalArea, getDistance as getSphericalDistance } from 'ol/sphere';
|
|
4
4
|
import { unByKey } from 'ol/Observable';
|
|
5
|
-
import { LineString } from 'ol/geom';
|
|
5
|
+
import { LineString, Point } from 'ol/geom';
|
|
6
6
|
import GeoConsts from '../geoconsts';
|
|
7
7
|
import { buffer } from 'ol/extent';
|
|
8
8
|
/**
|
|
@@ -67,7 +67,7 @@ export const getDistance = (coordinates, projection) => {
|
|
|
67
67
|
* @param polygon ol Polygon
|
|
68
68
|
* @returns the area of a polygon, considering the current map projection (projected or geographic)
|
|
69
69
|
*/
|
|
70
|
-
export const
|
|
70
|
+
export const getAreaOfPolygon = (polygon, projection) => {
|
|
71
71
|
if (isProjectionInDegrees(projection)) {
|
|
72
72
|
return getSphericalArea(polygon, {
|
|
73
73
|
projection: getProjection(projection)
|
|
@@ -75,6 +75,14 @@ export const getArea = (polygon, projection) => {
|
|
|
75
75
|
}
|
|
76
76
|
return polygon.getArea();
|
|
77
77
|
};
|
|
78
|
+
export const getAreaOfCircle = (circle, projection) => {
|
|
79
|
+
if (isProjectionInDegrees(projection)) {
|
|
80
|
+
return getSphericalArea(circle, {
|
|
81
|
+
projection: getProjection(projection)
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return Math.PI * Math.pow(circle.getRadius(), 2);
|
|
85
|
+
};
|
|
78
86
|
const isProjectionInDegrees = (proj) => {
|
|
79
87
|
const projection = getProjection(proj);
|
|
80
88
|
return projection?.getUnits() === 'degrees';
|
|
@@ -116,3 +124,52 @@ export const reprojectGeometry = (geometry, sourceProjection, destinationProject
|
|
|
116
124
|
throw new Error(`Not able to reproject geometry: ${e}`);
|
|
117
125
|
}
|
|
118
126
|
};
|
|
127
|
+
export const ensurePolygonIsProperlyClosed = (polygon) => {
|
|
128
|
+
const coordinates = polygon.getCoordinates()[0];
|
|
129
|
+
let segments = [...coordinates];
|
|
130
|
+
if (coordinates.length > 2 && coordinates[0][0] != coordinates[coordinates.length - 1][0]) {
|
|
131
|
+
segments = [...coordinates, coordinates[0]];
|
|
132
|
+
polygon.setCoordinates([segments]);
|
|
133
|
+
}
|
|
134
|
+
return segments;
|
|
135
|
+
};
|
|
136
|
+
export const getHalfPoint = (coordinates) => {
|
|
137
|
+
return new Point(new LineString(coordinates).getCoordinateAt(0.5));
|
|
138
|
+
};
|
|
139
|
+
export const getLabelStyle = (position, text, labelStyle) => {
|
|
140
|
+
if (text.trim() != '') {
|
|
141
|
+
const style = labelStyle.clone();
|
|
142
|
+
style.setGeometry(position);
|
|
143
|
+
style.getText().setText(text);
|
|
144
|
+
return style;
|
|
145
|
+
}
|
|
146
|
+
return undefined;
|
|
147
|
+
};
|
|
148
|
+
export const getRadiusDataForCircle = (circle, defaultStyle, stroke) => {
|
|
149
|
+
const radius = circle.getRadius();
|
|
150
|
+
const center = circle.getCenter();
|
|
151
|
+
const radiusLine = [center, [center[0] + radius, center[1]]];
|
|
152
|
+
const radiusLineStyle = defaultStyle.clone();
|
|
153
|
+
radiusLineStyle.setStroke(stroke);
|
|
154
|
+
radiusLineStyle.getText().setText('');
|
|
155
|
+
radiusLineStyle.setGeometry(new LineString(radiusLine));
|
|
156
|
+
return {
|
|
157
|
+
style: radiusLineStyle,
|
|
158
|
+
radius: radius,
|
|
159
|
+
radiusLine: radiusLine
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
export const getLengthAsMetricText = (length) => {
|
|
163
|
+
if (length) {
|
|
164
|
+
const formatedLength = length > 100 ? (length / 1000).toFixed(2) + ' km' : length.toFixed(2) + ' m';
|
|
165
|
+
return formatedLength;
|
|
166
|
+
}
|
|
167
|
+
return '';
|
|
168
|
+
};
|
|
169
|
+
export const getAreaAsMetricText = (area) => {
|
|
170
|
+
if (area) {
|
|
171
|
+
const formatedArea = area > 10000 ? (area / 1000000).toFixed(2) + ' km²' : area.toFixed(2) + ' m²';
|
|
172
|
+
return formatedArea;
|
|
173
|
+
}
|
|
174
|
+
return '';
|
|
175
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
|
2
|
-
import { getOlayerByName, removeUnwantedOlParams, getDistance,
|
|
2
|
+
import { getOlayerByName, removeUnwantedOlParams, getDistance, getAreaOfPolygon } from './olutils';
|
|
3
3
|
import { Map } from 'ol';
|
|
4
4
|
import BaseLayer from 'ol/layer/Base';
|
|
5
5
|
import Feature from 'ol/Feature';
|
|
@@ -129,7 +129,7 @@ describe('getArea', () => {
|
|
|
129
129
|
]
|
|
130
130
|
];
|
|
131
131
|
stateManager.state.projection = 'EPSG:2056';
|
|
132
|
-
expect(
|
|
132
|
+
expect(getAreaOfPolygon(new Polygon(coordinatesProjected), stateManager.state.projection)).toBe(1000 * 1000);
|
|
133
133
|
// Same polygon as above, but corners are transformed to WGS84 using
|
|
134
134
|
// https://www.swisstopo.admin.ch/en/coordinates-conversion-navref
|
|
135
135
|
const coordinatesGeographic = [
|
|
@@ -143,6 +143,6 @@ describe('getArea', () => {
|
|
|
143
143
|
];
|
|
144
144
|
stateManager.state.projection = 'EPSG:4326';
|
|
145
145
|
// Allow 2% deviation
|
|
146
|
-
expect(
|
|
146
|
+
expect(getAreaOfPolygon(new Polygon(coordinatesGeographic), stateManager.state.projection)).approximately(1000 * 1000, 1000 * 1000 * 0.02);
|
|
147
147
|
});
|
|
148
148
|
});
|
package/tools/utils/utils.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import BaseLayer from '../../models/layers/baselayer';
|
|
2
|
+
import Feature from 'ol/Feature';
|
|
3
|
+
import { Geometry } from 'ol/geom';
|
|
4
|
+
import State from '../state/state';
|
|
2
5
|
/**
|
|
3
6
|
* Checks if the system prefers dark mode.
|
|
4
7
|
* Falls back safely if matchMedia is not supported.
|
|
@@ -57,3 +60,10 @@ export declare const isValidEmail: (email: string) => boolean;
|
|
|
57
60
|
* @param callback Optional Callback after Opacity has been applied
|
|
58
61
|
*/
|
|
59
62
|
export declare const applyOpacityToLayers: (opacity: number, layers: BaseLayer[], callback?: (layer: BaseLayer) => void) => void;
|
|
63
|
+
/**
|
|
64
|
+
* Applies the given Array of Features to the Selection (<code>state.selection.selectedFeatures</code>) depending on the
|
|
65
|
+
* given SelectionMode (via <code>state.selection.selectionMode</code>).
|
|
66
|
+
* @param features Array of Features to add/replace/remove to/from existing selected Features
|
|
67
|
+
* @param state The State to apply the given Features
|
|
68
|
+
*/
|
|
69
|
+
export declare const applyFeaturesToSelection: (features: Feature<Geometry>[], state: State) => void;
|
package/tools/utils/utils.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import { SelectionMode } from '../../models/selection';
|
|
1
2
|
/**
|
|
2
3
|
* Checks if the system prefers dark mode.
|
|
3
4
|
* Falls back safely if matchMedia is not supported.
|
|
4
5
|
* @returns True if system is in dark mode.
|
|
5
6
|
*/
|
|
6
7
|
export const systemIsInDarkMode = () => {
|
|
7
|
-
return (typeof
|
|
8
|
-
typeof
|
|
9
|
-
|
|
8
|
+
return (typeof globalThis !== 'undefined' &&
|
|
9
|
+
typeof globalThis.matchMedia === 'function' &&
|
|
10
|
+
globalThis.matchMedia('(prefers-color-scheme: dark)').matches);
|
|
10
11
|
};
|
|
11
12
|
/**
|
|
12
13
|
* Checks if on Safari.
|
|
@@ -57,14 +58,14 @@ export const hexToRgbaArray = (hex) => {
|
|
|
57
58
|
const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
|
|
58
59
|
hex = hex.replace(shorthandRegex, (_m, r, g, b) => '#' + r + r + g + g + b + b);
|
|
59
60
|
if (hex.length >= 7) {
|
|
60
|
-
r = parseInt(hex.slice(1, 3), 16);
|
|
61
|
-
g = parseInt(hex.slice(3, 5), 16);
|
|
62
|
-
b = parseInt(hex.slice(5, 7), 16);
|
|
61
|
+
r = Number.parseInt(hex.slice(1, 3), 16);
|
|
62
|
+
g = Number.parseInt(hex.slice(3, 5), 16);
|
|
63
|
+
b = Number.parseInt(hex.slice(5, 7), 16);
|
|
63
64
|
if (hex.length === 9) {
|
|
64
65
|
// Contains alpha value
|
|
65
|
-
a = Math.round(100 * (parseInt(hex.slice(7, 9), 16) / 255)) / 100;
|
|
66
|
+
a = Math.round(100 * (Number.parseInt(hex.slice(7, 9), 16) / 255)) / 100;
|
|
66
67
|
}
|
|
67
|
-
if ([r, g, b, a].includes(NaN)) {
|
|
68
|
+
if ([r, g, b, a].includes(Number.NaN)) {
|
|
68
69
|
return null;
|
|
69
70
|
}
|
|
70
71
|
return [r, g, b, a];
|
|
@@ -110,9 +111,7 @@ export const rgbStrToRgbaArray = (rgbaStr) => {
|
|
|
110
111
|
*/
|
|
111
112
|
export const colorToRgbaArray = (color) => {
|
|
112
113
|
let rgbaColor = hexToRgbaArray(color);
|
|
113
|
-
|
|
114
|
-
rgbaColor = rgbStrToRgbaArray(color);
|
|
115
|
-
}
|
|
114
|
+
rgbaColor ??= rgbStrToRgbaArray(color);
|
|
116
115
|
return rgbaColor;
|
|
117
116
|
};
|
|
118
117
|
/**
|
|
@@ -135,3 +134,37 @@ export const applyOpacityToLayers = (opacity, layers, callback) => {
|
|
|
135
134
|
}
|
|
136
135
|
}
|
|
137
136
|
};
|
|
137
|
+
/**
|
|
138
|
+
* Applies the given Array of Features to the Selection (<code>state.selection.selectedFeatures</code>) depending on the
|
|
139
|
+
* given SelectionMode (via <code>state.selection.selectionMode</code>).
|
|
140
|
+
* @param features Array of Features to add/replace/remove to/from existing selected Features
|
|
141
|
+
* @param state The State to apply the given Features
|
|
142
|
+
*/
|
|
143
|
+
export const applyFeaturesToSelection = (features, state) => {
|
|
144
|
+
// Check if we have set a Geometry of the Selection (e.g. Polygon) and additionally filter the given Features
|
|
145
|
+
if (state.selection.selectionGeometry) {
|
|
146
|
+
features = features.filter((feature) => state.selection.selectionGeometry.intersectsExtent(feature.getGeometry().getExtent()));
|
|
147
|
+
}
|
|
148
|
+
switch (state.selection.selectionMode) {
|
|
149
|
+
case SelectionMode.Replace:
|
|
150
|
+
state.selection.selectedFeatures.push(...features);
|
|
151
|
+
break;
|
|
152
|
+
case SelectionMode.Add:
|
|
153
|
+
// Push/Add only Features that are not already in Selection (can happen if you select overlapping Regions
|
|
154
|
+
state.selection.selectedFeatures.push(...features.filter((newlySelectedFeature) => !state.selection.selectedFeatures.some((alreadySelectedFeature) => newlySelectedFeature.getId() === alreadySelectedFeature.getId())));
|
|
155
|
+
break;
|
|
156
|
+
case SelectionMode.Remove:
|
|
157
|
+
for (const featureToRemove of features) {
|
|
158
|
+
const idxOfGmlFeatureToRemove = state.selection.selectedFeatures.findIndex((gmlFeature, _idx, _feature) => featureToRemove.getId() === gmlFeature.getId());
|
|
159
|
+
if (idxOfGmlFeatureToRemove > -1) {
|
|
160
|
+
state.selection.selectedFeatures.splice(idxOfGmlFeatureToRemove, 1);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
const noFeaturesSelected = state.selection.selectedFeatures.length == 0;
|
|
166
|
+
state.interface.selectionComponentVisible = !noFeaturesSelected;
|
|
167
|
+
if (noFeaturesSelected) {
|
|
168
|
+
state.selection.highlightedFeatures = [];
|
|
169
|
+
}
|
|
170
|
+
};
|