Select to view content in your preferred language

Draw a point with a number received from a class in another file in C++.

746
2
Jump to solution
05-31-2021 11:38 PM
KanjaSousuke
Emerging Contributor

I want to draw a point with a number received from a class in another file.

The value is received, no error, but not drawn.

I'm still a beginner when it comes to C++.

Maps file:

CppMaps::CppMaps(QObject* parent /* = nullptr */):   QObject(parent)
{
        m_map = new Map(BasemapStyle::ArcGISTopographic, this);
        myPointBuilder = new PointBuilder(SpatialReference(6668), this);
        myGraph = new Graphic();
        mySymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle::Circle, QColor("red"), 10, this);
        myGraphOverLay = new GraphicsOverlay(this);

        myGraph->setSymbol(mySymbol);
        myGraphOverLay->graphics()->append(myGraph);

}

CppMaps::~CppMaps()
{
}

MapQuickView* CppMaps::mapView() const
{
    return m_mapView;
}

void CppMaps::setMapView(MapQuickView* mapView)
{
    if (!mapView || mapView == m_mapView)
    {
        return;
    }

    m_mapView = mapView;
    m_mapView->setMap(m_map);

    m_mapView->graphicsOverlays()->append(myGraphOverLay);
}

void CppMaps::fnGetShow(double lat,double lon)
{
    myPointBuilder->setXY(lon , lat);
    myGraph->setGeometry(myPointBuilder->toGeometry());
}

 

Sender file:

void Sender::fnSend(){
    CppMaps cppMap;
    cppMap.fnGetShow(lat, lon); //lat = 0
    lon++;
}

 

fnSend() is running on a one-second cycle in QML.

0 Kudos
1 Solution

Accepted Solutions
LucasDanzinger
Esri Frequent Contributor

Couple of things I see that could be going wrong:

 

1) In your "sender file", it is creating a new instance of CppMaps each time fsSend executes. Is this what you want, or do you want to update the map with new coordinates?

2) Is the spatial reference you are using correct? Your builder uses wkid 6668 - are the coordinates coming in from that coordinate system or do they need to be projected from one coordinate system to another?

3) Not required, but you could bypass the builder and just create a Point directly from the x/y coordinates that come through

View solution in original post

0 Kudos
2 Replies
LucasDanzinger
Esri Frequent Contributor

Couple of things I see that could be going wrong:

 

1) In your "sender file", it is creating a new instance of CppMaps each time fsSend executes. Is this what you want, or do you want to update the map with new coordinates?

2) Is the spatial reference you are using correct? Your builder uses wkid 6668 - are the coordinates coming in from that coordinate system or do they need to be projected from one coordinate system to another?

3) Not required, but you could bypass the builder and just create a Point directly from the x/y coordinates that come through

0 Kudos
KanjaSousuke
Emerging Contributor

Thanks.

It seems that C++ is still not my strong point.

I had to create a new instance every time.

0 Kudos