ArcGIS OnClick MouseEvent Question.

547
2
09-28-2018 07:46 AM
PaulMitchell3
New Contributor

Hello,

I have this piece of code where I can statically add points to the map

void MainWindow::populatePoints(QList<Point>& locations)
{
  locations.clear();
  locations.append(Point(-11853242.850239, 3922136.795369, SpatialReference::webMercator()));
}

But..what I am trying to figure out is how can I make OnClick event, so every time I click
on the map, it will append a point to the map. I am a fairly new programmer and any guidance to solve
this problem would be much appreciated.

Thank you,
Armando
0 Kudos
2 Replies
LucasDanzinger
Esri Frequent Contributor

You'll want to connect up to the mouseClicked signal coming off the MapView. This will pass through a QMouseEvent, which can be used to create a Point. You can then add that Point as a Graphic.

For example:

  connect(m_mapView, &MapGraphicsView::mouseClicked, this, [this](QMouseEvent& mouseEvent)
  {
    // obtain the map point
    const double screenX = mouseEvent.x();
    const double screenY = mouseEvent.y();
    Point newPoint = m_mapView->screenToLocation(screenX, screenY);

    // create graphic
    Graphic* graphic = new Graphic(newPoint, this);

    // add to overlay
    m_graphicsOverlay->graphics()->append(graphic);
  }
ArmandoGarcia3
New Contributor III

Thank you!!

0 Kudos