如何在按下清除按钮时禁用 google 地图上的自由手绘
how to disable free hand drawing on google map when clear button is pressed
我正在处理需要在 google 上添加自由手绘的项目 map.I 已在 google 地图上成功绘制。但我的问题是,当我点击清除按钮时,它删除了我在地图上绘制的所有内容,但我没有禁用编辑模式,这意味着当我再次触摸屏幕时它又开始绘制。
我希望当我点击清除按钮时,它会清除所有内容,并且地图会像以前一样处于初始模式。
这里有一些截图
1.this screenshot after clicking clear button and still i am able to draw on map
这里有一些相关代码...
这是我的地图activity
private void drawOnMap() {
mcontent = (FrameLayout) findViewById(signature);
save_button = (ImageButton) findViewById(R.id.save_button);
save_button.setEnabled(false);
exit_edit_mode = (ImageButton) findViewById(R.id.exit_edit_mode);
mSignature = new signature(this, null);
mcontent.addView(mSignature);
save_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mSignature.save();
}
});
exit_edit_mode.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mSignature.clear();
mGoogleMap.getUiSettings().setScrollGesturesEnabled(true);
}
});
这是我在 google 地图上绘制的 class
public class signature extends View {
static final float STROKE_WIDTH = 10f;
static final float HALF_STROKE_WIDTH = STROKE_WIDTH / 2;
Paint paint = new Paint();
Path path = new Path();
float lastTouchX;
float lastTouchY;
final RectF dirtyRect = new RectF();
public signature(Context context, AttributeSet attrs) {
super(context, attrs);
paint.setAntiAlias(true);
paint.setColor(Color.GREEN);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeWidth(STROKE_WIDTH);
}
public void clear() {
path.reset();
invalidate();
save_button.setEnabled(false);
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
canvas.drawPath(path, paint);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
float eventX = event.getX();
float eventY = event.getY();
//save.setEnabled(true);
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
path.moveTo(eventX, eventY);
lastTouchX = eventX;
lastTouchY = eventY;
return true;
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_UP:
resetDirtyRect(eventX, eventY);
int historySize = event.getHistorySize();
for (int i = 0; i < historySize; i++) {
float historicalX = event.getHistoricalX(i);
float historicalY = event.getHistoricalY(i);
path.lineTo(historicalX, historicalY);
}
path.lineTo(eventX, eventY);
break;
}
invalidate((int) (dirtyRect.left - HALF_STROKE_WIDTH),
(int) (dirtyRect.top - HALF_STROKE_WIDTH),
(int) (dirtyRect.right + HALF_STROKE_WIDTH),
(int) (dirtyRect.bottom + HALF_STROKE_WIDTH));
lastTouchX = eventX;
lastTouchY = eventY;
return true;
}
private void resetDirtyRect(float eventX, float eventY) {
dirtyRect.left = Math.min(lastTouchX, eventX);
dirtyRect.right = Math.max(lastTouchX, eventX);
dirtyRect.top = Math.min(lastTouchY, eventY);
dirtyRect.bottom = Math.max(lastTouchY, eventY);
}
}
提前致谢
我自己弄的
在
之后添加此代码
msignature.clear()
mcontent.removeView(mSignature);
我正在处理需要在 google 上添加自由手绘的项目 map.I 已在 google 地图上成功绘制。但我的问题是,当我点击清除按钮时,它删除了我在地图上绘制的所有内容,但我没有禁用编辑模式,这意味着当我再次触摸屏幕时它又开始绘制。
我希望当我点击清除按钮时,它会清除所有内容,并且地图会像以前一样处于初始模式。
这里有一些截图
1.this screenshot after clicking clear button and still i am able to draw on map
这里有一些相关代码...
这是我的地图activity
private void drawOnMap() {
mcontent = (FrameLayout) findViewById(signature);
save_button = (ImageButton) findViewById(R.id.save_button);
save_button.setEnabled(false);
exit_edit_mode = (ImageButton) findViewById(R.id.exit_edit_mode);
mSignature = new signature(this, null);
mcontent.addView(mSignature);
save_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mSignature.save();
}
});
exit_edit_mode.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mSignature.clear();
mGoogleMap.getUiSettings().setScrollGesturesEnabled(true);
}
});
这是我在 google 地图上绘制的 class
public class signature extends View {
static final float STROKE_WIDTH = 10f;
static final float HALF_STROKE_WIDTH = STROKE_WIDTH / 2;
Paint paint = new Paint();
Path path = new Path();
float lastTouchX;
float lastTouchY;
final RectF dirtyRect = new RectF();
public signature(Context context, AttributeSet attrs) {
super(context, attrs);
paint.setAntiAlias(true);
paint.setColor(Color.GREEN);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeWidth(STROKE_WIDTH);
}
public void clear() {
path.reset();
invalidate();
save_button.setEnabled(false);
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
canvas.drawPath(path, paint);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
float eventX = event.getX();
float eventY = event.getY();
//save.setEnabled(true);
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
path.moveTo(eventX, eventY);
lastTouchX = eventX;
lastTouchY = eventY;
return true;
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_UP:
resetDirtyRect(eventX, eventY);
int historySize = event.getHistorySize();
for (int i = 0; i < historySize; i++) {
float historicalX = event.getHistoricalX(i);
float historicalY = event.getHistoricalY(i);
path.lineTo(historicalX, historicalY);
}
path.lineTo(eventX, eventY);
break;
}
invalidate((int) (dirtyRect.left - HALF_STROKE_WIDTH),
(int) (dirtyRect.top - HALF_STROKE_WIDTH),
(int) (dirtyRect.right + HALF_STROKE_WIDTH),
(int) (dirtyRect.bottom + HALF_STROKE_WIDTH));
lastTouchX = eventX;
lastTouchY = eventY;
return true;
}
private void resetDirtyRect(float eventX, float eventY) {
dirtyRect.left = Math.min(lastTouchX, eventX);
dirtyRect.right = Math.max(lastTouchX, eventX);
dirtyRect.top = Math.min(lastTouchY, eventY);
dirtyRect.bottom = Math.max(lastTouchY, eventY);
}
}
提前致谢
我自己弄的 在
之后添加此代码msignature.clear()
mcontent.removeView(mSignature);