分类:C#、Android、VS2015、百度地图应用; 创建日期:2016-02-04

一、简介

百度地图SDK所提供的地图等级为3-19级(3.7.1版本中有些部分已经提供到了21级),所包含的信息有建筑物、道路、河流、学校、公园等内容。百度将所有叠加或覆盖到地图的内容统称为地图覆盖物。如标注、矢量图形元素(包括:折线、多边形和圆等)、定位图标等。覆盖物拥有自己的地理坐标,当拖动或缩放地图时,它们会相应的移动。

百度地图SDK 3.7.1支持多种地图覆盖物。该版本所支持的地图覆盖物有:定位图层、地图标注(Marker)、几何图形(点、折线、弧线、多边形等)、地形图图层、POI检索结果覆盖物、线路规划结果覆盖物、热力图图层、瓦片图层以及自定义标注等。

1、标注覆盖物

(1)标注

开发者可根据自己实际的业务需求,利用标注覆盖物,在地图指定的位置上添加标注信息。

(2)底图标注

自v3.6.0版本起,SDK在BaiduMap提供了控制底图标注的ShowMapPoi方法,默认显示底图标注。利用此方法可得到仅显示道路信息的地图。

2、几何图形覆盖物

地图SDK提供多种结合图形覆盖物,利用这些图形,可帮助您构建更加丰富多彩的地图应用。目前提供的几何图形有:点(Dot)、折线(Polyline)、弧线(Arc)、圆(Circle)、多边形(Polygon)。

3、文字覆盖物

文字,在地图中也是一种覆盖物,开发者可利用相关的接口,快速实现在地图上书写文字的需求。

4、弹出窗覆盖物

利用弹出窗覆盖物可构建具有更强交互性的地图页面。

5、地形图图层

地形图图层(GroundOverlay),又可叫做图片图层,即开发者可在地图的指定位置上添加图片。该图片可随地图的平移、缩放、旋转等操作做相应的变换。该图层是一种特殊的Overlay, 它位于底图和底图标注层之间(即该图层不会遮挡地图标注信息)。

6、检索结果覆盖物

针对检索功能模块(POI检索、线路规划等),地图SDK还对外提供相应的覆盖物来快速展示结果信息。这些方法都是开源的,开发者可根据自己的实际去求来做个性化的定制。

二、运行截图

简介:介绍添加覆盖物并响应点击功能和弹出pop功能

详述:

(1)在popup中添加弹出自定义View的示例;

(2)点击周围4个Marker,弹出popup,可更新marker位置和更新marker图标;

(3)中间显示的为图片图层,该图层可随地图的移动、缩放等做出相应的操作;

(4)支持Maker设置透明度的方法,利用滑动条可以展示maker透明度变化;

(5)支持Marker设置动画的能力,包含两种方式:从地上生长和从天上落下。

本示例运行截图如下:

三、设计步骤

1、添加demo09_overlay.xml文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" > <Button
android:id="@+id/clear"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="2dip"
android:layout_marginLeft="2dip"
android:layout_marginRight="2dip"
android:layout_marginTop="2dip"
android:layout_weight="1"
android:padding="10dip"
android:text="清除(clear)" /> <Button
android:id="@+id/resert"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="2dip"
android:layout_marginLeft="2dip"
android:layout_marginRight="2dip"
android:layout_marginTop="2dip"
android:layout_weight="1"
android:text="重置(reset)" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" > <SeekBar
android:id="@+id/alphaBar"
android:layout_marginBottom="2dip"
android:layout_marginLeft="2dip"
android:layout_marginRight="2dip"
android:layout_marginTop="2dip"
android:layout_weight="1"
android:layout_width="155dp"
android:max="10"
android:progress="10"
android:layout_height="wrap_content" /> <CheckBox
android:id="@+id/animation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2dip"
android:layout_marginLeft="2dip"
android:layout_marginRight="2dip"
android:layout_marginTop="2dip"
android:layout_weight="1"
android:checked="true"
android:text="Marker添加动画" />
</LinearLayout> <com.baidu.mapapi.map.TextureMapView
android:id="@+id/bmapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" /> </LinearLayout>

2、添加Demo09Overlay.cs文件

在SrcSdkDemos文件夹下添加该文件,然后将其内容改为下面的代码:

