Overview
All contents that overlay or overwrite a map are collectively referred to as map covers. Such as annotation, vector graphics elements (including: Line and polygon and circle), positioning icons, etc. The cover has its own geographic coordinates. When you drag or scale a map, they move accordingly.
The map API provides the following cover types:
- Overlay: the abstract base class of the cover. All the covers inherit this class of method to display custom layers.
- Mylocationoverlay: An overlay that displays the current user location.
Itemizedoverlay <item extends overlayitem>: a base class of overlay, which contains an overlayitem list, which is equivalent to an overlay of one group. by inheriting this class, a group of interest points are displayed on the map.
Poioverlay: A local search layer that provides a location search service for a specific region. For example, you can search for a "park" in Beijing and use this layer to display the park on a map.
Routeoverlay: a layer of walking and driving navigation lines. The routes and key points of the walking and driving routes are displayed on the map.
Transitoverlay: A bus transfer line layer that displays the route and transfer location of a bus trip plan in a specific region on the map.
Abstract base class of the covering: Overlay
To add an overlay in mapview, follow these steps:
- The custom class inherits overlay and override its draw () method. If you need to click, press, touch, and other interactive operations, override ONTAP () and other methods are also required.
Package xiaosi. baidumap; import android. graphics. canvas; import android. graphics. paint; import android. graphics. point; import android. OS. bundle; import android. view. view; import android. view. view. onclicklistener; import android. widget. button; import COM. baidu. mapapi. bmapmanager; import COM. baidu. mapapi. geopoint; import COM. baidu. mapapi. mapactivity; import COM. baidu. mapapi. mapcontroller; import COM. baidu. mapapi. Mapview; import COM. baidu. mapapi. overlay; public class baidumapactivity extends mapactivity {/** called when the activity is first created. */private bmapmanager mapmanager = NULL; private string key = "Hangzhou"; private mapview = NULL; @ overridepublic void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); mapma Nager = new bmapmanager (getapplication (); mapmanager. init (Key, null); super. initmapactivity (mapmanager); mapview = (mapview) findviewbyid (R. id. mapsview); mapview. setbuiltinzoomcontrols (true); // set to enable the built-in zoom control mapcontroller = mapview. getcontroller (); // get control of mmapview, which can be used to control and drive translation and scaling // geopoint point = new geopoint (INT) (39.915*1e6 ), // (INT) (116.404*1e6); // construct a geopoint with the given longitude and latitude, in the unit * 1e6) // mapcontroller. setcenter (point); // sets the map center point mapcontroller. setzoom (12); // sets the map zoom level mapview. getoverlays (). add (New myoverlay ()); /// ++ ++ }@overrideprotected Boolean isroutedisplayed () {return false ;}@ overrideprotected void ondestroy () {If (mapmanager! = NULL) {mapmanager. Destroy (); mapmanager = NULL;} super. ondestroy () ;}@ overrideprotected void onpause () {If (mapmanager! = NULL) {mapmanager. Stop () ;}super. onpause () ;}@ overrideprotected void onresume () {If (mapmanager! = NULL) {mapmanager. start ();} super. onresume ();} public class myoverlay extends overlay {geopoint = new geopoint (INT) (39.915*1e6), (INT) (116.404*1e6 )); paint paint = new paint (); @ overridepublic void draw (canvas, mapview, Boolean shadow) {// draw a stringpoint point = mapview at the Tiananmen Square. getprojection (). topixels (geopoint, null); canvas. drawtext ("★Here is Tiananmen Square ", point. X, point. Y, paint );}}}