Hi there,
I digged a bit deeper into the behaviour of map graphics and their CIM representation in a MapDocument and LayerDocument and found probably some bugs or atleast inconsistencies when working with them.
The map graphic binary reference is lost when parsing a .mapx file back to a CIMMapDocument instance.
// map needs to have a graphic layer with graphics ofc
map.SaveAsFile("C:\\temp\\temp.mapx", true);
var json = File.ReadAllText("C:\\temp\\temp.mapx");
var mapDoc = CIMMapDocument.FromJson(json);
// BUG :: BinaryReference.Object is null. Should be instance of CIMElementStorage
var binaryRefs = mapDoc.BinaryReferences.Where(br => br.Object is CIMElementStorage).ToList(); // returns none
Same behaviour can be observed when doing this with a .lyrx file.
var layerDoc = new LayerDocument(graphicLayer);
layerDoc.Save("C:\\temp\\temp.lyrx");
// The .lyrx file contains the CIMElementStorage object
var json = File.ReadAllText("C:\\temp\\temp.lyrx");
// BUG: BinaryReference.Object (CIMElementStorage) is null, although it does exist in the .lyrx file json
var cimLayerDoc2 = CIMLayerDocument.FromJson(json);
This two are probably just some parsing errors but the last one just does not make any sense to me. If I get the CIMLayerDocument in memory the CIMElementStorage object exists, but somehow the coordinates of the different graphic geometries are manipulated/odd in comparison when I do a proper save to .lyrx file.
var layerDoc = new LayerDocument(graphicLayer);
// BUG: The resulting geometries within the CIMElementStorage have completely different geometries, see image below
// geometries are broken
var cimLayerDoc = layerDoc.GetCIMLayerDocument();
// geometries are ok
layerDoc.Save("C:\\temp\\temp.lyrx");
Left the geometry saved as .lyrx and right the in memory create CIMLayoutDocument. The source is exactly the same.
Any explanations or hints on this would be appreciated!
Weird. I wonder if the coordinate system used between both formats is different?
The spatial reference is actually the exact same. Its the same source map and the same source geometry.