Initialize a CIMMapDocument same way as a CIMLayerDocument

144
2
a week ago
marco_vertigis
New Contributor III

Hi there,

Today I had to extract the binary references of a specific layer and to my surpirse it worked like a charm with the following code snippet:

var binaryReferences = new List<CIMBinaryReference>();

// fetch binary references which are needed in order to properly display graphic layers
var graphicsLayers = map.GetLayersAsFlattenedList().OfType<GraphicsLayer>();
foreach (var graphicLayer in graphicsLayers)
{
	var layerDoc = new LayerDocument(graphicLayer);
	var cimLayerDoc = layerDoc.GetCIMLayerDocument();

	var elementStorageList = cimLayerDoc.BinaryReferences.Where(br => br.Object is CIMElementStorage);
	binaryReferences.AddRange(elementStorageList);
}

At another point I have to do this for a whole map, but unfortunately the only way to get the binary references of a map is to save it to a .mapx file, read and parse it as a json, which has a horrible performance if the map gets huge. Is there a way to get the CIMLayerDocument somehow in memory like I did it with the layer? There is also no class named 'MapDocument' in the public API.

map.SaveAsFile("C:\data\map.mapx");
var json = File.ReadAllText("C:\data\map.mapx");
var doc = CIMLayoutDocument.FromJson(json);

  

0 Kudos
2 Replies
CharlesMacleod
Esri Regular Contributor

is something like map.GetDefinition().ToJson() good enough?

0 Kudos
marco_vertigis
New Contributor III

@CharlesMacleod  Not quite, map.GetDefinition() only returns the CIMMap. But sometimes I need the full mapx (CIMMapDocument) definition.

0 Kudos