Dynamic providers: Clear Cache and WMS Provider

Topics: Feature Requests
Nov 5, 2011 at 10:54 PM

I have implemented a WMS Provider where users can specify the service url, layers, srs, etc. When they change the WMS definition, I need to clear all caches for tiles belonging to the previous definition.

The methods I need are:
- GMaps.Instance.ImageCacheLocal.DeleteTiles(int dbid)
- GMaps.Instance.ImageCacheSecond.DeleteTiles(int dbid)
- GMaps.Instance.MemoryCache.DeleteTiles(int dbid)
When the tiles have been deleted I would call: MainMap.ReloadMap()

Regarding the constructor for  GMapProvider:
- Can you add a second one with Guid as a parameter?
I'am storing the guid in a database and would like to create the provider on request.

Thanks for an excellent product :-)  

Nov 5, 2011 at 11:09 PM

dynamic provider mess up the cache, you have to deal with that yourself if you want such functionality..

Nov 6, 2011 at 12:35 PM

What kind of mess whould that be? I'm not changing the DbId or Guid for the provider.

Nov 6, 2011 at 12:53 PM

thats the problem ;}

Nov 6, 2011 at 3:49 PM

Then, what is the problem? Can you give a short explanation?

Nov 7, 2011 at 7:30 AM

you'll get cache from mixed providers

Nov 7, 2011 at 10:30 AM

That's why I asked for the DeleteTiles methods :-|

Nov 7, 2011 at 12:53 PM
Edited Nov 7, 2011 at 1:03 PM

done ;}

MainMap.Manager.PrimaryCache.DeleteOlderThan(DateTime.Now, GMapProviders.BingMap.DbId); 

Nov 27, 2011 at 8:37 AM

Hi orvindo,

 

Could you please release your provider as a fork ?

I'm interested to get a WMS / WFS provider. I tough to extend to provider ID to manage many tiles for a unique location with the same provider.

I can do that.

Regards.

Feb 19, 2012 at 11:49 PM

Hi Guz

Sorry for my very late answer, but here is my WMS provider implementation. As GMap needs static providers, I have created a WMSProviderBase class and derives the static providers WMSProvider1, WMSProvider2, etc from that.

I store the parameters in a database table and initializes the providers on demand. The datatable is defined as follows: CREATE TABLE MapProvider (DbID int NOT NULL, Guid varchar(25) NOT NULL, ProviderName nvarchar(30) NOT NULL, ServiceUrl varchar(255) NOT NULL, Layer varchar(50) NOT NULL, Zoom varchar(10) NULL, Bounds varchar(50) NULL, TileFormat varchar(10) NULL, Wkt varchar(1024) NULL, BaseDbID int NULL).
    
The only parameters that is necessary to the Init() method are url and layer.

Regards,
orvindo

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using GMap.NET;
using GMap.NET.Projections;
using GMap.NET.MapProviders;
using ProjNet.Converters;
using ProjNet.CoordinateSystems;
using ProjNet.CoordinateSystems.Transformations;

[CLSCompliantAttribute(false)]
public class WMSProviderBase : GMapProvider
{
    bool initialized;
    string name = "Undefined WMS Provider";
    string url;
    string layer;
    string srs = "EPSG:4326"; // = WGS84
    string tileFormat = "png";
    ICoordinateTransformation coordTrans;
    List<GMapProvider> overlayList;

    protected WMSProviderBase()
    {
    }

