Select to view content in your preferred language

Drawing on the map with mouse gestures

1138
3
Jump to solution
09-20-2018 01:12 AM
GabeLevy
Emerging Contributor

Hi,

I'm working on an application that needs to allow the user to draw certain graphical objects on top of the map view (in MapGraphicsView). The problem I'm having is, to some extent, related also to the default behavior of the MapGraphicsView when the user presses the left mouse button and moving the mouse while holding the button down. The default behavior is that when the user moves the mouse with the left button down, it pans the map.

I've learnt the intended way to stop the map from being panned by calling accept() on the event object inside the geoViewMouseMoveEvent virtual method of my subclass.

Now what I need to achieve is to draw in response to the mouse movement, for instance a line from the starting point where the user pressed down the mouse, to the current mouse cursor position in real time while the user keeps the button down. I also will need to show some tooltip-like numerical info along the drawn line.

When I call accept() on the event object, it not only stops the map from being panned, but it also stops any paintEvent to be fired while moving the mouse with the button pressed (and consequentially no drawForground or drawBackground get called) until the accept() stops being called.

I tried to call update() from inside the geoViewMouseMoveEvent hoping that it would coerce the MapGraphicsView to call painting  methods but with no success.

My question is:

How do I achieve painting/redrawing to be called while blocking the map panning (as described above) when the user presses the left mouse button down and drags the mouse?

Thank you in advance

Gabe

mapgraphicsview‌ #painting

0 Kudos
1 Solution

Accepted Solutions
LucasDanzinger
Esri Frequent Contributor

You should be able to accept the mouse signals and draw on the screen. An engineer on our team wrote up a simple example of this (attached). Can you give this a try?

View solution in original post

3 Replies
LucasDanzinger
Esri Frequent Contributor

You should be able to accept the mouse signals and draw on the screen. An engineer on our team wrote up a simple example of this (attached). Can you give this a try?

GabeLevy
Emerging Contributor

Hi Lucas,

Thanks for the reply and the sample code.

I tried the concept from your team's example but implemented it in our real project and yes, it does work. Thank you for the guidance.

The error I've made was that I wanted to bypass the Scene/GraphicsItem paradigm and draw some simple things directly in MapGraphicsView::drawForeground(...) method of my subclass by handling the mouseMoveEvent on the said view class. I assumed that both ways would interchangeably work, which is obviously not the case.

It's better to follow the Scene/GraphicsItem paradigm anyway to make the "separation of concerns" principle more uniform.

Thanks again.

Gabe

0 Kudos
LucasDanzinger
Esri Frequent Contributor

@GabeLevy - the 100.12 release of ArcGIS Runtime now supports a SketchEditor, which greatly simplifies the workflow for sketching geometries on a map. This might be something worth considering integrating into your app. More details are in the release blog - https://community.esri.com/t5/arcgis-runtime-sdks-blog/sketcheditor-now-available-in-the-arcgis-runt... 

0 Kudos