Osmdroid 6.0.1 loads online vector and image data of the map, osmdroid6.0.1
Osmdroid has recently been upgraded to version 6.0.1. One major function is to scale to 29, which is about 0.02 meters. This article mainly describes loading online vector and image data of a map.
1. Image Display
2. Code display
Package com. osmdroid. sample. activity. titlesource; import android. OS. bundle; import android. support. v7.app. appCompatActivity; import android. view. view; import com. osmdroid. sample. r; import com. osmdroid. sample. util. customsOsmdroidMapConfig; import org. osmdroid. tileprovider. mapTileProviderBasic; import org. osmdroid. tileprovider. tilesource. onlineTileSourceBase; import org. osmdroid. util. geoPoint; import org. osmdroid. util. mapTileIndex; import org. osmdroid. views. mapView; import org. osmdroid. views. overlay. tilesOverlay;/*** map of Heaven and Earth ** removed the MapTile class in version 6.0 or later, so the TileURL for online tile map loading has changed a bit */public class TiandituTitleSouceTestActivity extends AppCompatActivity implements View. onClickListener {private MapView mapView; CustomsOsmdroidMapConfig config = new CustomsOsmdroidMapConfig (); // image map _ W is mocato projection _ c is the country's 2000 coordinate system OnlineTileSourceBase tianDiTuImgTileSource = new OnlineTileSourceBase ("Tian Di Tu Img", 1, 18,256 ,"", new String [] {" http://t1.tianditu.com/DataServer?T=img_w "," http://t2.tianditu.com/DataServer?T=img_w "," http://t3.tianditu.com/DataServer?T=img_w "," http://t4.tianditu.com/DataServer?T=img_w "," http://t5.tianditu.com/DataServer?T=img_w "," http://t6.tianditu.com/DataServer?T=img_w "}) {@ Override public String getTileURLString (final long pMapTileIndex) {return getBaseUrl () +" & X = "+ MapTileIndex. getX (pMapTileIndex) + "& Y =" + MapTileIndex. getY (pMapTileIndex) + "& L =" + MapTileIndex. getZoom (pMapTileIndex) ;}}; // image annotation _ W is mocato projection _ c is the national coordinate system OnlineTileSourceBase tianDiTuCiaTileSource = new OnlineTileSourceBase ("Tian Di Tu Cia", 1, 18,256, "", new String [] {" http://t1.tianditu.com/DataServer?T=cia_w "," http://t2.tianditu.com/DataServer?T=cia_w "," http://t3.tianditu.com/DataServer?T=cia_w "," http://t4.tianditu.com/DataServer?T=cia_w "," http://t5.tianditu.com/DataServer?T=cia_w "," http://t6.tianditu.com/DataServer?T=cia_w "}) {@ Override public String getTileURLString (final long pMapTileIndex) {return getBaseUrl () +" & X = "+ MapTileIndex. getX (pMapTileIndex) + "& Y =" + MapTileIndex. getY (pMapTileIndex) + "& L =" + MapTileIndex. getZoom (pMapTileIndex) ;}}; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_title_source); initView ();} private void initView () {findViewById (R. id. button ). setOnClickListener (this); mapView = (MapView) findViewById (R. id. mymapview); config. initMapOverlays (mapView, this); mapView. setDrawingCacheEnabled (true); mapView. setMultiTouchControls (true); // zoom in and out the mapView. setMaxZoomLevel (18.0); mapView. setMinZoomLevel (6.0); mapView. getController (). setZoom (12.0); // mMapView mapView. setTileSource (tianDiTuImgTileSource); TilesOverlay tilesOverlay = new TilesOverlay (new MapTileProviderBasic (this, tianDiTuCiaTileSource), this); mapView. getOverlayManager (). add (tilesOverlay) ;}@ Override public void onClick (View v) {switch (v. getId () {case R. id. button: // locate the current position and set the zoom level mapView. getController (). setZoom (18.0); mapView. getController (). setCenter (new GeoPoint (23.12648183, 113.365548756); break; default: break ;}}}
Package com. osmdroid. sample. activity. titlesource; import android. OS. bundle; import android. support. v7.app. appCompatActivity; import android. view. view; import com. osmdroid. sample. r; import com. osmdroid. sample. util. customsOsmdroidMapConfig; import org. osmdroid. tileprovider. mapTileProviderBasic; import org. osmdroid. tileprovider. tilesource. onlineTileSourceBase; import org. osmdroid. util. geoPoint; import org. osmdroid. util. mapTileIndex; import org. osmdroid. views. mapView; import org. osmdroid. views. overlay. tilesOverlay;/*** map of Heaven and Earth */public class TiandituTitleSouceTestActivity2 extends AppCompatActivity implements View. onClickListener {private MapView mapView; CustomsOsmdroidMapConfig config = new CustomsOsmdroidMapConfig (); // map _ W is mocato projection _ c is the national coordinate system OnlineTileSourceBase tianDiTuImgTileSource = new OnlineTileSourceBase ("Tian Di tuimg", 1, 2000 ,"", new String [] {" http://t1.tianditu.com/DataServer?T=vec_W "," http://t2.tianditu.com/DataServer?T=vec_w "," http://t3.tianditu.com/DataServer?T=vec_w "," http://t4.tianditu.com/DataServer?T=vec_w "," http://t5.tianditu.com/DataServer?T=vec_w "," http://t6.tianditu.com/DataServer?T=vec_w "}) {@ Override public String getTileURLString (final long pMapTileIndex) {return getBaseUrl () +" & X = "+ MapTileIndex. getX (pMapTileIndex) + "& Y =" + MapTileIndex. getY (pMapTileIndex) + "& L =" + MapTileIndex. getZoom (pMapTileIndex) ;}}; // note _ W is the mocato projection _ c is the national 2000 coordinate system cva_c // (Initial Chinese English) cva cia stands for Chinese eia eva is English OnlineTileSourceBase tianDiTuCiaTileSource = new OnlineTileSourceBase ("Tian Di Tu Cia", 1, 22,256, "", new String [] {" http://t1.tianditu.com/DataServer?T=cva_w "," http://t2.tianditu.com/DataServer?T=cva_w "," http://t3.tianditu.com/DataServer?T=cva_w "," http://t4.tianditu.com/DataServer?T=cva_w "," http://t5.tianditu.com/DataServer?T=cva_w "," http://t6.tianditu.com/DataServer?T=cva_w "}) {@ Override public String getTileURLString (final long pMapTileIndex) {return getBaseUrl () +" & X = "+ MapTileIndex. getX (pMapTileIndex) + "& Y =" + MapTileIndex. getY (pMapTileIndex) + "& L =" + MapTileIndex. getZoom (pMapTileIndex) ;}}; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_title_source); initView ();} private void initView () {findViewById (R. id. button ). setOnClickListener (this); mapView = (MapView) findViewById (R. id. mymapview); config. initMapOverlays (mapView, this); mapView. setMaxZoomLevel (22.0); mapView. setMinZoomLevel (6.0); mapView. getController (). setZoom (12.0); // mMapView mapView. setTileSource (tianDiTuImgTileSource); TilesOverlay tilesOverlay = new TilesOverlay (new MapTileProviderBasic (this, tianDiTuCiaTileSource), this); mapView. getOverlayManager (). add (tilesOverlay) ;}@ Override public void onClick (View v) {switch (v. getId () {case R. id. button: // locate the current position and set the zoom level mapView. getController (). setZoom (18.0); mapView. getController (). setCenter (new GeoPoint (23.12648183, 113.365548756); break; default: break ;}}}
Remember to attach network and storage Permissions
3. Information collected online
The world map we see is actually made up of tiled tiles, which are stored in the map service and each tile has its own URI,
The world map consists of four types of tiles,
These are: vec (vector basemap tile), cva (vector annotation tile), img (image basemap tile), and cia (image annotation tile). Their corresponding Uris are:
Vector Map: http://t0.tianditu.com/DataServer? T = vec_c & x = 0 & y = 0 & l = 1
Vector Note: http://t0.tianditu.com/DataServer? T = cva_c & x = 0 & y = 0 & l = 1
Image Base Map: http://t0.tianditu.com/DataServer? T = img_c & x = 0 & y = 0 & l = 1
Image Note: http://t0.tianditu.com/DataServer? T = cia_c & x = 0 & y = 0 & l = 1
Each URI contains four parameters:
T = vec_c; x =? ; Y =? ; L = ?;
T indicates the base map type, x indicates the column number of the tile (start bit 0), y indicates the row number of the tile (start bit 0), and l indicates the base map level (start bit 1, Max. 20 ).