Other Software and Data

Expand all | Collapse all

How to serialize a Layer

  • 1.  How to serialize a Layer

    Posted 03-29-2020 19:03
    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
    ------------------------------


  • 2.  RE: How to serialize a Layer

    Posted 04-14-2020 09:48
    Hi,

    Anoyone can help me with this problem please?

    Thank you!

    ------------------------------
    Alejandro Hernandez
    Information Technology & Services
    ITS SA (GBD)
    Buenos Aires
    ------------------------------



  • 3.  RE: How to serialize a Layer

    Employee
    Posted 04-16-2020 09:17

    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
    ------------------------------