Skip to content

Commit

Permalink
Merge pull request #1107 from geoadmin/fix-pb-603-balloon-drawing-dra…
Browse files Browse the repository at this point in the history
…g-mouse-hover

PB-603: fix hover selected vertex and feature
  • Loading branch information
sommerfe authored Nov 5, 2024
2 parents 1b9a9d1 + 3d3ed08 commit e7cc48f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 56 deletions.
104 changes: 50 additions & 54 deletions src/modules/drawing/components/DrawingTooltip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,66 +86,62 @@ function onPointerMove(event) {
let featureDrawingMode = featureUnderCursor?.get('type').toUpperCase()
let translationKeys
if (hoveringSelectedFeature) {
mapElement.classList.add(cssGrab)
mapElement.classList.remove(cssPointer)
let hoveringVertex = getVertexCoordinates(featureUnderCursor).some((coordinate) => {
let pixel = olMap.getPixelFromCoordinate(coordinate)
return pointWithinTolerance(pixel, event.pixel, DRAWING_HIT_TOLERANCE)
})
// Display a help tooltip when modifying
if (hoveringVertex || pointFeatureTypes.includes(featureDrawingMode)) {
translationKeys = `modify_existing_vertex_${featureDrawingMode}`
} else {
translationKeys = `modify_new_vertex_${featureDrawingMode}`
}
} else if (hoveringSelectableFeature) {
mapElement.classList.add(cssPointer)
mapElement.classList.remove(cssGrab)
if (drawingMode.value) {
if (this.currentlySketchedFeature && !pointFeatureTypes.includes(drawingMode.value)) {
let hoveringFirstVertex = false
let hoveringLastVertex = false
// The last two coordinates seem to be some OL internal points we don't need.
let coordinates = getVertexCoordinates(this.currentlySketchedFeature).slice(0, -2)
coordinates.some((coordinate, index) => {
let pixel = olMap.getPixelFromCoordinate(coordinate)
if (pointWithinTolerance(pixel, event.pixel, DRAWING_HIT_TOLERANCE)) {
hoveringFirstVertex = index === 0
hoveringLastVertex = index === coordinates.length - 1
// Abort loop. We have what we need.
return true
}
})
// Display a help tooltip when selecting
if (drawingMode.value) {
translationKeys = `select_feature_${drawingMode.value}`
if (hoveringFirstVertex && coordinates.length > 2) {
translationKeys = `draw_snap_first_point_${drawingMode.value}`
} else if (hoveringLastVertex && coordinates.length > 1) {
translationKeys = `draw_snap_last_point_${drawingMode.value}`
} else {
translationKeys = `draw_next_${drawingMode.value}`
}
if (coordinates.length > 1) {
translationKeys = [translationKeys, 'draw_delete_last_point']
}
} else {
translationKeys = 'select_no_feature'
translationKeys = `draw_start_${drawingMode.value}`
}
} else {
mapElement.classList.remove(cssPointer)
mapElement.classList.remove(cssGrab)
// Display a help tooltip when drawing
if (drawingMode.value) {
if (this.currentlySketchedFeature && !pointFeatureTypes.includes(drawingMode.value)) {
let hoveringFirstVertex = false
let hoveringLastVertex = false
// The last two coordinates seem to be some OL internal points we don't need.
let coordinates = getVertexCoordinates(this.currentlySketchedFeature).slice(0, -2)
coordinates.some((coordinate, index) => {
let pixel = olMap.getPixelFromCoordinate(coordinate)
if (pointWithinTolerance(pixel, event.pixel, DRAWING_HIT_TOLERANCE)) {
hoveringFirstVertex = index === 0
hoveringLastVertex = index === coordinates.length - 1
// Abort loop. We have what we need.
return true
}
})
if (hoveringFirstVertex && coordinates.length > 2) {
translationKeys = `draw_snap_first_point_${drawingMode.value}`
} else if (hoveringLastVertex && coordinates.length > 1) {
translationKeys = `draw_snap_last_point_${drawingMode.value}`
} else {
translationKeys = `draw_next_${drawingMode.value}`
}
if (hoveringSelectedFeature) {
let hoveringVertex = getVertexCoordinates(featureUnderCursor).some((coordinate) => {
let pixel = olMap.getPixelFromCoordinate(coordinate)
return pointWithinTolerance(pixel, event.pixel, DRAWING_HIT_TOLERANCE)
})
translationKeys = `select_feature_${featureDrawingMode}`
if (hoveringVertex) {
translationKeys = `modify_existing_vertex_${featureDrawingMode}`
mapElement.classList.remove(cssPointer)
mapElement.classList.add(cssGrab)
} else {
mapElement.classList.add(cssPointer)
mapElement.classList.remove(cssGrab)
}
} else if (hoveringSelectableFeature) {
mapElement.classList.add(cssPointer)
mapElement.classList.remove(cssGrab)
if (coordinates.length > 1) {
translationKeys = [translationKeys, 'draw_delete_last_point']
}
// Display a help tooltip when selecting
if (featureDrawingMode) {
translationKeys = `select_feature_${featureDrawingMode}`
} else {
translationKeys = `draw_start_${drawingMode.value}`
translationKeys = 'select_no_feature'
}
} else {
translationKeys = 'select_no_feature'
Expand Down
5 changes: 3 additions & 2 deletions src/modules/drawing/lib/drawingUtils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LineString, Polygon } from 'ol/geom'
import { LineString, Point, Polygon } from 'ol/geom'

/**
* Checks if point is at target within tolerance.
Expand Down Expand Up @@ -33,9 +33,10 @@ export function getVertexCoordinates(feature) {

if (geometry) {
const coordinates = geometry.getCoordinates()

if (geometry instanceof LineString) {
normalized = coordinates
} else if (geometry instanceof Point) {
normalized = [coordinates]
} else if (geometry instanceof Polygon) {
normalized = coordinates[0]
}
Expand Down

0 comments on commit e7cc48f

Please sign in to comment.