[Android] Chapter 3 (5) Layer display
Category: C#, Android, VS2015, Baidu map application; Creation date: 2016-02-04 3.4 Example 4--Layer display 1. Introduction 1. Map type Baidu Map Android SDK 3.7.1 provides two types For map resources (ordinary vector maps and satellite maps), developers can use the MapType attribute (C#) in BaiduMap to set the map type. C
Category: C#, Android, VS2015, Baidu map application; Creation date: 2016-02-04
3.4 Example 4--Layer display
1. Introduction
1. Map type
Baidu Map Android SDK 3.7.1 provides two types of map resources (ordinary vector maps and satellite maps). Developers can use the MapType attribute (C#) in BaiduMap to set the map type. The C# core code is as follows:
mMapView = FindViewById<TextureMapView><span style="color: #000000;">(Resource.Id.bmapView); mBaiduMap </span>=<span style="color: #000000;"> mMapView.Map; </span><span style="color: #008000;">//</span><span style="color: #008000;">设置底图显示模式:普通地图</span> mBaiduMap.MapType =<span style="color: #000000;"> BaiduMap.MapTypeNormal; </span><span style="color: #008000;">//</span><span style="color: #008000;">设置底图显示模式:卫星地图</span> mBaiduMap.MapType = BaiduMap.MapTypeSatellite;
2. Real-time traffic map
Currently, real-time traffic query is supported in many cities across the country, and will be launched in other cities gradually.
Which cities currently have real-time traffic maps?
Currently (2016-01-27) 31 cities have been opened, namely Nanjing, Guangzhou, Chongqing, Dongguan, Changchun, Taizhou, Fuzhou, Jinhua, Beijing, Changzhou, Hangzhou, Wenzhou, Dalian, Nanchang, Ningbo, Shenyang, Zhongshan, Zhuhai, Foshan, Quanzhou, Shijiazhuang, Chengdu, Qingdao, Shenzhen, Wuhan, Urumqi, Changsha, Shanghai, Tianjin, Wuxi, Xiamen. Other cities will be opened in the future.
The C# core code to open real-time traffic conditions on the map is as follows:
mMapView = FindViewById<TextureMapView><span style="color: #000000;">(Resource.Id.bmapView); mBaiduMap </span>=<span style="color: #000000;"> mMapView.Map; </span><span style="color: #008000;">//</span><span style="color: #008000;">开启交通图</span> mBaiduMap.TrafficEnabled = <span style="color: #0000ff;">true</span>;
3. Baidu city heat map
After opening up the local drawing capabilities of heat maps to developers, Baidu Map SDK once again further opens up the city heat map layer of Baidu's own data to help developers build more diverse mobile applications.
The nature and use of Baidu City Heat Map is similar to that of real-time traffic map. It only requires simple interface calls to display Baidu City Heat Map with rich styles on the map.
The C# core code to open Baidu city heat map on the map is as follows:
mMapView = FindViewById<TextureMapView><span style="color: #000000;">(Resource.Id.bmapView); mBaiduMap </span>=<span style="color: #000000;"> mMapView.Map; </span><span style="color: #008000;">//</span><span style="color: #008000;">开启交通图</span> mBaiduMap.BaiduHeatMapEnabled = <span style="color: #0000ff;">true</span>;
Based on the example in the previous section, you only need to add the following steps.
2. Add demo04_layers.axml file
<?xml version=<span style="color: #800000;">"</span><span style="color: #800000;">1.0</span><span style="color: #800000;">"</span> encoding=<span style="color: #800000;">"</span><span style="color: #800000;">utf-8</span><span style="color: #800000;">"</span>?> <LinearLayout xmlns:android=<span style="color: #800000;">"</span><span style="color: #800000;">http://schemas.android.com/apk/res/android</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_width</span>=<span style="color: #800000;">"</span><span style="color: #800000;">fill_parent</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_height</span>=<span style="color: #800000;">"</span><span style="color: #800000;">fill_parent</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:orientation</span>=<span style="color: #800000;">"</span><span style="color: #800000;">vertical</span><span style="color: #800000;">"</span> > <<span style="color: #000000;">LinearLayout android:layout_width</span>=<span style="color: #800000;">"</span><span style="color: #800000;">fill_parent</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_height</span>=<span style="color: #800000;">"</span><span style="color: #800000;">wrap_content</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:orientation</span>=<span style="color: #800000;">"</span><span style="color: #800000;">horizontal</span><span style="color: #800000;">"</span> > <<span style="color: #000000;">RadioGroup android:id</span>=<span style="color: #800000;">"</span><span style="color: #800000;">@+id/RadioGroup</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_width</span>=<span style="color: #800000;">"</span><span style="color: #800000;">wrap_content</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_height</span>=<span style="color: #800000;">"</span><span style="color: #800000;">wrap_content</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_weight</span>=<span style="color: #800000;">"</span><span style="color: #800000;">2</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:orientation</span>=<span style="color: #800000;">"</span><span style="color: #800000;">horizontal</span><span style="color: #800000;">"</span> > <<span style="color: #000000;">RadioButton android:id</span>=<span style="color: #800000;">"</span><span style="color: #800000;">@+id/normal</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_width</span>=<span style="color: #800000;">"</span><span style="color: #800000;">wrap_content</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_height</span>=<span style="color: #800000;">"</span><span style="color: #800000;">wrap_content</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_weight</span>=<span style="color: #800000;">"</span><span style="color: #800000;">1</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:</span><span style="color: #0000ff;">checked</span>=<span style="color: #800000;">"</span><span style="color: #800000;">true</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:text</span>=<span style="color: #800000;">"</span><span style="color: #800000;">普通图</span><span style="color: #800000;">"</span> /> <<span style="color: #000000;">RadioButton android:id</span>=<span style="color: #800000;">"</span><span style="color: #800000;">@+id/statellite</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_width</span>=<span style="color: #800000;">"</span><span style="color: #800000;">wrap_content</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_height</span>=<span style="color: #800000;">"</span><span style="color: #800000;">wrap_content</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_weight</span>=<span style="color: #800000;">"</span><span style="color: #800000;">1</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:text</span>=<span style="color: #800000;">"</span><span style="color: #800000;">卫星图</span><span style="color: #800000;">"</span> /> </RadioGroup> <<span style="color: #000000;">CheckBox android:id</span>=<span style="color: #800000;">"</span><span style="color: #800000;">@+id/traffice</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_width</span>=<span style="color: #800000;">"</span><span style="color: #800000;">wrap_content</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_height</span>=<span style="color: #800000;">"</span><span style="color: #800000;">wrap_content</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_weight</span>=<span style="color: #800000;">"</span><span style="color: #800000;">1</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:</span><span style="color: #0000ff;">checked</span>=<span style="color: #800000;">"</span><span style="color: #800000;">false</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:text</span>=<span style="color: #800000;">"</span><span style="color: #800000;">交通图</span><span style="color: #800000;">"</span> /> <<span style="color: #000000;">CheckBox android:id</span>=<span style="color: #800000;">"</span><span style="color: #800000;">@+id/baiduHeatMap</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_width</span>=<span style="color: #800000;">"</span><span style="color: #800000;">wrap_content</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_height</span>=<span style="color: #800000;">"</span><span style="color: #800000;">wrap_content</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_weight</span>=<span style="color: #800000;">"</span><span style="color: #800000;">1</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:</span><span style="color: #0000ff;">checked</span>=<span style="color: #800000;">"</span><span style="color: #800000;">false</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:text</span>=<span style="color: #800000;">"</span><span style="color: #800000;">百度城市热力图</span><span style="color: #800000;">"</span> /> </LinearLayout> <<span style="color: #000000;">com.baidu.mapapi.map.TextureMapView android:id</span>=<span style="color: #800000;">"</span><span style="color: #800000;">@+id/bmapView</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_width</span>=<span style="color: #800000;">"</span><span style="color: #800000;">fill_parent</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_height</span>=<span style="color: #800000;">"</span><span style="color: #800000;">fill_parent</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:clickable</span>=<span style="color: #800000;">"</span><span style="color: #800000;">true</span><span style="color: #800000;">"</span> /> </LinearLayout>
2. Add the Demo04Layers.cs file
Add this file under the SrcSdkDemos folder.
<span style="color: #0000ff;">using</span><span style="color: #000000;"> Android.App; </span><span style="color: #0000ff;">using</span><span style="color: #000000;"> Android.Content.PM; </span><span style="color: #0000ff;">using</span><span style="color: #000000;"> Android.OS; </span><span style="color: #0000ff;">using</span><span style="color: #000000;"> Android.Widget; </span><span style="color: #0000ff;">using</span><span style="color: #000000;"> Com.Baidu.Mapapi.Map; </span><span style="color: #0000ff;">namespace</span><span style="color: #000000;"> BdMapV371Demos.SrcSdkDemos { </span><span style="color: #808080;">///</span> <span style="color: #808080;"><summary></span> <span style="color: #808080;">///</span><span style="color: #008000;"> 演示地图图层显示的控制方法 </span><span style="color: #808080;">///</span> <span style="color: #808080;"></summary></span> [Activity(Label = <span style="color: #800000;">"</span><span style="color: #800000;">@string/demo_name_layers</span><span style="color: #800000;">"</span><span style="color: #000000;">, ConfigurationChanges </span>= ConfigChanges.Orientation |<span style="color: #000000;"> ConfigChanges.KeyboardHidden, ScreenOrientation </span>=<span style="color: #000000;"> ScreenOrientation.Sensor)] </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span><span style="color: #000000;"> Demo04Layers : Activity { </span><span style="color: #008000;">//</span><span style="color: #008000;">TextureMapView 是地图主控件</span> <span style="color: #0000ff;">PRivate</span><span style="color: #000000;"> TextureMapView mMapView; </span><span style="color: #0000ff;">private</span><span style="color: #000000;"> BaiduMap mBaiduMap; </span><span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> OnCreate(Bundle savedInstanceState) { </span><span style="color: #0000ff;">base</span><span style="color: #000000;">.OnCreate(savedInstanceState); SetContentView(Resource.Layout.demo04_layers); mMapView </span>= FindViewById<TextureMapView><span style="color: #000000;">(Resource.Id.bmapView); mBaiduMap </span>=<span style="color: #000000;"> mMapView.Map; mBaiduMap.SetMapStatus(MapStatusUpdateFactory.NewLatLng(MainActivity.HeNanUniversity)); </span><span style="color: #008000;">//</span><span style="color: #008000;">设置底图显示模式:普通图</span> <span style="color: #0000ff;">var</span> normal = FindViewById<RadioButton><span style="color: #000000;">(Resource.Id.normal); normal.Click </span>+= <span style="color: #0000ff;">delegate</span><span style="color: #000000;"> { mBaiduMap.MapType </span>=<span style="color: #000000;"> BaiduMap.MapTypeNormal; }; </span><span style="color: #008000;">//</span><span style="color: #008000;">设置底图显示模式:卫星图</span> <span style="color: #0000ff;">var</span> statellite = FindViewById<RadioButton><span style="color: #000000;">(Resource.Id.statellite); statellite.Click </span>+= <span style="color: #0000ff;">delegate</span><span style="color: #000000;"> { mBaiduMap.MapType </span>=<span style="color: #000000;"> BaiduMap.MapTypeSatellite; }; </span><span style="color: #008000;">//</span><span style="color: #008000;">是否显示交通图</span> <span style="color: #0000ff;">var</span> traffice = FindViewById<CheckBox><span style="color: #000000;">(Resource.Id.traffice); traffice.CheckedChange </span>+= (s, e) =><span style="color: #000000;"> { mBaiduMap.TrafficEnabled </span>=<span style="color: #000000;"> e.IsChecked; }; </span><span style="color: #008000;">//</span><span style="color: #008000;">是否显示热力图</span> <span style="color: #0000ff;">var</span> baiduHeatMap = FindViewById<CheckBox><span style="color: #000000;">(Resource.Id.baiduHeatMap); traffice.CheckedChange </span>+= (s, e) =><span style="color: #000000;"> { mBaiduMap.BaiduHeatMapEnabled </span>=<span style="color: #000000;"> e.IsChecked; }; } </span><span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> OnPause() { mMapView.OnPause(); </span><span style="color: #0000ff;">base</span><span style="color: #000000;">.OnPause(); } </span><span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> OnResume() { mMapView.OnResume(); </span><span style="color: #0000ff;">base</span><span style="color: #000000;">.OnResume(); } </span><span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> OnDestroy() { mMapView.OnDestroy(); </span><span style="color: #0000ff;">base</span><span style="color: #000000;">.OnDestroy(); } } }</span>
4. Modify the MainActivity.cs file
Add the following code in the demos field definition of the MainActivity.cs file.
<span style="color: #008000;"> //</span><span style="color: #008000;">示例4--图层展示</span> <span style="color: #0000ff;">new</span> DemoInfo<Activity><span style="color: #000000;">(Resource.String.demo_title_layers, Resource.String.demo_desc_layers, </span><span style="color: #0000ff;">new</span> Demo04Layers()),
Run.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In recent days, Ice Universe has been steadily revealing details about the Galaxy S25 Ultra, which is widely believed to be Samsung's next flagship smartphone. Among other things, the leaker claimed that Samsung only plans to bring one camera upgrade

OnLeaks has now partnered with Android Headlines to provide a first look at the Galaxy S25 Ultra, a few days after a failed attempt to generate upwards of $4,000 from his X (formerly Twitter) followers. For context, the render images embedded below h

Alongside announcing two new smartphones, TCL has also announced a new Android tablet called the NXTPAPER 14, and its massive screen size is one of its selling points. The NXTPAPER 14 features version 3.0 of TCL's signature brand of matte LCD panels

The Vivo Y300 Pro just got fully revealed, and it's one of the slimmest mid-range Android phones with a large battery. To be exact, the smartphone is only 7.69 mm thick but features a 6,500 mAh battery. This is the same capacity as the recently launc

Samsung has not offered any hints yet about when it will update its Fan Edition (FE) smartphone series. As it stands, the Galaxy S23 FE remains the company's most recent edition, having been presented at the start of October 2023. However, plenty of

In recent days, Ice Universe has been steadily revealing details about the Galaxy S25 Ultra, which is widely believed to be Samsung's next flagship smartphone. Among other things, the leaker claimed that Samsung only plans to bring one camera upgrade

The Redmi Note 14 Pro Plus is now official as a direct successor to last year'sRedmi Note 13 Pro Plus(curr. $375 on Amazon). As expected, the Redmi Note 14 Pro Plus heads up the Redmi Note 14 series alongside theRedmi Note 14and Redmi Note 14 Pro. Li

OnePlus'sister brand iQOO has a 2023-4 product cycle that might be nearlyover; nevertheless, the brand has declared that it is not done with itsZ9series just yet. Its final, and possibly highest-end,Turbo+variant has just beenannouncedas predicted. T
