Custom map example: Map World (2)

Source: Internet
Author: User

With the URL generation rules of Map Images, you can start to support custom map types.

MapType is used in the Guide bee map package. The ICustomMapType interface is mainly used to support custom maps. The class MapType defines GENERIC_MAPTYPE_1, GENERIC_MAPTYPE_2... GENERIC_MAPTYPE_7 consists of two layers (GENERIC_MAPTYPE_6 and GENERIC_MAPTYPE_7). That is to say, GENERIC_MAPTYPE_6 is drawn when the map type is ready, and GENERIC_MAPTYPE_7 is drawn on it, two layers are superimposed. More than two layers of map images are rare.

According to the characteristics of map world, GENERIC_MAPTYPE_7 is used as its map type. 1-10 consists of two layers of map, one layer of image and one layer of annotation. Layer 11 or above can also be regarded as two layers, and the other layer is empty layer.

The interface ICustomMapType defines only one method: map image generation rules.

[Java]
Public String getTileURL (int mtype, int x, int y, int zoomLevel );

Public String getTileURL (int mtype, int x, int y, int zoomLevel );

Currently, Android is used as an example. Similar to other platforms, add CustomMap Activity to the GISEngineTutorial project.

[Java]
Package com. pstreets. gisengine. demo;
Import com. mapdigit. gis. raster. ICustomMapType;
Import com. mapdigit. gis. raster. MapType;

Import com. mapdigit. gis. geometry. GeoLatLng;
Import com. pstreets. gisengine. R;
Import com. pstreets. gisengine. SharedMapInstance;

Import android. app. Activity;
Import android. OS. Bundle;
Import android. view. Menu;
Import android. view. MenuInflater;
Import android. view. MenuItem;

Public class CustomMap extends Activity {

@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
}

@ Override
Public void onStart (){
Super. onStart ();
MapType. setCustomMapTileUrl (new TiandiMapType ());
GeoLatLng center = new GeoLatLng (32.0616667, 118.7777778 );
SharedMapInstance. map. setCenter (center, 13, MapType. GENERIC_MAPTYPE_7 );

}

@ Override
Public boolean onCreateOptionsMenu (Menu menu ){
MenuInflater inflater = getMenuInflater ();
Inflater. inflate (R. menu. mapzoom_menu, menu );
Return true;
}

@ Override
Public boolean onOptionsItemSelected (MenuItem item ){
// Handle item selection
Switch (item. getItemId ()){
Case R. id. zoomin:
SharedMapInstance. map. zoomIn ();

Return true;
Case R. id. zoomout:
SharedMapInstance. map. zoomOut ();
Return true;

Default:
Return super. onOptionsItemSelected (item );
}

}

}

Class TiandiMapType implements ICustomMapType {

Private static int serverIndex = 1;

Public String getTileURL (int mtype, int x, int y, int zoomLevel ){
String returnURL = "";
ServerIndex + = 1;
ServerIndex % = 6;
Int maxTiles = (int) Math. pow (2, zoomLevel );
Switch (mtype ){

Case MapType. GENERIC_MAPTYPE_6:

If (zoomLevel <11 ){
ReturnURL = "http: // tile" + serverIndex
+ ".Tianditu.com/DataServer? T = A0512_EMap ";
ReturnURL + = "& X =" + x + "& Y =" + y + "& L =" + zoomLevel;

} Else if (zoomLevel <13 ){
ReturnURL = "http: // tile" + serverIndex
+ ".Tianditu.com/DataServer? T = B0627_EMap1112 ";
ReturnURL + = "& X =" + x + "& Y =" + y + "& L =" + zoomLevel;
} Else {
ReturnURL = "http: // tile" + serverIndex
+ ".Tianditu.com/DataServer? T = siwei0608 ";
ReturnURL + = "& X =" + x + "& Y =" + y + "& L =" + zoomLevel;
}

Break;
Case MapType. GENERIC_MAPTYPE_7:
If (zoomLevel <11 ){
ReturnURL = "http: // tile" + serverIndex
+ ".Tianditu.com/DataServer? T = AB0512_Anno ";
ReturnURL + = "& X =" + x + "& Y =" + y + "& L =" + zoomLevel;
} Else {
ReturnURL = MapType. EMPTY_TILE_URL;
}

Break;

}
Return returnURL;
}

}
Package com. pstreets. gisengine. demo;
Import com. mapdigit. gis. raster. ICustomMapType;
Import com. mapdigit. gis. raster. MapType;
 
