Deep understanding of the strongest desktop map controls gmap.net---Baidu map

Source: Internet
Author: User

GMAP. NET supports Google, Bing, Ovi, Openstreetmap, Yahoo,gis and many other maps, but the domestic map support is relatively small.

But it does not matter, we can add Baidu Map support for Gmap.net, as long as the map loading principle, it is easy to integrate in,

Most importantly, it is supported offline, that is to say, using gmap.net, we can make a variety of offline maps for our desktop applications to use,

That's why I call it the strongest map control .

How to use gmap.net Baidu map in your program

The entire code has been submitted to http://ypmap.googlecode.com/, and interested friends can check out the code.

If you want to use, the first thing to refer to the article: in-depth understanding of the strongest desktop map control gmap.net---First use,

and change the initialization code to the following.

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.120995this. MainMap.Manager.Mode = accessmode.cacheonly; this. Mainmap.mapprovider = gmapproviders.baidumapprovider;//or baidusatelitemapprovider  This. Mainmap.dragbutton = Mousebutton.left; this. Mainmap.zoom = 13this. Mainmap.minzoom = 8this. Mainmap.maxzoom = 24;           

GMAP. NET Baidu Map effect

General Map

Satellite map

Baidu Map Loading principle

To understand how gmap.net use Baidu map, then the first to understand the Baidu map of the loading principle or there is a certain need.

We first open the Baidu map with Chrome browser, locate somewhere (for example, Chongqing) and open the Developer tool as shown in:

Continue to see, the original Baidu map is made of such a picture of a photo, and then look at one of the pictures of the link address:

Http://q5.baidu.com/it/u=x=1450;y=418;z=13;v=014;type=web&fm=44. What do these several parameters mean, where

Q5 should be the address of the distributed server, Q3,q4 can also;

U,x,y should be a value based on the mercatorprojection algorithm, which will be elaborated in the theoretical chapter;

Z=13 is the version number that represents the current zoom,v;

The type means that the FM is a fixed value through browser access.

Then gmap.net should also construct a URL to get the picture based on the user's mouse position and the current zoom level.

Gmapprovider

GMAP. NET takes a good code structure, the cache, data structures follow the principle of low coupling-high cohesion, the connection between each module

are also programmed on an interface basis. Similarly, the interface Mapprovider of the map data source follows this principle.

Gmapprovider is the interface of the map data source when the client calls this on initialization. Mainmap.mapprovider = Gmapproviders.baidumapprovider time,

will be based on different maps of the different rules of loading data, the following is a map of Baidu as an example of how to expand the interface of a map data source.

1). Baidumapproviderbase

Add abstract class Baidumapproviderbase inheritance Gmapprovider

Baidumapproviderbase has done three main things.

Initialization of information such as Refereurl,copyright is only useful in copyright;

Return a mercatorprojection instance, talk about Mercatorprojection, can refer to Google's tile engine explain, theory will be described in detail;

Initializes the overlays.

Although may not quite understand now, does not have the relationship, I most start writes the time also not to understand very much, but sees basically all provider to write like this, the leaf out is good. The only thing to note is that it's called xxxproviderbase,

And it is abstract, because the map will have a satellite and a normal map of the two modes, so there must be some common methods.

    PublicAbstractClassBaidumapproviderbase:gmapprovider {PublicBaidumapproviderbase () {maxzoom =Null; Refererurl ="Http://map.baidu.com"; Copyright =String. Format ("©{0} Baidu corporation,©{0} navteq,©{0} Image courtesy of NASA", DateTime.Today.Year); }public overrideget {return Mercatorprojection.instance; }} gmapprovider[] overlays; public overrideget {if (Overlays = = nullnew gmapprovider[] {this};} return Overlays;}} } 

2). Baidumapprovider

Add Baidumapprovider, inherit from Baidumapproviderbase, and implement Gettileimage method. Where Gettileimage is based on the current mouse information pos and zoom than Zoom to get the picture.

The Gettileimageusinghttp (URL) is the URL that gets the picture. OK, you can now according to Baidu map loading principle to construct the URL.

The specific code is as follows:

 PublicClassBaidumapprovider:baidumapproviderbase {....PublicOverride Pureimage Gettileimage (Gpoint pos,IntZoom) {String url =Maketileimageurl (POS, zoom, LANGUAGESTR);ReturnGettileimageusinghttp (URL); }String Maketileimageurl (Gpoint pos,int zoom,StringLanguage) {zoom = Zoom-1;var OffsetX = Math.pow (2, zoom);var OffsetY = OffsetX-1;var numx = pos. XOffsetX;var numy =-pos. Y +OffsetY; Zoom = Zoom +1;var num = (pos. X + pos. Y)%8 +1;var x = numx.tostring (). Replace ("-","M");var y = numy.tostring (). Replace ("-","M");//http://q3.baidu.com/it/u=x=721; y=209;z=12;v=014;type=web&fm=44 String url =String. Format (Urlformat, num, x, y, zoom,"014" web" 44 "); Console.WriteLine ( "url:  "+ URL); return URL;} static readonly string Urlformat =  "http://q{0}.baidu.com/it/u=x={1};y={2}; Z={3};v={4};type={5}&fm={6} "    

Original link: http://www.cnblogs.com/enjoyeclipse/archive/2013/01/14/2859026.html

(turn) deep understanding of the strongest desktop map controls gmap.net---Baidu map

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.