using Android.App;
using Android.Content.PM;
using Android.Graphics;
using Android.OS;
using Android.Widget;
using Com.Baidu.Mapapi.Map;
using Com.Baidu.Mapapi.Model;
using System.Collections.Generic; namespace BdMapV371Demos.SrcSdkDemos
{
/// <summary>
/// 演示覆盖物的用法
/// </summary>
[Activity(Label = "@string/demo_name_overlay",
ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.KeyboardHidden,
ScreenOrientation = ScreenOrientation.Sensor)]
public class Demo09Overlay : Activity
{
private TextureMapView mMapView;
private BaiduMap mBaiduMap;
private Marker mMarkerA;
private Marker mMarkerB;
private Marker mMarkerC;
private Marker mMarkerD;
private CheckBox animationBox = null; // 初始化全局 bitmap 信息,不用时及时 Recycle
BitmapDescriptor bdA = BitmapDescriptorFactory.FromResource(Resource.Drawable.icon_marka);
BitmapDescriptor bdB = BitmapDescriptorFactory.FromResource(Resource.Drawable.icon_markb);
BitmapDescriptor bdC = BitmapDescriptorFactory.FromResource(Resource.Drawable.icon_markc);
BitmapDescriptor bdD = BitmapDescriptorFactory.FromResource(Resource.Drawable.icon_markd);
BitmapDescriptor bd = BitmapDescriptorFactory.FromResource(Resource.Drawable.icon_gcoding);
BitmapDescriptor bdGround = BitmapDescriptorFactory.FromResource(Resource.Drawable.ground_overlay); protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.demo09_overlay); var clear = FindViewById<Button>(Resource.Id.clear);
clear.Click += delegate
{
ClearOverlay();
}; var resert = FindViewById<Button>(Resource.Id.resert);
resert.Click += delegate
{
ClearOverlay();
InitOverlay();
}; var alphaSeekBar = FindViewById<SeekBar>(Resource.Id.alphaBar);
alphaSeekBar.ProgressChanged += (s, e) =>
{
float alpha = e.Progress / 10.0f;
if (mMarkerA != null) mMarkerA.Alpha = alpha;
if (mMarkerB != null) mMarkerB.Alpha = alpha;
if (mMarkerC != null) mMarkerC.Alpha = alpha;
if (mMarkerD != null) mMarkerD.Alpha = alpha;
}; animationBox = FindViewById<CheckBox>(Resource.Id.animation);
mMapView = FindViewById<TextureMapView>(Resource.Id.bmapView);
mBaiduMap = mMapView.Map;
mBaiduMap.SetMapStatus(MapStatusUpdateFactory.ZoomTo(14.0f));
InitOverlay();
mBaiduMap.MarkerClick += (sender, args) =>
{
Marker marker = args.P0;
Button button = new Button(ApplicationContext);
button.SetTextColor(Color.Black);
button.SetBackgroundResource(Resource.Drawable.popup);
if (marker == mMarkerA || marker == mMarkerD)
{
button.Text = "更改位置";
button.Click += (s, e) =>
{
LatLng latLng = args.P0.Position;
LatLng latLngNew = new LatLng(latLng.Latitude + 0.005,
latLng.Longitude + 0.005);
mBaiduMap.HideInfoWindow();
};
var mInfoWindow = new InfoWindow(button, marker.Position, -);
mBaiduMap.ShowInfoWindow(mInfoWindow);
}
else if (marker == mMarkerB)
{
button.Text = "更改图标";
button.Click += delegate
{
marker.Icon = bd;
mBaiduMap.HideInfoWindow();
};
var mInfoWindow = new InfoWindow(button, marker.Position, -);
mBaiduMap.ShowInfoWindow(mInfoWindow);
}
else if (marker == mMarkerC)
{
button.Text = "删除";
button.Click += delegate
{
marker.Remove();
mBaiduMap.HideInfoWindow();
};
var mInfoWindow = new InfoWindow(button, marker.Position, -);
mBaiduMap.ShowInfoWindow(mInfoWindow);
}
};
} public void InitOverlay()
{
// add marker overlay
LatLng latLngA = new LatLng(39.963175, 116.400244);
LatLng latLngB = new LatLng(39.942821, 116.369199);
LatLng latLngC = new LatLng(39.939723, 116.425541);
LatLng latLngD = new LatLng(39.906965, 116.401394); OverlayOptions ooA = new MarkerOptions()
.InvokePosition(latLngA)
.InvokeIcon(bdA)
.InvokeZIndex()
.Draggable(true);
if (animationBox.Checked)
{
//掉下动画
((MarkerOptions)ooA).InvokeAnimateType(MarkerOptions.MarkerAnimateType.Drop);
}
mMarkerA = (Marker)(mBaiduMap.AddOverlay(ooA)); OverlayOptions ooB = new MarkerOptions()
.InvokePosition(latLngB)
.InvokeIcon(bdB)
.InvokeZIndex();
if (animationBox.Checked)
{
//掉下动画
((MarkerOptions)ooB).InvokeAnimateType(MarkerOptions.MarkerAnimateType.Drop);
}
mMarkerB = (Marker)(mBaiduMap.AddOverlay(ooB)); OverlayOptions ooC = new MarkerOptions()
.InvokePosition(latLngC)
.InvokeIcon(bdC)
.Perspective(false)
.Anchor(0.5f, 0.5f)
.InvokeRotate()
.InvokeZIndex();
if (animationBox.Checked)
{
//生长动画
((MarkerOptions)ooC).InvokeAnimateType(MarkerOptions.MarkerAnimateType.Grow);
}
mMarkerC = (Marker)(mBaiduMap.AddOverlay(ooC)); IList<BitmapDescriptor> giflist = new List<BitmapDescriptor>();
giflist.Add(bdA);
giflist.Add(bdB);
giflist.Add(bdC);
OverlayOptions ooD = new MarkerOptions()
.InvokePosition(latLngD)
.InvokeIcons(giflist)
.InvokeZIndex()
.InvokePeriod();
if (animationBox.Checked)
{
//生长动画
((MarkerOptions)ooD).InvokeAnimateType(MarkerOptions.MarkerAnimateType.Grow);
}
mMarkerD = (Marker)(mBaiduMap.AddOverlay(ooD)); // add ground overlay
LatLng southwest = new LatLng(39.92235, 116.380338);
LatLng northeast = new LatLng(39.947246, 116.414977);
LatLngBounds bounds = new LatLngBounds.Builder()
.Include(northeast)
.Include(southwest).Build();
OverlayOptions ooGround = new GroundOverlayOptions()
.PositionFromBounds(bounds)
.InvokeImage(bdGround)
.InvokeTransparency(0.8f);
mBaiduMap.AddOverlay(ooGround); MapStatusUpdate u = MapStatusUpdateFactory.NewLatLng(bounds.Center);
mBaiduMap.SetMapStatus(u);
mBaiduMap.MarkerDrag += (s, e) => { };
mBaiduMap.MarkerDragStart += (s, e) => { };
mBaiduMap.MarkerDragEnd += (s, e) =>
{
Marker marker = e.P0;
Toast.MakeText(this,
"拖拽结束,新位置:"
+ marker.Position.Latitude + ", "
+ marker.Position.Longitude,
ToastLength.Long).Show();
};
} /// <summary>
/// 清除所有Overlay
/// </summary>
public void ClearOverlay()
{
mBaiduMap.Clear();
mMarkerA = null;
mMarkerB = null;
mMarkerC = null;
mMarkerD = null;
} protected override void OnPause()
{
mMapView.OnPause();
base.OnPause();
} protected override void OnResume()
{
mMapView.OnResume();
base.OnResume();
} protected override void OnDestroy()
{
mMapView.OnDestroy();
base.OnDestroy();
// 回收 bitmap 资源
bdA.Recycle();
bdB.Recycle();
bdC.Recycle();
bdD.Recycle();
bd.Recycle();
bdGround.Recycle();
}
}
}

