Serialization

Jul 3, 2010 at 10:12 PM

Following on from where I've asked before about custom layers.

I'm planning on allowing a user to construct multiple overlays that all overlap each other. I then want them to be able to close down the app, and reload it, opening up the existing overlays. Fairly easy to do with serialization I believe but it seems the classes I'd expect to do this sort of thing (e.g. GMapOverlay) aren't currently marked as serializable? Is there a reason for this?

Jul 3, 2010 at 10:22 PM

you can create your own:

 [serialize...] class MyLayer : GMapOverlay { ... }

Jul 3, 2010 at 10:37 PM

I believe though that all the base classes need to be serializable too? So actually it would need to be like

[Serializable]

class MyLayer : GMapOverlay {}

[Serializable]

class GMapOverlay{}

Jul 3, 2010 at 10:49 PM

does it work?

Jul 5, 2010 at 12:49 PM
Edited Jul 5, 2010 at 12:51 PM
radioman, I've not had a chance to use GMap.Net to do this. But if you try the following example you'll see it fail with the sort of error I'd expected "Type 'ConsoleApplication1.A' in Assembly 'ConsoleApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.". This means that overlays and markers need to be serializable for layer saving/loading.

using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
B b = new B() { Name = "Test", AnotherName = "AnotherTest" };

MemoryStream ms = new MemoryStream();
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(ms, b);
}
}

public class A
{
public String Name { get; set; }
}

[Serializable]
public class B : A
{
public String AnotherName { get; set; }
}
}

Jul 5, 2010 at 1:07 PM

it's open source, you can make changes anytime, anywhere ;}

Jul 6, 2010 at 12:13 PM
Do I need to request to join the project to make changes?
Jul 6, 2010 at 12:41 PM
Hmm tried connecting to " https://hg01.codeplex.com/greatmaps" and tried creating a fork and connecting to it "https://hg01.codeplex.com/forks/ianwright83/serializableclasses" but I get an error each time :( The OPTIONS response did not include the requested activity-collection-set. this often means that the URL is not WebDAV-enabled.
Jul 6, 2010 at 1:53 PM

i see your fork, but there is no changes in it, please commit and push it

Jul 6, 2010 at 5:30 PM
radioman, unfortunately I can't make any changes... I can't actually get the source when I try, I get an error. "The OPTIONS response did not include the requested activity-collection-set. this often means that the URL is not WebDAV-enabled."
Jul 6, 2010 at 5:42 PM

works just perfect for me