Options > Maps > Views Maps Reader Framework > Renderers > Making a Renderer Persistent
Making a Renderer Persistent
There are certain situations where you might want to save a renderer. When you work in load-on-demand mode, for example, only the parameters necessary for loading the graphic objects in the layer are saved, not the objects themselves. Load-on-demand is described in Using Load-On-Demand.
If the graphic objects are created using a specific renderer, you must save that renderer to render the objects in the same way the next time they are loaded. The class IlvSDOLayer, for example, lets you specify a renderer that will be saved with the layer. See IlvSDOLayer::setFeatureRenderer in the Reference Manual.
The ColorLineRenderer presented in the previous section derives from the IlvFeatureRenderer abstract class. This class specifies three methods related to persistence: the isPersistent method specifies whether the renderer is persistent, the write method that writes the renderer in an IlvOutputFile, and the save method that saves the class and the renderer. To implement a persistent renderer, you then have to overwrite the isPersistent method and the write method.
IlvBoolean
ColorLineRenderer::isPersistent()
{
return IlvTrue;
}
void
ColorLineRenderer::write(IlvOutputFile& output) const
{
IlvWriteString(output, _attributeName);
if(_colorModel->isPersistent()) {
output.getStream() << 1 << IlvSpc();
_colorModel->write(output);
} else {
output.getStream() << 1 << IlvSpc();
IlvWarning("colormodel not saved");
}
}
You can, however, build the renderer using any other color model, which might not be persistent. In this case, the color model is not saved and the write method generates a warning.
If the color model is not saved with the renderer, a default color model is created when the renderer is read.
ColorLineRenderer::ColorLineRenderer(IlvInputFile& stream)
:IlvFeatureRenderer(stream.getDisplay(), IlvTrue)
{
char* s = IlvReadString(stream);
if(s)
_attributeName = strcpy(new char[strlen(s)+1], s);
IlvInt hasColorModel;
stream.getStream() >> hasColorModel;
if(hasColorModel) {
_colorModel = (IlvMapColorModel*)
IlvMapClassInfo::ReadObject(IlvMapColorModel::ClassInfo(),
stream,
0);
} else {
_colorModel = IlvIntervalColorModel::MakeElevationColorModel();
}
}
Published date: 05/24/2022
Last modified date: 02/24/2022