3、修改MainActivity.cs

在MainActivity.cs文件的demos字段定义中,去掉【示例9】下面的注释。

运行观察结果。

【Android】3.9 覆盖物功能的更多相关文章

  1. Android Webview实现文件下载功能

        在做美图欣赏Android应用的时候,其中有涉及到Android应用下载的功能,这个应用本身其实也比较简单,就是通过WebView控制调用相应的WEB页面进行展示.刚开始以为和普通的文件下载实 ...

  2. I.MX6 android 移除shutdown功能

    /************************************************************************ * I.MX6 android 移除shutdown ...

  3. 你真的有必要退出吗——再说Android程序的退出功能

    转自你真的有必要退出吗--再说Android程序的退出功能 搞Android开发有一段时间了,相信很多从Windows开发过来的Android程序员都习惯性地会跟我一样遇到过同一个问题:如何彻底退出程 ...

  4. 调用Android自带日历功能(日历列表单、添加一个日历事件)

    调用Android自带日历功能  觉得这篇文章不错,转载过来. 转载:http://blog.csdn.net/djy1992/article/details/9948393 Android手机配备有 ...

  5. Android使得手机拍照功能的发展(源共享)

    Android系统调用手机拍照功能有两种方法来直接调用手机自带摄像头还有一个就是要当心自己的节拍. 例Camera360 强大的一个在每个操作系统都有一个手机摄影软件:您可以捕捉不同风格,不同特效的照 ...

  6. Android实现自动更新功能

    Android实现自动更新功能 Android自动更新的功能可以使用第三方的SDK来实现,但是类似友盟,就不支持x86手机的自动更新,科大讯飞,弹窗是全局的,小米手机就会默认把弹窗权限关掉不允许弹出提 ...

  7. Android Camera2 预览功能实现

    1. 概述 最近在做一些关于人脸识别的项目,需要用到 Android 相机的预览功能.网上查阅相关资料后,发现 Android 5.0 及以后的版本中,原有的 Camera API 已经被 Camer ...

  8. [转]Android 代码自动提示功能

    源地址http://blog.sina.com.cn/s/blog_7dbac12501019mbh.html 或者http://blog.csdn.net/longvslove/article/de ...

  9. Android 代码自动提示功能

    Eclipse for android 实现代码自动提示智能提示功能,介绍 Eclipse for android 编辑器中实现两种主要文件 java 与 xml 代码自动提示功能,解决 eclips ...

  10. Android Toast的多功能封装——Android开发之路1

    Android封装实现各种功能的Toast GitHub地址:https://github.com/SibreiaDante/ToastUtils 效果图: 方法封装如下: showSingleton ...

随机推荐

  1. Visual Studio 2008破解90天试用期

    Visual Studio 2008破解90天试用期变成正式版的方法: 第一种方法(安装前用): 把iso文件中的setup文件夹中的setup.sdb文件中的[Product Key]下的一行的原来 ...

  2. 微信小程序 - 生命周期

    生命周期 1.小程序注册完成后,加载页面,触发onLoad方法.(切记,onShow和onLoad的区别,onShow是每当进入这个页面时就会触发,而onload是载入进来时才触发) 2.页面载入后触 ...

  3. vue 子组件引用

    使用 ref 为子组件指定一个引用 ID.例如: <div id="parent"> <user-profile ref="profile"& ...

  4. Codevs3008 加工生产调度

    题目大意:某工厂收到了n个产品的订单,这n个产品分别在A.B两个车间加工,而且必须先在A车间加工后才干够到B车间加工. 求如何安排这n个产品的加工顺序.才干使总的加工时间最短. 这里所说的加工时间是指 ...

  5. How to hide the create button dynamical tree view in openerp ?

    <tree create="false" edit="false" > <tree attrs="{'create':[(" ...

  6. eclipse Java compiler level does not match the version of the installed Java project facet.

      eclipse Java compiler level does not match the version of the installed Java project facet. Create ...

  7. 〖Linux〗Ubuntu 64位安装sqlite3_analyzer

    1. 安装过程 -dev:i386 wget -c "http://www.sqlite.org/2013/sqlite-analyzer-linux-x86-3080200.zip&quo ...

  8. 转载:PHP详解ob_clean,ob_start和ob_get_contents函数

    1.这三个函数运用在PHP4和PHP5中.在一些PHP项目中,经常能看到这三个函数的使用. 有的输出,前面本来要显示在页面里的东西全都被清除了,不显示了. 第二个函数:ob_start(); 告诉ph ...

  9. 微信小程序:酒店订房之时间选择器 picker

    下单页面,选择开始日期和结束日期,不废话,直接代码: 1.wxml: <picker mode="date" value="{{date1}}" star ...

  10. PHP-手册阅读笔记

    1.第一次遇到$_ENV为空数组的情况, 原来是PHP.INI中variables_order为'GPCS'(表示系统在定义PHP预定义变量时的顺序是GET,POST,COOKIES,SERVER,只 ...