Clicking/Hovering on marker

1939
7
11-24-2019 07:03 PM
HaikalSyed
New Contributor

Hi,

I would like to add clicking and hovering functionalities on a marker.

I am currently using a SimpleMarkerSymbol to display a marker. At the moment, I can click on it and it works.

However what I would like is to have a left click that would have a different function to a right click, as well as hovering. I don't think I have seen any examples regarding this.

How I am doing it at the moment is to use onMouseClicked with identifyGraphicsOverlay function in it and later onIdentifyGraphicsOverlayStatusChanged.

Thanks!

0 Kudos
7 Replies
LucasDanzinger
Esri Frequent Contributor

The MouseEvent has some additional properties on it that will let you check whether it is a left or right button click - MouseEvent QML Type | Qt Quick 5.13.2 

Here is some code for you to enable hovering:

import QtQuick 2.6
import QtQuick.Controls 2.2
import Esri.ArcGISRuntime 100.6

ApplicationWindow {
    id: appWindow
    width: 800
    height: 600
    title: "HoverTest"

    // add a mapView component
    MapView {
        anchors.fill: parent
        // set focus to enable keyboard navigation
        focus: true

        // add a map to the mapview
        Map {
            // add the BasemapTopographic basemap to the map
            BasemapTopographic {}
        }

        MouseArea {
            anchors.fill: parent
            hoverEnabled: true

            onPositionChanged: {
                // get mouse coordinates
                console.log(mouse.x, mouse.y, mouse.button);

                // reject mouse event so events go through to mapview
                mouse.accepted = false;
            }

            onClicked: {
                mouse.accepted = false;
            }

            onDoubleClicked: {
                mouse.accepted = false;
            }

            onPressAndHold: {
                mouse.accepted = false;
            }

            onPressed: {
                mouse.accepted = false;
            }

            onReleased: {
                mouse.accepted = false;
            }
        }
    }
}
HaikalSyed
New Contributor

Hi. Thanks for reply.

It seems that the code works for the map since the parent is the MapView.

However, not for the marker (SimpleMarkerSymbol).

I tried putting a MouseArea inside GraphicsOverlay and nothing happens.

0 Kudos
LucasDanzinger
Esri Frequent Contributor

MouseArea will only work if nested under a MapView or SceneView. If you are trying to identify an individual graphic on a mouse movement, you could try calling MapView.identifyGraphicsOverlay() on one of the mouse move signals

0 Kudos
HaikalSyed
New Contributor

In MapView.identifyGraphicsOverlay(), is there anyway to detect left or right click or hovering?

0 Kudos
LucasDanzinger
Esri Frequent Contributor

Hover implies no clicking - just hovering. If you want to perform identify after a click, use the mouseClicked signal - MapQuickView Class | ArcGIS for Developers 

MouseClicked will pass through a QMouseEvent object through as a parameter, and that object contains a method to determine if it was  left, right, or middle button click - QMouseEvent Class | Qt GUI 5.14.0 

0 Kudos
HaikalSyed
New Contributor

First of all, sorry to be asking so many questions.

Secondly, this works for QML?

0 Kudos
LucasDanzinger
Esri Frequent Contributor
0 Kudos