Implementing a Unique Value Renderer for Graphics Layers

1858
7
03-09-2017 10:35 AM
MichaelGreene2
New Contributor II

Hi QT SDK community,

I'm looking to use a Unique Value Renderer in order to display different colored lines connecting from the ground to points in the sky. I have read ESRI's webpage about different rendering processes, and I think the Unique Value Renderer is what I need to be using. I've created a unique value denoted as "QString uniqueString", which I think I need as a unique ID in order to render properly. uniqueString contains unique values to the objects in the sky that I am trying to project lines from. "Qcolor lineColor" contain the unique colors that I want the lines to be. Below is the code I am using that does not compile.

void addLineOfSightToMapFunc(Point deviceLocation, Point satLocation,Esri::ArcGISRuntime::SceneGraphicsView* m_sceneView, QColor lineColor,QString uniqueString,mn::GraphicsOverlay* lineGraphicOverlay, MapRay *thisF )
{
    mn::UniqueValueRenderer* LOS= new mn:: UniqueValueRenderer(thisF);
    // create a graphics overlay for the lines
    lineGraphicOverlay->sceneProperties().setSurfacePlacement(mn::SurfacePlacement::Absolute);
    lineGraphicOverlay->setSceneProperties(mn::LayerSceneProperties(mn::SurfacePlacement::Absolute));
    // add the overlay to the mapview
    m_sceneView->graphicsOverlays()->append(LOS);
    // create line geometry
    mn::PolygonBuilder polylineBuilder(m_sceneView->spatialReference());
    // build the polyline
    polylineBuilder.addPoint(deviceLocation.x,deviceLocation.y,deviceLocation.z);
    polylineBuilder.addPoint(satLocation.x,satLocation.y,satLocation.z);
    // tells renderer what type of symbol to use.
    mn::SimpleLineSymbol* sls = new mn::SimpleLineSymbol(mn::SimpleLineSymbolStyle::Solid, lineColor, 5, thisF);
    // creates graphic from the polylineBuilder
    mn::Graphic* lineGraphic = new mn::Graphic(polylineBuilder.toGeometry(), thisF);
    // set the renderer of the graphic overlay to be the line symbol
    lineGraphicOverlay->setRenderer(UniqueValueRenderer);
    // add the graphic to the overlay
    lineGraphicOverlay->graphics()->append(lineGraphic);
}
Any help would be greatly appreciated.
0 Kudos
7 Replies
NorbertThoden
Occasional Contributor III

Hi Michael!
I don´t have experience with UniqueValueRenderer - sorry.

But did you have a look here: https://developers.arcgis.com/qt/latest/cpp/sample-code/sample-qt-uniquevaluerenderer.htm

Any maybe you should try out the examples of the gitHub...

For your problem the should be helpful...

But maybe you have already done this...

good luck 🙂

0 Kudos
MichaelGreene2
New Contributor II

Thanks! i'm still plugging away at it.  Using different types of renderers is new to me.

0 Kudos
LukeSmallwood
Esri Contributor

Hi Michael,

This line looks wrong to me:

// add the overlay to the mapview
m_sceneView->graphicsOverlays()->append(LOS);

In your code I think that LOS is your UniqueValueRenderer* rather than a graphics overlay.
MichaelGreene2
New Contributor II

Thanks for this! I'm still having trouble understanding what I need to do to use the UniqueValueRenderer properly.

My code now looks like this:

    
void addLineOfSightToMapFunc(Point deviceLocation, Point satLocation,Esri::ArcGISRuntime::SceneGraphicsView* m_sceneView, QColor lineColor,QString uniqueString,mn::GraphicsOverlay* lineGraphicOverlay, MapRay *thisF )
{

    lineGraphicOverlay->sceneProperties().setSurfacePlacement(mn::SurfacePlacement::Absolute);
    lineGraphicOverlay->setSceneProperties(mn::LayerSceneProperties(mn::SurfacePlacement::Absolute));
    m_sceneView->graphicsOverlays()->append(lineGraphicOverlay);
    // create line geometry
    mn::PolygonBuilder polylineBuilder(m_sceneView->spatialReference());
    // build the polyline
    polylineBuilder.addPoint(deviceLocation.x,deviceLocation.y,deviceLocation.z);
    polylineBuilder.addPoint(satLocation.x,satLocation.y,satLocation.z);
    // tells renderer what type of symbol to use.
    mn::SimpleLineSymbol* SLS = new mn::SimpleLineSymbol(mn::SimpleLineSymbolStyle::Solid, lineColor, 5, thisF);
    // creates graphic from the polylineBuilder
    mn::Graphic* lineGraphic = new mn::Graphic(polylineBuilder.toGeometry(), thisF);
    // set the renderer of the graphic overlay to be the line symbol
    lineGraphicOverlay->setRenderer(new mn:: UniqueValueRenderer(SLS));
    // add the graphic to the overlay
    lineGraphicOverlay->graphics()->append(lineGraphic);
}

I've been reading about how to use the UniqueValueRenderer and am having trouble understanding the "uniquevalue" aspect of the implementation. I'm trying to add Polylines that extend from the deviceLocation to the satLocation.  
I'd like the lines to be different colors based on the variable lineColor within the code.
0 Kudos
LucasDanzinger
Esri Frequent Contributor

We have an example in the API ref - UniqueValueRenderer Class | ArcGIS for Developers 

Basically, the unique value renderer will display a different symbol depending on an attribute value. So the only difference between your code and the example in the API ref is that you are using Graphics instead of Features.The trick is to use a constructor that allows you to set attributes in the Graphic - Graphic Class | ArcGIS for Developers 

Give each an attribute that is something like "lineColor" : "red", and then the field your unique value renderer is based on would be "lineColor". Then set up a UniqueValue like in the code sample, and specify a symbol for each unique value of lineColor that you will have specified.

MichaelGreene2
New Contributor II

I was able to figure out my problem thanks to Lucas Danzinger's advice on graphics.

A unique value renderer was not needed for our purposes (a simple renderer was used). Adding an attribute to the graphic with QVariantMap attr; was able to solve the issue.

Thanks for the help Lucas Danzinger &norbert.thoden 

0 Kudos
NorbertThoden
Occasional Contributor III

Hi Michael!

Your were able to go one step forward - fine.

Take care

0 Kudos