Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add survey generation functionality #1347

Merged

Conversation

rafaellehmkuhl
Copy link
Member

@rafaellehmkuhl rafaellehmkuhl commented Sep 19, 2024

Kapture.2024-09-19.at.01.00.41.mp4

Fix #646

@rafaellehmkuhl rafaellehmkuhl force-pushed the add-survey-generator branch 2 times, most recently from 1ef3ffa to 64296f5 Compare September 19, 2024 03:58
@rafaellehmkuhl rafaellehmkuhl marked this pull request as ready for review September 19, 2024 04:06
Copy link
Contributor

@ArturoManzoli ArturoManzoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some points to improve:
1- The cursor when creating the survey polygon is a hand (grab), but a pointer or another type would be more fit to the task;

2- Is there a way to delete some added points? I accidentally added some unwanted ones on my tests;

3- An undo icon or CTRL+Z hotkey should be added. Sometimes I added some bizarre unintentional points and the polygon got very weird. I had to restart the task in order to get the polygon I wanted.

4- There was an odd issue with the 'distance-between-lines' number input. When I clicked the arrow to increase the value, it went full auto-mode all the way to the max value (video):

Screenshare.-.2024-09-20.10_05_27.AM.mp4

@rafaellehmkuhl
Copy link
Member Author

Some points to improve: 1- The cursor when creating the survey polygon is a hand (grab), but a pointer or another type would be more fit to the task;

2- Is there a way to delete some added points? I accidentally added some unwanted ones on my tests;

3- An undo icon or CTRL+Z hotkey should be added. Sometimes I added some bizarre unintentional points and the polygon got very weird. I had to restart the task in order to get the polygon I wanted.

4- There was an odd issue with the 'distance-between-lines' number input. When I clicked the arrow to increase the value, it went full auto-mode all the way to the max value (video):

  • Will do 1 and 2 immediately.
  • Item 3 I think will be fulfilled with the delete functionality on item 2, right?
  • About item 4, could you check if it's this was not something like a pressed enter button on your machine? I really tried to reproduce the problem here, but has no success, and there's nothing in the code that I can see that could create such a situation.

Copy link
Contributor

@ArturoManzoli ArturoManzoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I think the problem with the increasing values was indeed in my local browser.

I'll just suggest one more UX improvement:
With the 'X' icon permanently on the waypoint, it was a little confusing to the user what would happen if he touches it.

Try this implementation (video below), where the keyboard 'shift', when pressed, will swap the icon from the blue dot to the red X and will also change the function from drag to delete the survey point:

let isShiftPressed = false
let hoveredMarkers: L.Marker[] = [] 

window.addEventListener('keydown', (event) => {
  if (event.key === 'Shift') {
    isShiftPressed = true
    updateHoveredMarkers() 
  }
})

window.addEventListener('keyup', (event) => {
  if (event.key === 'Shift') {
    isShiftPressed = false
    updateHoveredMarkers() 
  }
})

const updateHoveredMarkers = (): void => {
  hoveredMarkers.forEach((marker) => {
    const icon = marker.getElement()?.querySelector('.delete-icon') as SVGGElement
    if (icon) {
      icon.style.display = isShiftPressed ? 'block' : 'none' // Show or hide the delete icon based on Shift key state
    }
  })
}

const addVertexAtEdge = (edgeIndex: number, latlng: L.LatLng): void => {
  surveyPolygonPoints.value.splice(edgeIndex + 1, 0, latlng)
  const newMarker = L.marker(latlng, {
    icon: customIcon,
    draggable: true,
  })
    .on('drag', () => {
      updatePolygon()
      createSurveyPath()
    })
    .on('mouseover', (event: L.LeafletEvent) => {
      const target = event.target as L.Marker
      hoveredMarkers.push(target) // Add marker to hovered list
      updateHoveredMarkers() // Check and update the icon when hovered
    })
    .on('mouseout', (event: L.LeafletEvent) => {
      const target = event.target as L.Marker
      const icon = target.getElement()?.querySelector('.delete-icon') as SVGGElement
      if (icon) icon.style.display = 'none'
      // Remove marker from hovered list when mouse leaves
      hoveredMarkers = hoveredMarkers.filter((m) => m !== target)
    })
    .on('click', (event: L.LeafletEvent) => {
      if (isShiftPressed) {
        const target = event.target as L.Marker
        const index = surveyPolygonMarkers.value.indexOf(target)
        if (index !== -1) {
          surveyPolygonPoints.value.splice(index, 1)
          surveyPolygonMarkers.value.splice(index, 1)
          target.remove()
          updatePolygon()
          updateEdgeMarkers()
          checkAndRemoveSurveyPath()
          createSurveyPath()
        }
      }
    })
    .addTo(planningMap.value!)
  surveyPolygonMarkers.value.splice(edgeIndex + 1, 0, newMarker)
  updatePolygon()
  updateEdgeMarkers()
  createSurveyPath()
}

