Here is the code snippet which shall work for you.
BinaryFormatter _formatter = new BinaryFormatter();
MemoryStream serializedLayers = new MemoryStream();
FeatureLayer layer = (FeatureLayer)GetMapControl().Map.Layers[0];
layer.Enabled = true;
_formatter.Serialize(serializedLayers, GetMapControl().Map.Layers[0]);
layer.Enabled = false;
serializedLayers.Position = 0;
FeatureLayer layer2 = (FeatureLayer)_formatter.Deserialize(serializedLayers);
GetMapControl().Map.Layers.Remove(GetMapControl().Map.Layers[0]);
GetMapControl().Map.Layers.Add(layer2);
I am able to get back the visibility true. Since it was true when serialized.
------------------------------
Dinesh Ahuja
PITNEY BOWES SOFTWARE
NOIDA
------------------------------
Original Message:
Sent: 04-14-2020 09:47
From: Alejandro Hernandez
Subject: How to serialize a Layer
Hi,
Anoyone can help me with this problem please?
Thank you!
------------------------------
Alejandro Hernandez
Information Technology & Services
ITS SA (GBD)
Buenos Aires
Original Message:
Sent: 03-29-2020 19:03
From: Alejandro Hernandez
Subject: How to serialize a Layer
Hi,
I don't know how to serialize the layer I need. (MapxTeme 8.1 + VB.Net)
I have this code
Dim oCatalog As Catalog = Session.Current.Catalog
Dim oMITable As Table = oCatalog.GetTable("Localidades")
Dim oLayer As New FeatureLayer(oMITable)
Dim mySerializer As XmlSerializer = New XmlSerializer(GetType(FeatureLayer))
Dim myWriter As StreamWriter = New StreamWriter("myFileName.xml")
mySerializer.Serialize(myWriter, oLayer)
myWriter.Close()
But the line in bold, give me an error. Which is the correct class?
Thank you!
------------------------------
Alejandro Hernandez
Information Technology & Services
ITS SA (GBD)
Buenos Aires
------------------------------