Select to view content in your preferred language

UniqueValueRenderer does not work on DynamicEntityLayer's track line renderer

395
4
05-12-2025 01:15 AM
Labels (2)
FatmaAkdemir
Frequent Contributor

 

 

auto* uniqueValue1 = new UniqueValue("Cat 11", "Cat 11", QVariantList() << "Cat 11", new SimpleMarkerSymbol(SimpleMarkerSymbolStyle::X, QColor(Qt::darkYellow), 12.0, this), this);
        auto* uniqueValue2 = new UniqueValue("Cat 20", "Cat 20", QVariantList() << "Cat 20", new SimpleMarkerSymbol(SimpleMarkerSymbolStyle::X, QColor(Qt::darkGreen), 12.0, this), this);
        auto* uniqueValue3 = new UniqueValue("Cat 21", "Cat 21", QVariantList() << "Cat 21", new SimpleMarkerSymbol(SimpleMarkerSymbolStyle::X, QColor(Qt::darkBlue), 12.0, this), this);
        auto* uniqueValue4 = new UniqueValue("Cat 48", "Cat 48", QVariantList() << "Cat 48", new SimpleMarkerSymbol(SimpleMarkerSymbolStyle::X, QColor(Qt::darkMagenta), 12.0, this), this);
        auto* uniqueValue5 = new UniqueValue("Cat 62", "Cat 62", QVariantList() << "Cat 62", new SimpleMarkerSymbol(SimpleMarkerSymbolStyle::X, QColor(Qt::darkCyan), 12.0, this), this);

        auto* history1 = new UniqueValue("Cat 11", "Cat 11", QVariantList() << "Cat 11", new SimpleMarkerSymbol(SimpleMarkerSymbolStyle::Circle, QColor(Qt::darkYellow), 4.0, this), this);
        auto* history2 = new UniqueValue("Cat 20", "Cat 20", QVariantList() << "Cat 20", new SimpleMarkerSymbol(SimpleMarkerSymbolStyle::Circle, QColor(Qt::darkGreen), 4.0, this), this);
        auto* history3 = new UniqueValue("Cat 21", "Cat 21", QVariantList() << "Cat 21", new SimpleMarkerSymbol(SimpleMarkerSymbolStyle::Circle, QColor(Qt::darkBlue), 4.0, this), this);
        auto* history4 = new UniqueValue("Cat 48", "Cat 48", QVariantList() << "Cat 48", new SimpleMarkerSymbol(SimpleMarkerSymbolStyle::Circle, QColor(Qt::darkMagenta), 4.0, this), this);
        auto* history5 = new UniqueValue("Cat 62", "Cat 62", QVariantList() << "Cat 62", new SimpleMarkerSymbol(SimpleMarkerSymbolStyle::Circle, QColor(Qt::darkCyan), 4.0, this), this);

        auto* line1 = new UniqueValue("Cat 11", "Cat 11", QVariantList() << "Cat 11", new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor(Qt::darkYellow), 2.0, this), this);
        auto* line2 = new UniqueValue("Cat 20", "Cat 20", QVariantList() << "Cat 20", new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor(Qt::darkGreen), 2.0, this), this);
        auto* line3 = new UniqueValue("Cat 21", "Cat 21", QVariantList() << "Cat 21", new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor(Qt::darkBlue), 2.0, this), this);
        auto* line4 = new UniqueValue("Cat 48", "Cat 48", QVariantList() << "Cat 48", new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor(Qt::darkMagenta), 2.0, this), this);
        auto* line5 = new UniqueValue("Cat 62", "Cat 62", QVariantList() << "Cat 62", new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor(Qt::darkCyan), 2.0, this), this);

        // Add the unique values to the renderer
        auto* uniqueRenderer = new UniqueValueRenderer("", new SimpleMarkerSymbol(this), QStringList() << "source", QList<UniqueValue*>() << uniqueValue1 << uniqueValue2 << uniqueValue3 << uniqueValue4 << uniqueValue5, this);
        auto* uniqueRendererHistory = new UniqueValueRenderer("", new SimpleMarkerSymbol(this), QStringList() << "source", QList<UniqueValue*>() << history1 << history2 << history3 << history4 << history5, this);
        auto* uniqueRendererTrajectory = new UniqueValueRenderer("", new SimpleLineSymbol(this), QStringList() << "source", QList<UniqueValue*>() << line1 << line2 << line3 << line4 << line5, this);
        mpDynamicEntityLayer->setRenderer(uniqueRenderer);
        mpDynamicEntityLayer->trackDisplayProperties()->setPreviousObservationRenderer(uniqueRendererHistory);
        mpDynamicEntityLayer->trackDisplayProperties()->setTrackLineRenderer(uniqueRendererTrajectory);

At line 25 I'm trying to give different colors to track lines for different categories of tracks, but it does not work. What am I missing?