const addSurveyPoint = (e: L.LeafletMouseEvent): void => {
  if (!isCreatingSurvey.value) return
  const newPoint = e.latlng
  surveyPolygonPoints.value.push(newPoint)
  const marker = L.marker(newPoint, {
    icon: customIcon,
    draggable: true,
  })
    .on('drag', (event: L.LeafletEvent) => {
      if (!isShiftPressed) { // Allow dragging only when Shift is not pressed
        const target = event.target as L.Marker
        const index = surveyPolygonMarkers.value.indexOf(target)
        if (index !== -1) {
          surveyPolygonPoints.value[index] = target.getLatLng()
        }
        updatePolygon()
        updateEdgeMarkers()
        createSurveyPath()
      }
    })
    .on('mouseover', (event: L.LeafletEvent) => {
      const target = event.target as L.Marker
      hoveredMarkers.push(target) // Add marker to hovered list
      updateHoveredMarkers() // Check and update the icon when hovered
    })
    .on('mouseout', (event: L.LeafletMouseEvent) => {
      const target = event.target as L.Marker
      const icon = target.getElement()?.querySelector('.delete-icon') as SVGGElement
      if (icon) icon.style.display = 'none'
      // Remove marker from hovered list when mouse leaves
      hoveredMarkers = hoveredMarkers.filter((m) => m !== target)
    })
    .on('click', (event: L.LeafletMouseEvent) => {
      if (isShiftPressed) {
        const target = event.target as L.Marker
        const index = surveyPolygonMarkers.value.indexOf(target)
        if (index !== -1) {
          surveyPolygonPoints.value.splice(index, 1)
          surveyPolygonMarkers.value.splice(index, 1)
          target.remove()
          updatePolygon()
          updateEdgeMarkers()
          checkAndRemoveSurveyPath()
          createSurveyPath()
        }
      }
    })
    .addTo(planningMap.value!)
  surveyPolygonMarkers.value.push(marker)
  updatePolygon()
  updateEdgeMarkers()
  createSurveyPath()
}
Screenshare.-.2024-09-20.2_25_36.PM.mp4

@rafaellehmkuhl
Copy link
Member Author

Nice, I think the problem with the increasing values was indeed in my local browser.

I'll just suggest one more UX improvement: With the 'X' icon permanently on the waypoint, it was a little confusing to the user what would happen if he touches it.

Try this implementation (video below), where the keyboard 'shift', when pressed, will swap the icon from the blue dot to the red X and will also change the function from drag to delete the survey point:

Humnnn.....

I get the problem. The user will not know that they can drag the marker or if it will just be deleted, although dragging markers is very conventional.

On the other hand, I don't much like the shift approach as the user has to find out that they have this shift functionality, and it's also not mobile-friendly.

I'm thinking about opening a small popup that has the delete button when the user hovers or clicks the marker. What do you think?

This package will be used for geo-data calculations. The first usage will be the implementation of the survey paths, where it helps to find the intersections of the path lines with the surrounding polygon.
@ArturoManzoli
Copy link
Contributor

ArturoManzoli commented Sep 23, 2024

I'm thinking about opening a small popup that has the delete button when the user hovers or clicks the marker. What do you think?

Sounds very good. Some design software like the Autodesk Inventor and Fusion use this approach. It can vary from a single popup icon to a very complete list of actions.

@rafaellehmkuhl rafaellehmkuhl force-pushed the add-survey-generator branch 2 times, most recently from 48de343 to cf0a37c Compare September 23, 2024 18:00
@rafaellehmkuhl
Copy link
Member Author

I'm thinking about opening a small popup that has the delete button when the user hovers or clicks the marker. What do you think?

Sounds very good. Some design software like the Autodesk Inventor and Fusion use this approach. It can vary from a single popup icon to a very complete list of actions.

Done!

@rafaellehmkuhl rafaellehmkuhl requested review from ArturoManzoli and removed request for ArturoManzoli September 23, 2024 18:09
@ArturoManzoli ArturoManzoli merged commit 70063b8 into bluerobotics:master Sep 23, 2024
10 checks passed
@rafaellehmkuhl rafaellehmkuhl deleted the add-survey-generator branch September 23, 2024 19:18
@ES-Alexander ES-Alexander added the docs-needed Change needs to be documented label Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs-needed Change needs to be documented
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request - Mission planning
3 participants