Arcgis for android 10.2示例代码之MapRotation

刚刚开始学习Arcgis for android,为了让自己更好的学习、体会,也为了方便大家一起理解Arcgis for android,现在,我把自己的一些学习体会写下来,和大家分享,如果大神们发现有问题的话,欢迎给我指出。

下面是应用 的主要代码,其中Compass的代码在“===”后面,第一次写博客,不大会排版,先就这样看着吧,在以后我会慢慢改进的。

对了,在这之前请先确定你们的电脑上已经安装好了Arcgis 10.2 for android的插件。

public class MyMapDemoActivity extends Activity {
MapView map;
Compass compass;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
map = (MapView) findViewById(R.id.map);
//底图
ArcGISTiledMapServiceLayer baseUrl = new ArcGISTiledMapServiceLayer(
"http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");
map.addLayer(baseUrl);
map.setAllowRotationByPinch(true);//允许地图进行旋转操作

compass=new Compass(this, null);
map.addView(compass);

map.setOnSingleTapListener(new OnSingleTapListener() {
@Override
public void onSingleTap(float x, float y) {
map.setRotationAngle(0);
compass.setRotationAngle(map.getRotationAngle());
compass.postInvalidate();
}
});
map.setOnPinchListener(new OnPinchListener() {
private static final long serialVersionUID = 1L;
@Override
public void prePointersUp(float x1, float y1, float x2, float y2,
double factor) {
map.getRotationAngle();
compass.setRotationAngle(map.getRotationAngle());
compass.postInvalidate();
}
@Override
public void prePointersMove(float x1, float y1, float x2, float y2,
double factor) {
}

@Override
public void prePointersDown(float x1, float y1, float x2, float y2,
double factor) {
}

@Override
public void postPointersUp(float x1, float y1, float x2, float y2,
double factor) {
}

@Override
public void postPointersMove(float x1, float y1, float x2, float y2,
double factor) {
}

@Override
public void postPointersDown(float x1, float y1, float x2, float y2,
double factor) {
}
});
}
}

===========================================================================

public class Compass extends View {
float m_angle = 0;//旋转的角度
Paint paint;
Context m_Context;
ImageButton north ;
Bitmap bitmap ;
/**
* 在代码中新建对象需要使用的构造函数
* @param context 上下文
* @param attrs
*/
public Compass(Context context, AttributeSet attrs) {
super(context, attrs);
paint=new Paint();//画笔
m_Context=context;
north=new ImageButton(m_Context);
}
public void setRotationAngle(double angle){
this.m_angle=(float) angle;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.compass);
Matrix matrix=new Matrix();//矩阵
matrix.postRotate(m_angle,bitmap.getHeight()/2,bitmap.getWidth()/2);
canvas.drawBitmap(bitmap, matrix, paint);
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值