Cache gets mixed up

Topics: General
Apr 5, 2013 at 8:28 AM
Edited Apr 5, 2013 at 8:30 AM
Hi,

Got the following problem. Cache gets mixed up when switching between providers.
I use a custom created provider and open street map in this example.

What steps (clean up cache ?) do I have to do before displaying the next map.

mGmapControl.ScaleMode = ScaleModes.Integer;

Caching mode is set to ServerandCache.

Memory cache:
mGmapControl.Manager.UseMemoryCache = true;
mGmapControl.LevelsKeepInMemmory = 6;

Secondairy cache:
I have made de DbId in Gmap public so the database cache does get mixed up when using the same provider for multiple maps.
mGmapControl.MapProvider.DbId = mGeographicDeviceMap.Id;

Primairy cache:
Set mGmapControl.CacheLocation = Path.GetDirectoryName(Application.ExecutablePath) + "\Gmap.Cache\" + mGeographicDeviceMap.Id + "\"; so each map has it's own SQLite db.

Use mGmapControl.ReloadMap(); when switching.

Image
Coordinator
Apr 5, 2013 at 8:40 AM
each map provider should have constant DbId, and it is by default

just make new provider with unique GUID, and everything will work just fine
Apr 5, 2013 at 9:18 AM
Edited Apr 5, 2013 at 9:19 AM
Thank you for the quick response!

It is not clear to me why the tiles get mixed up. Please explain.

I need multiple instances of the same provider.
Can I use something like this to fix the problem.
In the GmapProvider.cs code:

DbId in my case is public and is set from mGmapControl.MapProvider.DbId = ...
  public override Guid Id
  {
     get
     {
         return new Guid(string.Format("D7287DA0-A7FF-405F-8166-{0}", ("000000000000" + DbId.ToString()).Substring(DbId.ToString().Length - 1, 12)));
     }
  }


Coordinator
Apr 5, 2013 at 9:35 AM
you don't need multiply instances of the same provider
Apr 5, 2013 at 10:16 AM
You're right :)

The situation is I have to switch between geographic maps like open street map and maps created from drawings.
I use Maperative to generate the tiles. Works great :)
So I created a CustomMapProvider for my own maps.

This class has a TileServerUrl property to switch between maps of this CustomMapProvider type.
Set the TileServerUrl property to http://localhost/MyMaps/MapOne/ http://localhost/MyMaps/MapTwo/ etc..
Had to add public string TileServerUrl = string.Empty; to the GmapProvider class.
I use the Guid override code below now not in the GmapProvider class but in my own CustomMapProvider class.
Seems to solve the mix up. I'm still testing.
  public override Guid Id
  {
      get
      {
          return new Guid(string.Format("D7287DA0-A7FF-405F-8166-{0}", ("000000000000" + DbId.ToString()).Substring(DbId.ToString().Length - 1, 12)));  // id;
      }
  }
Custom tile image url format:
  string MakeTileImageUrl(GPoint pos, int zoom, string language)
  {
      string tileUrl = string.Format(UrlFormat, TileServerUrl, zoom, pos.X, pos.Y, baseFormatExt);
      return tileUrl; 
  }

  static readonly string baseFormatExt = ".png";
  static readonly string UrlFormat = "http://{0}/{1}/{2}/{3}{4}";
Coordinator
Apr 5, 2013 at 11:12 AM
DbId is generated using Guid id, so use some other parameter, like hash of name or something...

..and you don't need multiply instances of the same provider, but i mean for one map, for different maps you need multiply instances of usually different providers, but in your case it can be different instances of the same provider with different parameters, therefore guids will be different and DbId will be automaticaly different too

simple logic:
CustomProvider : GMapProvider
{
    CustomProvider(string server, string myMapName)
    {
       this.myMapName = myMapName;
    }

    public override Guid Id
    {
      get
      {
          return new Guid(string.Format("D7287DA0-A7FF-405F-8166-{0}", Hash(myMapName));
      }
}

var p1 = new CustomProvider("localhost", "MapOne");
var p2 = new CustomProvider("localhost", "MapTwo");
var p3 = new CustomProvider("localhost", "MapThree");

lisbox.items = new [] {p1, p2, p3}

OnListBoxItemchanged
{
  mGmapControl.MapProvider = currentitem;
}
Apr 5, 2013 at 11:49 AM
Thanx! Got it :)

Gmap is a wonderfull piece of work!
Aug 9, 2013 at 11:42 AM
Hello,

I'm busy with an identical problem but the proposed solution seems not working for me.
CustomProvider : GMapProvider
{
    CustomProvider(string server, string myMapName)
    {
       this.myMapName = myMapName;
    }

    public override Guid Id
    {
      get
      {
          return new Guid(string.Format("D7287DA0-A7FF-405F-8166-{0}", Hash(myMapName));
      }
}

var p1 = new CustomProvider("localhost", "MapOne");
The problem is that the constructor of GmapProvider class (in which dbid is generated) is called before the constructor of CustomProvider class. Therefore myMapName is not yet assigned to the right value when the dbid is generated. Is it right ? If yes, any workaround ?
Coordinator
Aug 9, 2013 at 2:54 PM
assign before
Aug 10, 2013 at 7:21 AM
Sorry, I am not sure to understand. What do you want to say by assign before ?
It could be really helpfull for me if someone can update the sample accordingly.
Thank you.