How to implement draw functionality of polylines/polygons in ArcGIS SDK 100.0

752
3
Jump to solution
06-22-2017 01:41 AM
DarkRider
New Contributor II

In ArcGIS 10.2.6 there was sample code about drawing polylines. I am now using the ArcGIS 100.0 SDK trying to implment the same functionality there but it does not work somehow. Nothing is shown on the map.

This is the code I am currently using:

When clicking left on the map, this code is executed:

if(!m_currentPolylineStarted)
        {
            m_currentPolyLineBuilder.addPoint(mapPointMouse);
            m_currentPolylineGraphic = new Esri::ArcGISRuntime::Graphic(m_currentPolyLineBuilder.toGeometry(), this);           
            m_graphicsLayer->graphics()->append(m_currentPolylineGraphic);
            
m_currentPolylineStarted = true;
//            m_currentPolyline.startPath(mapPointMouse);
//            m_currentPolyline.lineTo(mapPointMouse);
//            Esri::ArcGISRuntime::Graphic* graphic = new Esri::ArcGISRuntime::Graphic(Esri::ArcGISRuntime::Polyline(m_currentPolyline), Esri::ArcGISRuntime::SimpleLineSymbol(Qt::red, 1));
//            m_currentPolylineId = m_graphicsLayer->graphics()->append(graphic);
}
        else
        {
            m_currentPolyLineBuilder.addPoint(mapPointMouse);
            m_currentPolylineGraphic->setGeometry(m_currentPolyLineBuilder.toGeometry());
//            m_currentPolyline.lineTo(mapPointMouse);
//            m_graphicsLayer->updateGraphic(m_currentPolylineId, new Esri::ArcGISRuntime::Graphic(Esri::ArcGISRuntime::Polyline(m_currentPolyline), Esri::ArcGISRuntime::SimpleLineSymbol(Qt::red, 1)));
        }

where mapPointMouse is the current mouse point position. The commented code was the old way (using ArcGIS SDK 10.2.6 which worked fine.

What am I doing wrong?

Are there samples providing the same functionality on the new ArcGIS SDK 100.0?

Thanks in advance

0 Kudos
1 Solution

Accepted Solutions
DarkRider
New Contributor II

Hi Luke,

I've added a simpleLineSymbol, but I also find out that my mapPointMouse was in the wrong spatial reference system. My Polylinebuilder is using spatialReference WGS84 while my mapPointMouse is not georeferenced. When I put in the right coordinate values, it works! 

            m_currentPolyLineBuilder.addPoint(mapPointMouse);
            Esri::ArcGISRuntime::SimpleLineSymbol simpleLineSymbol;
            simpleLineSymbol.setColor(Qt::red);
            simpleLineSymbol.setWidth(2);
            simpleLineSymbol.setStyle(Esri::ArcGISRuntime::SimpleLineSymbolStyle::Solid);
            m_currentPolylineGraphic = new Esri::ArcGISRuntime::Graphic(m_currentPolyLineBuilder.toGeometry(), &simpleLineSymbol);
            m_graphicsLayer->graphics()->append(m_currentPolylineGraphic);
            m_currentPolylineStarted = true;

Thank you!

View solution in original post

0 Kudos
3 Replies
LukeSmallwood
Esri Contributor

Hi there,

Can you try providing the Graphic* that you create with a Symbol (for example a SimpleLineSymbol). The Graphic class should have c'tor that accepts a Symbol* or you can call Graphic::setSymbol.

Let me know if that helps.

Thanks, Luke

0 Kudos
DarkRider
New Contributor II

Hi Luke,

I've added a simpleLineSymbol, but I also find out that my mapPointMouse was in the wrong spatial reference system. My Polylinebuilder is using spatialReference WGS84 while my mapPointMouse is not georeferenced. When I put in the right coordinate values, it works! 

            m_currentPolyLineBuilder.addPoint(mapPointMouse);
            Esri::ArcGISRuntime::SimpleLineSymbol simpleLineSymbol;
            simpleLineSymbol.setColor(Qt::red);
            simpleLineSymbol.setWidth(2);
            simpleLineSymbol.setStyle(Esri::ArcGISRuntime::SimpleLineSymbolStyle::Solid);
            m_currentPolylineGraphic = new Esri::ArcGISRuntime::Graphic(m_currentPolyLineBuilder.toGeometry(), &simpleLineSymbol);
            m_graphicsLayer->graphics()->append(m_currentPolylineGraphic);
            m_currentPolylineStarted = true;

Thank you!

View solution in original post

0 Kudos
LukeSmallwood
Esri Contributor

Excellent - I'm glad that's working for you now.

It might be worth making the SimpleLineSymbol a ptr type - I'm not sure what will happen when the local simpleLineSymbol goes out of scope and is destructed since the Graphic will continue to exist and need to be rendered...

You may also want to consider giving your other ptr objects (e.g. the Graphic) a parent QObject so that they are cleaned up. For example you could pass "this" as the parent to these types if you want them to be cleaned up when the current object is destroyed.