    public void Init(string name, string url, string layer, string zoom, string bounds, string wkt, string tileformat, List<GMapProvider> overlays)
    {
        this.name = name;
        this.url = url;
        this.layer = layer;
        if (string.IsNullOrEmpty(tileformat) == false) this.tileFormat = tileformat;

        // Set zoom levels
        int minzoom, maxzoom;
        bool zoomOk = ParseZoom(zoom, out minzoom, out maxzoom);
        if (zoomOk == true && minzoom >= 0) MinZoom = minzoom;
        if (zoomOk == true && maxzoom > 0) MaxZoom = maxzoom;

        // Set area (bounds)
        float latnorth, longwest, latsouth, longeast;
        bool boundsOk = ParseBounds(bounds, out latnorth, out longwest, out latsouth, out longeast);
        if (boundsOk == true) Area = new RectLatLng(latnorth, longwest, longeast - longwest, latnorth - latsouth);

        // Set wkt + srs
        if (string.IsNullOrEmpty(wkt) == false)
        {
            CoordinateSystemFactory csFactory = new CoordinateSystemFactory();
            ICoordinateSystem coordsystem = csFactory.CreateFromWkt(wkt);
            this.srs = coordsystem.Authority + ":" + coordsystem.AuthorityCode.ToString(NumberFormatInfo.InvariantInfo);

            CoordinateTransformationFactory transFactory = new CoordinateTransformationFactory();
            this.coordTrans = transFactory.CreateFromCoordinateSystems(GeographicCoordinateSystem.WGS84, coordsystem);
        }

        // Overlays
        this.overlayList = new List<GMapProvider>(1);
        if (overlays != null) this.overlayList.AddRange(overlays);
        this.overlayList.Add(this);

        this.initialized = true;
    }