0 Kudos
4 Replies
JamesBallard1
Esri Regular Contributor

@FatmaAkdemir 

Currently only the track id field is supported on track lines with attribute renderers like unique value renderers.

Also take a look at the attribute values... Possibly the label field is where the field name should be (like "Cat 11" with a value of "Cat 11").  If the track id was say, "Category" and the value was "Cat 11", then I would expect something like 

UniqueValue("Category", "Category", QVariantList() << "Cat 11", new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor(Qt::darkYellow), 2.0, this), this);

 

to work.

 

FatmaAkdemir
Frequent Contributor

Thank you very much @JamesBallard1. In fact track ids are string values starting with 2 digits of category number. Is there a way to render track lines according to the first 2 characters of track ID attribute?

0 Kudos
JamesBallard1
Esri Regular Contributor

@FatmaAkdemir I checked with our experts in this area, and it doesn't appear possible to do what you're asking about, unfortunately.

It might be possible to use a DictionaryRenderer with a custom dictionary style to parse out the category from the field on-the-fly and return different symbols based on that, but I can't say for certain that would work, and it would be a major reworking of how your data is structured to prototype it.

0 Kudos
KerryRobinson
Esri Contributor

Hi Fatma,

There is the option to use a Unique Value Renderer but with a `valueExpression` which can parse out the first 2 characters of the track ID and use that to determine the values.   Unfortunately we do not yet support setting `valueExpression` in the API, however you can create the renderer from JSON and it will work.  (use renderer.fromJson();)

Here is a sample JSON that uses the right 4 characters of a track ID to create the unique values:

{
  "defaultSymbol": {
    "symbol": {
      "symbolLayers": [
        {
          "anchor3D": "Center",
          "capStyle": "Round",
          "color": [ 130, 130, 130, 255 ],
          "colorLocked": false,
          "enable": true,
          "height3D": 1,
          "joinStyle": "Round",
          "lineStyle3D": "Strip",
          "miterLimit": 10.0,
          "type": "CIMSolidStroke",
          "width": 3.0
        }
      ],
      "type": "CIMLineSymbol"
    },
    "type": "CIMSymbolReference"
  },
  "fieldDelimiter": ",",
  "type": "uniqueValue",
  "valueExpression": "RIGHT($feature.vehiclename,4)",
  "valueExpressionTitle": "Custom",
  "uniqueValueInfos": [
    {
      "label": "2043",
      "symbol": {
        "symbol": {
          "symbolLayers": [
            {
              "anchor3D": "Center",
              "capStyle": "Round",
              "color": [ 46, 194, 194, 255 ],
              "colorLocked": false,
              "enable": true,
              "height3D": 1,
              "joinStyle": "Round",
              "lineStyle3D": "Strip",
              "miterLimit": 10.0,
              "type": "CIMSolidStroke",
              "width": 3.0
            }
          ],
          "type": "CIMLineSymbol"
        },
        "type": "CIMSymbolReference"
      },
      "value": "2043"
    },
    {
      "label": "2421",
      "symbol": {
        "symbol": {
          "symbolLayers": [
            {
              "anchor3D": "Center",
              "capStyle": "Round",
              "color": [ 82, 43, 194, 255 ],
              "colorLocked": false,
              "enable": true,
              "height3D": 1,
              "joinStyle": "Round",
              "lineStyle3D": "Strip",
              "miterLimit": 10.0,
              "type": "CIMSolidStroke",
              "width": 3.0
            }
          ],
          "type": "CIMLineSymbol"
        },
        "type": "CIMSymbolReference"
      },
      "value": "2421"
    },
    {
      "label": "3018",
      "symbol": {
        "symbol": {
          "symbolLayers": [
            {
              "anchor3D": "Center",
              "capStyle": "Round",
              "color": [ 198, 48, 60, 255 ],
              "colorLocked": false,
              "enable": true,
              "height3D": 1,
              "joinStyle": "Round",
              "lineStyle3D": "Strip",
              "miterLimit": 10.0,
              "type": "CIMSolidStroke",
              "width": 3.0
            }
          ],
          "type": "CIMLineSymbol"
        },
        "type": "CIMSymbolReference"
      },
      "value": "3018"
    },
    {
      "label": "4008",
      "symbol": {
        "symbol": {
          "symbolLayers": [
            {
              "anchor3D": "Center",
              "capStyle": "Round",
              "color": [ 186, 201, 62, 255 ],
              "colorLocked": false,
              "enable": true,
              "height3D": 1,
              "joinStyle": "Round",
              "lineStyle3D": "Strip",
              "miterLimit": 10.0,
              "type": "CIMSolidStroke",
              "width": 3.0
            }
          ],
          "type": "CIMLineSymbol"
        },
        "type": "CIMSymbolReference"
      },
      "value": "4008"
    }
  ]
}

 

Hope that helps!

 

0 Kudos