问题:1:仅定位后显示当前位置的图标如,在此基础上添加动态图层以开发查询功能,结果是实时定位能实现,查询功能正常,仅上图位置图标不显示。
2:在单独实现定位功能时,手机转动上图标“圆”随之转动,三角形不动,如何改成三角形转动,而圆圈不动?
本人代码:
mMapControl.getMap().refresh();
mDynView = new DynamicView(context, mMapControl.getMap());
mView = new CompassView(this);
mapView.addDynamicView(mDynView);
mapView.addView(mView);
mGesture = new Gesture(mapView,mDynView);
mPopup = new QueryResultPopup(mapView,mDynView);
mMapControl.getMap().refresh();
mGesture.setSearchAroundListener(new SearchAroundListener() {
public void searchGeometry(Geometry geoRegion) {
query(geoRegion, DatasetType.POINT);
}
});
CompassView.java:
package com.example.supermarket;
import java.io.InputStream;
import com.supermap.data.Point;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.BitmapFactory.Options;
import android.util.AttributeSet;
import android.view.View;
public class CompassView extends View {
private Bitmap[] mBitmapArray = new Bitmap[4];
InputStream is;
private float[] mValues;
int[] mBitmapWidth = new int[4];
int[] mBitmapHeight = new int[4];
public Point point;
public Point getPoint() {
return point;
}
public void setPoint(Point point) {
this.point = point;
}
public CompassView(Context context) {
this(context, null);
// TODO Auto-generated constructor stub
}
public CompassView(Context context, AttributeSet attrs) {
super(context, attrs);
BitmapFactory.Options opts = new Options();
opts.inJustDecodeBounds = false;
setBitMapArray(context, 0, opts, R.drawable.panel);
setBitMapArray(context, 1, opts, R.drawable.daohang);
}
/**
* 设置bitmap数组个下标的值
*
* @param index
* @param opts
* @param resid
*/
private void setBitMapArray(Context context, int index,
BitmapFactory.Options opts, int resid) {
is = context.getResources().openRawResource(resid);
mBitmapArray[index] = BitmapFactory.decodeStream(is);
mBitmapWidth[index] = mBitmapArray[index].getWidth();
mBitmapHeight[index] = mBitmapArray[index].getHeight();
mBitmapArray[index + 2] = BitmapFactory.decodeStream(is, null, opts);
mBitmapHeight[index + 2] = mBitmapArray[index + 2].getHeight();
mBitmapWidth[index + 2] = mBitmapArray[index + 2].getWidth();
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
Paint paint = new Paint();
paint.setAntiAlias(true);
int w = canvas.getWidth();
int h = canvas.getHeight();
int cx;
int cy;
if(point !=null){
cx = point.getX();
cy = point.getY();
}else
{
cx=w/2;
cy=h/2;
}
canvas.translate(cx, cy);
drawPictures(canvas, 0);
}
private void drawPictures(Canvas canvas, int idDelta) {
if (mValues != null) {
// Log.d(TAG, "mValues[0] = "+ mValues[0]);
canvas.rotate(-mValues[0]);
canvas.drawBitmap(mBitmapArray[0 + idDelta],
-mBitmapWidth[0 + idDelta] / 2,
-mBitmapHeight[0 + idDelta] / 2, null);
canvas.rotate(360 + mValues[0]);
canvas.drawBitmap(mBitmapArray[1 + idDelta],
-mBitmapWidth[1 + idDelta] / 2,
-mBitmapHeight[1 + idDelta] / 2, null);
} else {
canvas.drawBitmap(mBitmapArray[0 + idDelta],
-mBitmapWidth[0 + idDelta] / 2,
-mBitmapHeight[0 + idDelta] / 2, null);
canvas.drawBitmap(mBitmapArray[1 + idDelta],
-mBitmapWidth[1 + idDelta] / 2,
-mBitmapHeight[1 + idDelta] / 2, null);
}
}
public void setValue(float[] value) {
this.mValues = value;
}
}
本人参考的源码(查询)
源码(定位)
望大神指导一二!