-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'map/feature/area-measurements' of github.com:EOX-A/EOxE…
…lements into map/feature/area-measurements
- Loading branch information
Showing
34 changed files
with
579 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ jobs: | |
check-latest: true | ||
|
||
- name: Cache node_modules 📦 | ||
uses: actions/[email protected].1 | ||
uses: actions/[email protected].2 | ||
with: | ||
path: ~/.npm | ||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ jobs: | |
check-latest: true | ||
|
||
- name: Cache node_modules 📦 | ||
uses: actions/[email protected].1 | ||
uses: actions/[email protected].2 | ||
with: | ||
path: ~/.npm | ||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ jobs: | |
check-latest: true | ||
|
||
- name: Cache node_modules 📦 | ||
uses: actions/[email protected].1 | ||
uses: actions/[email protected].2 | ||
with: | ||
path: ~/.npm | ||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
elements/drawtools/src/methods/draw/create-select-handler.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Factory function to create a select event handler | ||
* @param {import("../../main").EOxDrawTools} EoxDrawTool - The drawing tool instance. | ||
*/ | ||
const createSelectHandler = (EoxDrawTool) => { | ||
/** | ||
* Copy the selected feature to the draw layer | ||
* and dispatches an event to add the feature to the map. | ||
* | ||
* @param {*} e | ||
*/ | ||
const selectHandler = (e) => { | ||
if (e?.detail.id !== "SelectLayerClickInteraction" || !e.detail.feature) { | ||
return; | ||
} | ||
EoxDrawTool.drawLayer.getSource().addFeature(e.detail.feature); | ||
EoxDrawTool.eoxMap.dispatchEvent( | ||
new CustomEvent("addfeatures", { detail: e.detail }), | ||
); | ||
}; | ||
|
||
/** | ||
* Adds the selection event to the map | ||
**/ | ||
const addSelectionEvent = () => { | ||
if (EoxDrawTool.layerId) { | ||
const hoverInteraction = | ||
EoxDrawTool.eoxMap.selectInteractions["SelectLayerHoverInteraction"]; | ||
hoverInteraction.setActive(true); | ||
EoxDrawTool.eoxMap.addEventListener("select", selectHandler); | ||
} | ||
}; | ||
|
||
/** | ||
* Removes the selection event from the map and resets the selected features | ||
**/ | ||
const removeSelectionEvent = () => { | ||
const hoverInteraction = | ||
EoxDrawTool.eoxMap.selectInteractions?.["SelectLayerHoverInteraction"]; | ||
if (hoverInteraction) { | ||
hoverInteraction.selectedFids = []; | ||
hoverInteraction.setActive(false); | ||
} | ||
EoxDrawTool.eoxMap.removeEventListener("select", selectHandler); | ||
}; | ||
|
||
return { addSelectionEvent, removeSelectionEvent }; | ||
}; | ||
|
||
export default createSelectHandler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { initSelection } from "."; | ||
|
||
/** | ||
* handles switching between selection and drawing and updates of the selection layer | ||
* | ||
* @param {import("../../main").EOxDrawTools} EoxDrawTool | ||
* @param {import("@eox/map/src/main").EOxMap} EoxMap | ||
* @param {string} oldLayerId | ||
* @param {string} updatedLayerId | ||
* @returns | ||
*/ | ||
const handleLayerId = (EoxDrawTool, EoxMap, updatedLayerId, oldLayerId) => { | ||
if (!EoxMap) { | ||
return; | ||
} | ||
|
||
if (updatedLayerId) { | ||
if (oldLayerId && updatedLayerId !== oldLayerId) { | ||
exitSelection(EoxDrawTool, EoxMap); | ||
initSelection(EoxDrawTool, EoxMap, updatedLayerId); | ||
} else { | ||
initSelection(EoxDrawTool, EoxMap, updatedLayerId); | ||
} | ||
return; | ||
} | ||
|
||
if (!updatedLayerId && oldLayerId) { | ||
exitSelection(EoxDrawTool, EoxMap); | ||
return; | ||
} | ||
}; | ||
|
||
export default handleLayerId; | ||
|
||
/** | ||
* Exits the selection mode and reverts the selection layer to its original state | ||
* | ||
* @param {import("../../main").EOxDrawTools} EoxDrawTool | ||
* @param {import("@eox/map").EOxMap} EoxMap | ||
*/ | ||
function exitSelection(EoxDrawTool, EoxMap) { | ||
if (!EoxMap) { | ||
return; | ||
} | ||
EoxDrawTool.discardDrawing(); | ||
EoxDrawTool.selectionEvents.removeSelectionEvent(); | ||
EoxDrawTool.draw = /** @type {import("ol/interaction").Draw} */ ( | ||
EoxMap.interactions["drawInteraction"] | ||
); | ||
EoxMap.selectInteractions["SelectLayerClickInteraction"].remove(); | ||
EoxMap.selectInteractions["SelectLayerHoverInteraction"].remove(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.