SketchEditor starting fine but can't draw polygon on map?

655
5
Jump to solution
02-01-2023 08:20 PM
NothernCoder
New Contributor III

Good evening all, hope you're doing well. Wondering if anyone else has ran into this issue trying to use the new SketchEditor class introduced in 100.12.0. I have a QWidget button that calls the following method to start drawing a polygon but it's not showing anything on my map view AppView. I got the code below from the official doc C++ SketchEditor

Any help would be greatly appreciated thank you. 

void AppView::startSketching()
{
	Esri::ArcGISRuntime::SketchEditor* sketchEditor = new SketchEditor(this);
	setSketchEditor(sketchEditor);
	sketchEditor->start(SketchCreationMode::Polygon);
	Geometry sketchGeometry = sketchEditor->geometry();
	sketchEditor->stop();
}

 

0 Kudos
1 Solution

Accepted Solutions
TroyFoster
Occasional Contributor

Visual Studio versus QtCreator, they just abstract away a lot of the setup magic to get code working. Code is Code and if the setup is correct and works on one you should be able to copy/paste snippets from one to the other and it should work.

Confirm your assumptions that the buttons are wired up for the start and stop sketching functions by putting a qdebug/cout/print statement right at the beginning of it saying you made it there.

Calling sketchEditor->start returns a bool value whether it started successfully or not, print that out.

Why is your work inheriting from MapView?  Is that the pattern your professor gave to you or is that how Visual Studio makes new projects?

Welcome to the wide world of debugging, this is what makes or breaks a good software developer.

For reward, if I help fix your problem, then accept it as a solution.  I just realized yesterday that this subforum has a widget that shows who has the most accepted solutions for the past month and I am currently doing better than the Esri employees and want to brag about that when I see them at FedGIS next week and at devsummit in a month lol.

View solution in original post

5 Replies
TroyFoster
Occasional Contributor

code examples from the Esri github tend to be better than the announcements pages in my opinion 

https://github.com/Esri/arcgis-maps-sdk-samples-qt/blob/main/ArcGISRuntimeSDKQt_CppSamples/DisplayIn...

 

From what it looks to me in your code is that you need to have the sketchEditor be a class level variable and add a stopSketching function wired into a second button with lines 6 and 7 from your code snippet moved to it.

// in your header file, initialize as nullptr so that you can protect against out of order button clicking
Esri::ArcGISRuntime::SketchEditor* sketchEditor = nullptr;

// in your implementation file
void AppView::startSketching()
{
	if (sketchEditor == nullptr)
	{
		sketchEditor = new SketchEditor(this);
		setSketchEditor(sketchEditor);
	}
	sketchEditor->start(SketchCreationMode::Polygon);
}
void AppView::stopSketching()
{
	if (sketchEditor == nullptr)
	{
		return;// TODO log an error before return
	}
	Geometry sketchGeometry = sketchEditor->geometry();// TODO do something with the geometry?
	sketchEditor->stop();
}

 

NothernCoder
New Contributor III

Good afternoon @TroyFoster and thank you for the quick reply. I've been playing with the code example you posted and still don't see the line being drawn on the map. The Github repo is for QT Creator and I'm doing my coding in Visual Studio unfortunately (it's what the school requires). I can run the SketchEditor sample just fine in QT Creator and see what it's supposed to look like. Wonder what the difference is?

Here's the latest code snippet:

// reacts to SketchEditor Line button
void AppView::startSketching()
{
    if (sketchEditor == nullptr)
    {
        sketchEditor = new SketchEditor(this);
	setSketchEditor(sketchEditor);
    }
    sketchEditor->start(SketchCreationMode::Polygon);
}

// reacts to SketchEditor Save Edits button
void AppView::stopSketching()
{
    if (sketchEditor == nullptr)
    {
        qDebug() << "SketchEditor is null";
	return;
    }
    Geometry sketchGeometry = sketchEditor->geometry();
    SimpleFillSymbol sketchFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle::Solid, QColor(67, 166, 198, 119), new 
SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor(67, 166, 198), 2.0, this), this);
    Graphic* sketchGraphic = new Graphic(sketchGeometry, sketchFillSymbol, this);
    sketchEditorGraphics(sketchGraphic);
    graphicsOverlay->graphics()->append(sketchGraphic);
    sketchEditor->stop();
}

 

Thanks again and we can talk a reward if I can get this solved 🙂

0 Kudos
TroyFoster
Occasional Contributor

Visual Studio versus QtCreator, they just abstract away a lot of the setup magic to get code working. Code is Code and if the setup is correct and works on one you should be able to copy/paste snippets from one to the other and it should work.

Confirm your assumptions that the buttons are wired up for the start and stop sketching functions by putting a qdebug/cout/print statement right at the beginning of it saying you made it there.

Calling sketchEditor->start returns a bool value whether it started successfully or not, print that out.

Why is your work inheriting from MapView?  Is that the pattern your professor gave to you or is that how Visual Studio makes new projects?

Welcome to the wide world of debugging, this is what makes or breaks a good software developer.

For reward, if I help fix your problem, then accept it as a solution.  I just realized yesterday that this subforum has a widget that shows who has the most accepted solutions for the past month and I am currently doing better than the Esri employees and want to brag about that when I see them at FedGIS next week and at devsummit in a month lol.

NothernCoder
New Contributor III

Good morning and yeah it's just the way I set it up, I can easily change that to the main app widget and just call it there. Only difference I see is that the ArcGIS team loves to use QML files in all their samples. I have a QWidget based app and not QQuick. This forced me to see what the buttons do in the .qml file and try to duplicate that in a form file where I placed the buttons that trigger the line, point, multipoint, etc... Wonder if that missing .qml file is the issue?

As far as the reward goes, great accomplishment btw. Not too sure what we users would do without these forums as the official support docs are majorly lacking in any type of help whatsoever. Even a paid tech support number would do wonders as this isn't the easiest framework to work with. I'll keep at it and see if I can get this to work. If I do I'll set your solution as solved. Have fun at the conferences and hopefully see my reply with SUCCESS soon 🙂

0 Kudos
NothernCoder
New Contributor III

Good day @TroyFoster,

I ended up making my own class using the SketchEditor class as a parent. Seems to be working well now. Still looking why the parent methods don't seem to work. For example I had to manually create the required SimpleLineSymbol and SimpleMarkerSymbol to use on my AppView graphicOverlay.

A million thanks and all the best. Hope this helps others and to the ArcGis QT team, please please please think deeply of doing Visual Studio / VS Code based tutorials and samples as I'm sure they're more popular IDEs versus QT Creator.

0 Kudos