    public static bool ParseZoom(string zoom, out int min, out int max)
    {
        // Format: min[empty]|max[empty] 
        min = -1;
        max = -1;
        if (string.IsNullOrEmpty(zoom) == true) return true;

        bool success = false;
        string[] p = zoom.Split('|');
        if (p.Length == 2)
        {
            if (p[0].Length > 0) int.TryParse(p[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out min);
            if (p[1].Length > 0) int.TryParse(p[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out max);
            if (min >= 0 || max >= 0) success = true;
        }
        return success;
    }

    public static bool ParseBounds(string bounds, out float latnorth, out float longwest, out float latsouth, out float longeast)
    {
        // Format: LatNorth;LongWest|LatSouth;LongEast 
        latnorth = 0f;
        longwest = 0f;
        latsouth = 0f;
        longeast = 0f;
        if (string.IsNullOrEmpty(bounds) == true) return true;

        bool success = false;
        string[] p = bounds.Replace(',', '.').Split('|');
        if (p.Length == 2)
        {
            string[] p0 = p[0].Split(';');
            string[] p1 = p[1].Split(';');
            if (p0.Length == 2 && p1.Length == 2)
            {
                bool parseOk = float.TryParse(p0[0], NumberStyles.Float, CultureInfo.InvariantCulture, out latnorth);
                if (parseOk == true) parseOk = float.TryParse(p0[1], NumberStyles.Float, CultureInfo.InvariantCulture, out longwest);
                if (parseOk == true) parseOk = float.TryParse(p1[0], NumberStyles.Float, CultureInfo.InvariantCulture, out latsouth);
                if (parseOk == true) parseOk = float.TryParse(p1[1], NumberStyles.Float, CultureInfo.InvariantCulture, out longeast);
                if (parseOk == true)
                {
                    if (latnorth > latsouth && longeast > longwest) success = true;
                }
            }
        }
        return success;
    }

    #region GMapProvider Members

    public override Guid Id
    {
        get { return Guid.Empty; }
    }

    public override string Name
    {
        get { return this.name; }
    }

    public override GMapProvider[] Overlays
    {
        get { return this.overlayList.ToArray(); }
    }

    public override PureProjection Projection
    {
        get { return MercatorProjection.Instance; }
    }

    public override PureImage GetTileImage(GPoint pos, int zoom)
    {
        if (this.initialized == false) return null;

        string tileUrl = MakeTileImageUrl(pos, zoom, LanguageStr);
        return GetTileImageUsingHttp(tileUrl);
    }

    #endregion

    string MakeTileImageUrl(GPoint pos, int zoom, string language)
    {
        if (this.initialized == false) return string.Empty;

        GPoint px1 = Projection.FromTileXYToPixel(pos);
        GPoint px2 = px1;

        px1.Offset(0, Projection.TileSize.Height);
        PointLatLng p1 = Projection.FromPixelToLatLng(px1, zoom);

        px2.Offset(Projection.TileSize.Width, 0);
        PointLatLng p2 = Projection.FromPixelToLatLng(px2, zoom);

        if (this.coordTrans != null)
        {
            double[] convp1 = this.coordTrans.MathTransform.Transform(new double[] { p1.Lat, p1.Lng });
            p1.Lat = Math.Round(convp1[0], 6);
            p1.Lng = Math.Round(convp1[1], 6);
            double[] convp2 = this.coordTrans.MathTransform.Transform(new double[] { p2.Lat, p2.Lng });
            p2.Lat = Math.Round(convp2[0], 6);
            p2.Lng = Math.Round(convp2[1], 6);
        }

        string ret = string.Format(CultureInfo.InvariantCulture, UrlFormat, this.url, this.layer,
            p1.Lng.ToString(NumberFormatInfo.InvariantInfo), p1.Lat.ToString(NumberFormatInfo.InvariantInfo),
            p2.Lng.ToString(NumberFormatInfo.InvariantInfo), p2.Lat.ToString(NumberFormatInfo.InvariantInfo),
            Projection.TileSize.Width.ToString(NumberFormatInfo.InvariantInfo), Projection.TileSize.Height.ToString(NumberFormatInfo.InvariantInfo),
            this.srs, "image/" + this.tileFormat);
        return ret;
    }

    const string UrlFormat = "{0}?service=WMS&version=1.1.1&request=GetMap&layers={1}&styles=&bbox={2},{3},{4},{5}&width={6}&height={7}&srs={8}&format={9}&transparent=true";
}

[CLSCompliantAttribute(false)]
public class WMSProvider1 : WMSProviderBase
{
    readonly Guid id = new Guid("CAF1D2FB-FA91-0576-A1BB-FB43128EBCFF");
    public static readonly WMSProvider1 Instance;

    WMSProvider1()
    {
    }

    static WMSProvider1()
    {
        Instance = new WMSProvider1();
    }

    public override Guid Id
    {
        get { return id; }
    }
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using GMap.NET;
using GMap.NET.Projections;
using GMap.NET.MapProviders;
using ProjNet.Converters;
using ProjNet.CoordinateSystems;
using ProjNet.CoordinateSystems.Transformations;

[CLSCompliantAttribute(false)]
public class WMSProviderBase : GMapProvider
{
    bool initialized;
    string name = "Undefined WMS Provider";
    string url;
    string layer;
    string srs = "EPSG:4326"; // = WGS84
    string tileFormat = "png";
    ICoordinateTransformation coordTrans;
    List<GMapProvider> overlayList;

    protected WMSProviderBase()
    {
    }

    public void Init(string name, string url, string layer, string zoom, string bounds, string wkt, string tileformat, List<GMapProvider> overlays)
    {
        this.name = name;
        this.url = url;
        this.layer = layer;
        if (string.IsNullOrEmpty(tileformat) == false) this.tileFormat = tileformat;

        // Set zoom levels
        int minzoom, maxzoom;
        bool zoomOk = ParseZoom(zoom, out minzoom, out maxzoom);
        if (zoomOk == true && minzoom >= 0) MinZoom = minzoom;
        if (zoomOk == true && maxzoom > 0) MaxZoom = maxzoom;

        // Set area (bounds)
        float latnorth, longwest, latsouth, longeast;
        bool boundsOk = ParseBounds(bounds, out latnorth, out longwest, out latsouth, out longeast);
        if (boundsOk == true) Area = new RectLatLng(latnorth, longwest, longeast - longwest, latnorth - latsouth);

        // Set wkt + srs
        if (string.IsNullOrEmpty(wkt) == false)
        {
            CoordinateSystemFactory csFactory = new CoordinateSystemFactory();
            ICoordinateSystem coordsystem = csFactory.CreateFromWkt(wkt);
            this.srs = coordsystem.Authority + ":" + coordsystem.AuthorityCode.ToString(NumberFormatInfo.InvariantInfo);

            CoordinateTransformationFactory transFactory = new CoordinateTransformationFactory();
            this.coordTrans = transFactory.CreateFromCoordinateSystems(GeographicCoordinateSystem.WGS84, coordsystem);
        }

        // Overlays
        this.overlayList = new List<GMapProvider>(1);
        if (overlays != null) this.overlayList.AddRange(overlays);
        this.overlayList.Add(this);

        this.initialized = true;
    }

    public static bool ParseZoom(string zoom, out int min, out int max)
    {
        // Format: min[empty]|max[empty]
        min = -1;
        max = -1;
        if (string.IsNullOrEmpty(zoom) == true) return true;

        bool success = false;
        string[] p = zoom.Split('|');
        if (p.Length == 2)
        {
            if (p[0].Length > 0) int.TryParse(p[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out min);
            if (p[1].Length > 0) int.TryParse(p[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out max);
            if (min >= 0 || max >= 0) success = true;
        }
        return success;
    }

    public static bool ParseBounds(string bounds, out float latnorth, out float longwest, out float latsouth, out float longeast)
    {
        // Format: LatNorth;LongWest|LatSouth;LongEast
        latnorth = 0f;
        longwest = 0f;
        latsouth = 0f;
        longeast = 0f;
        if (string.IsNullOrEmpty(bounds) == true) return true;

        bool success = false;
        string[] p = bounds.Replace(',', '.').Split('|');
        if (p.Length == 2)
        {
            string[] p0 = p[0].Split(';');
            string[] p1 = p[1].Split(';');
            if (p0.Length == 2 && p1.Length == 2)
            {
                bool parseOk = float.TryParse(p0[0], NumberStyles.Float, CultureInfo.InvariantCulture, out latnorth);
                if (parseOk == true) parseOk = float.TryParse(p0[1], NumberStyles.Float, CultureInfo.InvariantCulture, out longwest);
                if (parseOk == true) parseOk = float.TryParse(p1[0], NumberStyles.Float, CultureInfo.InvariantCulture, out latsouth);
                if (parseOk == true) parseOk = float.TryParse(p1[1], NumberStyles.Float, CultureInfo.InvariantCulture, out longeast);
                if (parseOk == true)
                {
                    if (latnorth > latsouth && longeast > longwest) success = true;
                }
            }
        }
        return success;
    }

    #region GMapProvider Members

    public override Guid Id
    {
        get { return Guid.Empty; }
    }

    public override string Name
    {
        get { return this.name; }
    }

    public override GMapProvider[] Overlays
    {
        get { return this.overlayList.ToArray(); }
    }

    public override PureProjection Projection
    {
        get { return MercatorProjection.Instance; }
    }

    public override PureImage GetTileImage(GPoint pos, int zoom)
    {
        if (this.initialized == false) return null;

        string tileUrl = MakeTileImageUrl(pos, zoom, LanguageStr);
        return GetTileImageUsingHttp(tileUrl);
    }

    #endregion

    string MakeTileImageUrl(GPoint pos, int zoom, string language)
    {
        if (this.initialized == false) return string.Empty;

        GPoint px1 = Projection.FromTileXYToPixel(pos);
        GPoint px2 = px1;

        px1.Offset(0, Projection.TileSize.Height);
        PointLatLng p1 = Projection.FromPixelToLatLng(px1, zoom);

        px2.Offset(Projection.TileSize.Width, 0);
        PointLatLng p2 = Projection.FromPixelToLatLng(px2, zoom);

        if (this.coordTrans != null)
        {
            double[] convp1 = this.coordTrans.MathTransform.Transform(new double[] { p1.Lat, p1.Lng });
            p1.Lat = Math.Round(convp1[0], 6);
            p1.Lng = Math.Round(convp1[1], 6);
            double[] convp2 = this.coordTrans.MathTransform.Transform(new double[] { p2.Lat, p2.Lng });
            p2.Lat = Math.Round(convp2[0], 6);
            p2.Lng = Math.Round(convp2[1], 6);
        }

        string ret = string.Format(CultureInfo.InvariantCulture, UrlFormat, this.url, this.layer,
            p1.Lng.ToString(NumberFormatInfo.InvariantInfo), p1.Lat.ToString(NumberFormatInfo.InvariantInfo),
            p2.Lng.ToString(NumberFormatInfo.InvariantInfo), p2.Lat.ToString(NumberFormatInfo.InvariantInfo),
            Projection.TileSize.Width.ToString(NumberFormatInfo.InvariantInfo), Projection.TileSize.Height.ToString(NumberFormatInfo.InvariantInfo),
            this.srs, "image/" + this.tileFormat);
        return ret;
    }

    const string UrlFormat = "{0}?service=WMS&version=1.1.1&request=GetMap&layers={1}&styles=&bbox={2},{3},{4},{5}&width={6}&height={7}&srs={8}&format={9}&transparent=true";
}

[CLSCompliantAttribute(false)]
public class WMSProvider1 : WMSProviderBase
{
    readonly Guid id = new Guid("CAF1D2FB-FA91-0576-A1BB-FB43128EBCFF");
    public static readonly WMSProvider1 Instance;

    WMSProvider1()
    {
    }

    static WMSProvider1()
    {
        Instance = new WMSProvider1();
    }

    public override Guid Id
    {
        get { return id; }
    }
}
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using GMap.NET;
using GMap.NET.Projections;
using GMap.NET.MapProviders;
using ProjNet.Converters;
using ProjNet.CoordinateSystems;
using ProjNet.CoordinateSystems.Transformations;

[CLSCompliantAttribute(false)]
public class WMSProviderBase : GMapProvider
{
    bool initialized;
    string name = "Undefined WMS Provider";
    string url;
    string layer;
    string srs = "EPSG:4326"; // = WGS84
    string tileFormat = "png";
    ICoordinateTransformation coordTrans;
    List<GMapProvider> overlayList;

    protected WMSProviderBase()
    {
    }

    public void Init(string name, string url, string layer, string zoom, string bounds, string wkt, string tileformat, List<GMapProvider> overlays)
    {
        this.name = name;
        this.url = url;
        this.layer = layer;
        if (string.IsNullOrEmpty(tileformat) == false) this.tileFormat = tileformat;

        // Set zoom levels
        int minzoom, maxzoom;
        bool zoomOk = ParseZoom(zoom, out minzoom, out maxzoom);
        if (zoomOk == true && minzoom >= 0) MinZoom = minzoom;
        if (zoomOk == true && maxzoom > 0) MaxZoom = maxzoom;

        // Set area (bounds)
        float latnorth, longwest, latsouth, longeast;
        bool boundsOk = ParseBounds(bounds, out latnorth, out longwest, out latsouth, out longeast);
        if (boundsOk == true) Area = new RectLatLng(latnorth, longwest, longeast - longwest, latnorth - latsouth);

        // Set wkt + srs
        if (string.IsNullOrEmpty(wkt) == false)
        {
            CoordinateSystemFactory csFactory = new CoordinateSystemFactory();
            ICoordinateSystem coordsystem = csFactory.CreateFromWkt(wkt);
            this.srs = coordsystem.Authority + ":" + coordsystem.AuthorityCode.ToString(NumberFormatInfo.InvariantInfo);

            CoordinateTransformationFactory transFactory = new CoordinateTransformationFactory();
            this.coordTrans = transFactory.CreateFromCoordinateSystems(GeographicCoordinateSystem.WGS84, coordsystem);
        }

        // Overlays
        this.overlayList = new List<GMapProvider>(1);
        if (overlays != null) this.overlayList.AddRange(overlays);
        this.overlayList.Add(this);

        this.initialized = true;
    }

    public static bool ParseZoom(string zoom, out int min, out int max)
    {
        // Format: min[empty]|max[empty] 
        min = -1;
        max = -1;
        if (string.IsNullOrEmpty(zoom) == true) return true;

        bool success = false;
        string[] p = zoom.Split('|');
        if (p.Length == 2)
        {
            if (p[0].Length > 0) int.TryParse(p[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out min);
            if (p[1].Length > 0) int.TryParse(p[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out max);
            if (min >= 0 || max >= 0) success = true;
        }
        return success;
    }

    public static bool ParseBounds(string bounds, out float latnorth, out float longwest, out float latsouth, out float longeast)
    {
        // Format: LatNorth;LongWest|LatSouth;LongEast 
        latnorth = 0f;
        longwest = 0f;
        latsouth = 0f;
        longeast = 0f;
        if (string.IsNullOrEmpty(bounds) == true) return true;

        bool success = false;
        string[] p = bounds.Replace(',', '.').Split('|');
        if (p.Length == 2)
        {
            string[] p0 = p[0].Split(';');
            string[] p1 = p[1].Split(';');
            if (p0.Length == 2 && p1.Length == 2)
            {
                bool parseOk = float.TryParse(p0[0], NumberStyles.Float, CultureInfo.InvariantCulture, out latnorth);
                if (parseOk == true) parseOk = float.TryParse(p0[1], NumberStyles.Float, CultureInfo.InvariantCulture, out longwest);
                if (parseOk == true) parseOk = float.TryParse(p1[0], NumberStyles.Float, CultureInfo.InvariantCulture, out latsouth);
                if (parseOk == true) parseOk = float.TryParse(p1[1], NumberStyles.Float, CultureInfo.InvariantCulture, out longeast);
                if (parseOk == true)
                {
                    if (latnorth > latsouth && longeast > longwest) success = true;
                }
            }
        }
        return success;
    }

    #region GMapProvider Members

    public override Guid Id
    {
        get { return Guid.Empty; }
    }

    public override string Name
    {
        get { return this.name; }
    }

    public override GMapProvider[] Overlays
    {
        get { return this.overlayList.ToArray(); }
    }

    public override PureProjection Projection
    {
        get { return MercatorProjection.Instance; }
    }

    public override PureImage GetTileImage(GPoint pos, int zoom)
    {
        if (this.initialized == false) return null;

        string tileUrl = MakeTileImageUrl(pos, zoom, LanguageStr);
        return GetTileImageUsingHttp(tileUrl);
    }

    #endregion

    string MakeTileImageUrl(GPoint pos, int zoom, string language)
    {
        if (this.initialized == false) return string.Empty;

        GPoint px1 = Projection.FromTileXYToPixel(pos);
        GPoint px2 = px1;

        px1.Offset(0, Projection.TileSize.Height);
        PointLatLng p1 = Projection.FromPixelToLatLng(px1, zoom);

        px2.Offset(Projection.TileSize.Width, 0);
        PointLatLng p2 = Projection.FromPixelToLatLng(px2, zoom);

        if (this.coordTrans != null)
        {
            double[] convp1 = this.coordTrans.MathTransform.Transform(new double[] { p1.Lat, p1.Lng });
            p1.Lat = Math.Round(convp1[0], 6);
            p1.Lng = Math.Round(convp1[1], 6);
            double[] convp2 = this.coordTrans.MathTransform.Transform(new double[] { p2.Lat, p2.Lng });
            p2.Lat = Math.Round(convp2[0], 6);
            p2.Lng = Math.Round(convp2[1], 6);
        }

        string ret = string.Format(CultureInfo.InvariantCulture, UrlFormat, this.url, this.layer,
            p1.Lng.ToString(NumberFormatInfo.InvariantInfo), p1.Lat.ToString(NumberFormatInfo.InvariantInfo),
            p2.Lng.ToString(NumberFormatInfo.InvariantInfo), p2.Lat.ToString(NumberFormatInfo.InvariantInfo),
            Projection.TileSize.Width.ToString(NumberFormatInfo.InvariantInfo), Projection.TileSize.Height.ToString(NumberFormatInfo.InvariantInfo),
            this.srs, "image/" + this.tileFormat);
        return ret;
    }

    const string UrlFormat = "{0}?service=WMS&version=1.1.1&request=GetMap&layers={1}&styles=&bbox={2},{3},{4},{5}&width={6}&height={7}&srs={8}&format={9}&transparent=true";
}

[CLSCompliantAttribute(false)]
public class WMSProvider1 : WMSProviderBase
{
    readonly Guid id = new Guid("CAF1D2FB-FA91-0576-A1BB-FB43128EBCFF");
    public static readonly WMSProvider1 Instance;

    WMSProvider1()
    {
    }

    static WMSProvider1()
    {
        Instance = new WMSProvider1();
    }

    public override Guid Id
    {
        get { return id; }
    }
}

Sep 21, 2012 at 9:31 PM

I would like to do something much like this, however i hope to avoid hard coded classes like WMSProvider1 etc. I may have many, really it will be up to the user how many MapProvider they wish to add.

Ideally i would like to construct classes inherited from GMapProvider, and provide a unique GUID for each in the constructor.

If i derive any class from GMapProvider, then the base class constructor checks the GUID is unique, and fails.

I'd like to be able to pass in a unique GUID when GMapProvider is intantiated.

Any ideas on how to do this?

 

Dec 17, 2012 at 9:14 AM

well have you succeeded to add the WMSProvider? Can it work? Today I also try to add a BaiDu Map Provider, but when I try to get the map, nothing return for me!

Dec 17, 2012 at 12:54 PM

1) I would be interested to know the GetCapabilities URL for access to BaiDu using WMS - does it actually support WMS?

 

2) I have hard coded classes with fixed GUID. Ideally i would like to generate a new GUID for each new map and be able to add it without compiling the code but i have not done this.

Dec 18, 2012 at 12:47 AM

well, there is a MakeTileImageUrl function for getting the tile url, and I don't know what the url format mean? Where the url format come from?

Feb 21, 2013 at 10:05 AM
Edited Feb 21, 2013 at 10:52 AM
MakeTileImageUrl is a method of the provider.

Something like this. This is a example of the MakeTileImageUrl in the custom provider i wrote to get multiple maps from a local tile server.
Works like a charme. I use maperative latest version to generate tiles from an image.
Caching is a problem, Guid is readonly. I have made the DbId public and set these for each map a load. That works for the database cache (secondairy) but not for the primairy cache and memory cache.

Would be nice to have multiple instances of the Gmap control.
  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}";
Feb 21, 2013 at 3:24 PM
guid should be readonly, but you can use whatever guid you want, you don't have to change anything, it can be hash of TileServerUrl or something...
Sep 12, 2013 at 9:48 PM
Edited Sep 12, 2013 at 10:04 PM
Hi
@orvindo could you post your working project code ?
I am stuck at using the new WMS provider
I could not figure out how you managed to send the Url and layer dynamically.

Regards
prad
Jun 10, 2015 at 1:31 PM
Hi,

I use WMSProviderBase class and work fine, but how can I have multiple WMS layer? Into WMSProviderBase class I see overlayList, but how can I use and declare it?

regards
Jun 10, 2015 at 3:06 PM
The only way I have found is to derive new classes like this (note that each class must have their own guid):
    [CLSCompliantAttribute(false)]
    public class WMSProvider1 : WMSProviderBase
    {
        readonly Guid id = new Guid("CAF1D2FB-FA91-0576-A1BB-FB43128EBCFF");
        public static readonly WMSProvider1 Instance;

        WMSProvider1()
        {
        }

        static WMSProvider1()
        {
            Instance = new WMSProvider1();
        }

        public override Guid Id
        {
            get { return id; }
        }
    }