The default Military Symbology IFeaturePainter implementations only work for feature models with the Military Symbology DataModel.

If the features in your model are not configured according to this data type, you can still visualize your data as military symbols by implementing your own painter. This is useful if you want to add your own symbols, or if your military symbols do not entirely comply with the supported military symbology standards.

The IFeaturePainter implementation needs to:

The example implementation below visualizes every feature as a fixed MIL-STD 2525b icon symbol.

class MyMilitarySymbolPainter : public IFeaturePainter {
public:
  void configureMetadata(FeaturePainterMetadata& metadata) const override {
    // If the feature's geometry changes, the symbol needs to be painted on a different location.
    metadata.painterDependsOnFeature(true);
  }

  void paint(const Feature& feature, const FeaturePainterContext& /*context*/, FeatureCanvas& canvas) const override {
    // Create a geometry denoting the symbol's location.
    // For an icon symbol, this needs to be a point, so we use the center point of the feature geometry's bounds.
    auto featureGeometry = feature.findGeometry();
    if (!featureGeometry) {
      std::cerr << "Ignoring feature '" << feature.getId() << "'. It has no geometry." << std::endl;
      return;
    }
    auto center = featureGeometry.value()->getBounds().getCenter();
    auto symbolGeometry = GeometryFactory::createPoint((*featureGeometry)->getCoordinateReference(), center.x, center.y, 0);

    // Create the military symbol to visualize. You can customize the symbol based on the feature.
    // In this example, we simply set the feature ID as value for the symbol text modifier "Unique Designation".
    auto symbol = MilitarySymbol::create(MilitarySymbology::Standard::MilStd2525d, "10030100001101000000");
    symbol->putValue(MilitarySymbol::Modifier::UniqueDesignation, std::to_string(feature.getId()));

    // Use a MilitarySymbologyCanvas to submit a draw command for the military symbol.
    MilitarySymbologyCanvas(canvas).drawMilitarySymbol().symbol(symbol).geometry(symbolGeometry).submit();
  }
};