Import com. mapdigit. gis. geometry. GeoLatLng;
Import com. pstreets. gisengine. R;
Import com. pstreets. gisengine. SharedMapInstance;
 
Import android. app. Activity;
Import android. OS. Bundle;
Import android. view. Menu;
Import android. view. MenuInflater;
Import android. view. MenuItem;
 
Public class CustomMap extends Activity {
 
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
}
 
@ Override
Public void onStart (){
Super. onStart ();
MapType. setCustomMapTileUrl (new TiandiMapType ());
GeoLatLng center = new GeoLatLng (32.0616667, 118.7777778 );
SharedMapInstance. map. setCenter (center, 13, MapType. GENERIC_MAPTYPE_7 );
 
}
 
@ Override
Public boolean onCreateOptionsMenu (Menu menu ){
MenuInflater inflater = getMenuInflater ();
Inflater. inflate (R. menu. mapzoom_menu, menu );
Return true;
}
 
@ Override
Public boolean onOptionsItemSelected (MenuItem item ){
// Handle item selection
Switch (item. getItemId ()){
Case R. id. zoomin:
SharedMapInstance. map. zoomIn ();
 
Return true;
Case R. id. zoomout:
SharedMapInstance. map. zoomOut ();
Return true;
 
Default:
Return super. onOptionsItemSelected (item );
}
 
}
 
}
 
Class TiandiMapType implements ICustomMapType {
 
Private static int serverIndex = 1;
 
Public String getTileURL (int mtype, int x, int y, int zoomLevel ){
String returnURL = "";
ServerIndex + = 1;
ServerIndex % = 6;
Int maxTiles = (int) Math. pow (2, zoomLevel );
Switch (mtype ){
 
Case MapType. GENERIC_MAPTYPE_6:
 
If (zoomLevel <11 ){
ReturnURL = "http: // tile" + serverIndex
+ ".Tianditu.com/DataServer? T = A0512_EMap ";
ReturnURL + = "& X =" + x + "& Y =" + y + "& L =" + zoomLevel;
 
} Else if (zoomLevel <13 ){
ReturnURL = "http: // tile" + serverIndex
+ ".Tianditu.com/DataServer? T = B0627_EMap1112 ";
ReturnURL + = "& X =" + x + "& Y =" + y + "& L =" + zoomLevel;
} Else {
ReturnURL = "http: // tile" + serverIndex
+ ".Tianditu.com/DataServer? T = siwei0608 ";
ReturnURL + = "& X =" + x + "& Y =" + y + "& L =" + zoomLevel;
}
 
Break;
Case MapType. GENERIC_MAPTYPE_7:
If (zoomLevel <11 ){
ReturnURL = "http: // tile" + serverIndex
+ ".Tianditu.com/DataServer? T = AB0512_Anno ";
ReturnURL + = "& X =" + x + "& Y =" + y + "& L =" + zoomLevel;
} Else {
ReturnURL = MapType. EMPTY_TILE_URL;
}
 
Break;
 
}
Return returnURL;
}
 
}


It looks good, but after careful analysis, the sharding method of map world is different from that of Google map. At the same scaling level, map world is half shorter than Google map in the height direction, specifically, the two types of maps are set to the minimum level (display world maps). The size of the map is 512X256, while that of the Google map is 512X512. The result is that the longitude and latitude coordinates of the map must be adjusted. How to adjust it will be described in detail later. However, this does not affect the User-Defined map sample method. If the User-Defined map partition method and the Google location method, you do not need to adjust the longitude and latitude coordinates. It should be noted that the adjustment of latitude and longitude coordinates and coordinate offset are different concepts. Here, the latitude and longitude coordinates are adjusted because the coordinate Projection Method of the map is different from that of the Google Map, while the coordinate offset refers to the artificially added offset.

Author: mapdigit
 

 

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.