The previous article introduced the theoretical basis of GMAP. NET and how to integrate AMAP. AMAP has been widely known since it provided maps for IOS6.
In my experience of integrating domestic maps, it is also the most appropriate mocato projection method.
Link to the previous article:
Deep understanding of the most powerful desktop map control GMAP. NET --- principles
Gain a deep understanding of the most powerful desktop map control GMAP. NET --- SOSO Map
Deep understanding of the most powerful desktop map control GMAP. NET --- Baidu Map
Gain a deep understanding of the most powerful desktop map control GMAP. NET --- initial use
Deep understanding of the most powerful desktop map control GMAP. NET
How to Use GMAP. net amap in your program
To use the following code, we recommend that you use the code below.
this.MainMap.Position = new PointLatLng(double.Parse(ConfigurationManager.AppSettings["defaultLat"]),double.Parse(ConfigurationManager.AppSettings["defaultLng"]));this.MainMap.MapProvider.Area = new RectLatLng(30.981178, 105.351914, 2.765142, 4.120995);this.MainMap.BoundsOfMap = new RectLatLng(30.981178, 105.351914, 2.765142, 4.120995);this.MainMap.Manager.Mode = AccessMode.CacheOnly;this.MainMap.MapProvider = GMapProviders.AMapProvider;this.MainMap.DragButton = MouseButton.Left;this.MainMap.Zoom = 13;this.MainMap.MinZoom = 8;this.MainMap.MaxZoom = 24;
GMAP. net amap Effect
Normal Map
Satellite Map
How AMAP Loads
To understand how to load AMAP, we also need to understand the loading principle. We can use Chrome to open http://www.amap.com/, and use a location to access the address:
The address of Tile is as follows: http://webrd03.is.autonavi.com/appmaptile? X = 1629 & y = 849 & z = 11 & lang = zh_cn & size = 1 & scale = 1 & style = 7
The Url link parameters are analyzed as follows:
Http://webrd03.is.autonavi.com/appmaptileis fixed
& Lang = zh_cn & size = 1 & scale = 1 & style = 7 is also fixed
X = 1629 is the horizontal coordinate of the grid, and y = 849 is the vertical coordinate of the grid. The Generation Principle of the horizontal and vertical coordinates has been described in the principles section. I will not go into details here.
Z = 11 is the current scaling level.
Therefore, AMAP is relatively simple and standard.
Let's take a look at how to implement AMAP in GMAP. NET.
AMapProvider
Like the operation process of a hundred-degree map, the following process is used to add AMapProvider support.
1)Add abstract class AMapProviderBase
Because AMAP also has common maps and satellite maps, it provides an abstract class with common methods and can be reused.
Public abstract class AMapProviderBase: GMapProvider {public AMapProviderBase () {MaxZoom = null; RefererUrl = "http://www.amap.com/"; Copyright = string. format ("{0} autonavi Corporation, {0} NAVTEQ, {0} Image courtesy of NASA", DateTime. today. year);} public override PureProjection Projection {get {return MercatorProjection. instance ;}} GMapProvider [] overlays; public override GMapProvider [] Overlays {get {if (overlays = null) {overlays = new GMapProvider [] {this };} return overlays ;}}}
2).MapProvider
MainlyMakeTileImageUrl method is based on the search map loading principle: essentially is to construct a get image url link (such as: http://webrd03.is.autonavi.com/appmaptile? X = 1629 & y = 849 & z = 11 & lang = zh_cn & size = 1 & scale = 1 & style = 7 ).
public class AMapProvider : AMapProviderBase { public static readonly AMapProvider Instance; readonly Guid id = new Guid("EF3DD303-3F74-4938-BF40-232D0595EE88"); public override Guid Id { get { return id; } } readonly string name = "AMap"; public override string Name { get { return name; } } static AMapProvider() { Instance = new AMapProvider(); } public override PureImage GetTileImage(GPoint pos, int zoom) { string url = MakeTileImageUrl(pos, zoom, LanguageStr); return GetTileImageUsingHttp(url); } string MakeTileImageUrl(GPoint pos, int zoom, string language) { //http://webrd04.is.autonavi.com/appmaptile?x=5&y=2&z=3&lang=zh_cn&size=1&scale=1&style=7 string url = string.Format(UrlFormat, pos.X, pos.Y, zoom); Console.WriteLine("url:" + url); return url; } static readonly string UrlFormat = "http://webrd04.is.autonavi.com/appmaptile?x={0}&y={1}&z={2}&lang=zh_cn&size=1&scale=1&style=7"; }
How to Use GMAP. net amap in your program
To use the following code, we recommend that you use the code below.
this.MainMap.Position = new PointLatLng(double.Parse(ConfigurationManager.AppSettings["defaultLat"]),double.Parse(ConfigurationManager.AppSettings["defaultLng"]));this.MainMap.MapProvider.Area = new RectLatLng(30.981178, 105.351914, 2.765142, 4.120995);this.MainMap.BoundsOfMap = new RectLatLng(30.981178, 105.351914, 2.765142, 4.120995);this.MainMap.Manager.Mode = AccessMode.CacheOnly;this.MainMap.MapProvider = GMapProviders.AMapProvider;this.MainMap.DragButton = MouseButton.Left;this.MainMap.Zoom = 13;this.MainMap.MinZoom = 8;this.MainMap.MaxZoom = 24;
GMAP. net amap Effect
Normal Map
Satellite Map
How AMAP Loads
To understand how to load AMAP, we also need to understand the loading principle. We can use Chrome to open http://www.amap.com/, and use a location to access the address:
The address of Tile is as follows: http://webrd03.is.autonavi.com/appmaptile? X = 1629 & y = 849 & z = 11 & lang = zh_cn & size = 1 & scale = 1 & style = 7
The Url link parameters are analyzed as follows:
Http://webrd03.is.autonavi.com/appmaptileis fixed
& Lang = zh_cn & size = 1 & scale = 1 & style = 7 is also fixed
X = 1629 is the horizontal coordinate of the grid, and y = 849 is the vertical coordinate of the grid. The Generation Principle of the horizontal and vertical coordinates has been described in the principles section. I will not go into details here.
Z = 11 is the current scaling level.
Therefore, AMAP is relatively simple and standard.
Let's take a look at how to implement AMAP in GMAP. NET.
AMapProvider
Like the operation process of a hundred-degree map, the following process is used to add AMapProvider support.
1)Add abstract class AMapProviderBase
Because AMAP also has common maps and satellite maps, it provides an abstract class with common methods and can be reused.
Public abstract class AMapProviderBase: GMapProvider {public AMapProviderBase () {MaxZoom = null; RefererUrl = "http://www.amap.com/"; Copyright = string. format ("{0} autonavi Corporation, {0} NAVTEQ, {0} Image courtesy of NASA", DateTime. today. year);} public override PureProjection Projection {get {return MercatorProjection. instance ;}} GMapProvider [] overlays; public override GMapProvider [] Overlays {get {if (overlays = null) {overlays = new GMapProvider [] {this };} return overlays ;}}}
2).MapProvider
MainlyMakeTileImageUrl method is based on the search map loading principle: essentially is to construct a get image url link (such as: http://webrd03.is.autonavi.com/appmaptile? X = 1629 & y = 849 & z = 11 & lang = zh_cn & size = 1 & scale = 1 & style = 7 ).
public class AMapProvider : AMapProviderBase { public static readonly AMapProvider Instance; readonly Guid id = new Guid("EF3DD303-3F74-4938-BF40-232D0595EE88"); public override Guid Id { get { return id; } } readonly string name = "AMap"; public override string Name { get { return name; } } static AMapProvider() { Instance = new AMapProvider(); } public override PureImage GetTileImage(GPoint pos, int zoom) { string url = MakeTileImageUrl(pos, zoom, LanguageStr); return GetTileImageUsingHttp(url); } string MakeTileImageUrl(GPoint pos, int zoom, string language) { //http://webrd04.is.autonavi.com/appmaptile?x=5&y=2&z=3&lang=zh_cn&size=1&scale=1&style=7 string url = string.Format(UrlFormat, pos.X, pos.Y, zoom); Console.WriteLine("url:" + url); return url; } static readonly string UrlFormat = "http://webrd04.is.autonavi.com/appmaptile?x={0}&y={1}&z={2}&lang=zh_cn&size=1&scale=1&style=7"; }