Closed ZhouKanZ closed 6 years ago
Too much code :) What are you trying to achieve and what is not working for you?
I see you are using standalone GestureController
instance, so basically you are implementing custom view so please check wiki on how to deal with it.
Also your applyState()
method is empty, you need to apply current state to you map somehow, otherwise it definitely won't work. Not sure what you want to achieve though, so can't really suggest anything.
:) I thought I didn't need to operate matrix,I will try it again .
The MapView is just like ImageView with scaleType = center_inside; and draw POI and path on the Bitmap of map;I operated on the canvas in order to implement this feature (center_inside);I almost finished, but there are some problems:
the key code as following:
I hope these can be expressed clearly !
The first question is: rotation center is (0,0) at upper left corner, however I want the bitmap to rotate around the physical center.
The second is: I tried to set diablebound, but the image can still be zoomed to extreme detail and swapped out of screen, too free. I want to restrict the user operation on the image.
The last question is: I want to listen the click event of poi (point of interest) on the bitmap, and because of matrix transformation, I don't know how to match user click point and the exact original point on map
Few notes:
setViewport()
and setImage()
as described in wiki. If the lib will not know these sizes it can easily lead to your rotation issue.GestureFrameLayout
as a parent of your view to not deal with matrixes yourself.matrix.invert(matrixInverse)
) and then map a point with:
tmpPointArray[0] = event.getX();
tmpPointArray[1] = event.getY();
matrix.mapPoints(tmpPointArray);
You can check how it works in GestureFrameLayout sources.
Note, that if you'll use GestureFrameLayout
and regular Android views as your pins then you can just listen for those views' on-click events.
thanks ! follow u suggestion i finished this view . hah
I regret to close this issue , Now have another question , Click Event have been triggered many times,When clicked once .
@Override
public boolean onTouch(View v, MotionEvent event) {
float[] point = new float[2];
point[0] = event.getX();
point[1] = event.getY();
index = -1;
Log.d(TAG, "onTouchEvent: origin point :x" + point[0] + ",y:" + point[1]);
changeMatrix.invert(matrix);
matrix.mapPoints(point, new float[]{point[0], point[1]});
Log.d(TAG, "onTouchEvent: transfrom point:x" + point[0] + ",y:" + point[1]);
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
startClickTime = Calendar.getInstance().getTimeInMillis();
break;
case MotionEvent.ACTION_UP:
clickEvent(point);
break;
case MotionEvent.ACTION_CANCEL:
break;
case MotionEvent.ACTION_MOVE:
break;
}
return controller.onTouch(this, event);
}
private void clickEvent(float[] point) {
long clickDuration = Calendar.getInstance().getTimeInMillis() - startClickTime;
if (clickDuration < MAX_CLICK_DURATION && onClickListener != null) {
Observable.fromIterable(points)
.filter(rectF -> rectF.contains(point[0], point[1]))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(rectF -> {
Log.d(TAG, "onTouchEvent: xxxxx");
onClickListener.onPointClick(testPOIS.get(0), index);
}
, t -> {
}
);
}
}
private void applyState(State state) {
state.get(changeMatrix);
invalidate();
}
Your click implementation is not implemented correctly, simply waiting for ACTION_UP will not work.
You should try using OnGestureListener
as described in usage wiki.
thank u ! Harassing for a long time .
@ZhouKanZ Is this issue solved for you?
it had been solved,tks !
how can i make surfaceView have the same function?
I have write a MapView with surfaceView ,then i wish it can be operated as well as GestureImageView,But it can't work. I hope to get your suggestion ,the following is my code:
package com.jms.cleanse.widget;
import android.annotation.SuppressLint; import android.content.Context; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; import android.graphics.PixelFormat; import android.graphics.RectF; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; import android.util.AttributeSet; import android.util.Log; import android.view.MotionEvent; import android.view.SurfaceHolder; import android.view.SurfaceView;
import com.alexvasilkov.gestures.GestureController; import com.alexvasilkov.gestures.State; import com.alexvasilkov.gestures.views.interfaces.GestureView; import com.jms.cleanse.widget.mapview.POIConfig; import com.jms.cleanse.widget.mapview.ScaleUtils; import com.jms.cleanse.widget.mapview.TestPOI;
import java.util.ArrayList; import java.util.LinkedList; import java.util.List;
/**
public class JMMapView extends SurfaceView implements SurfaceHolder.Callback, Runnable,GestureView {
// this.setSurfaceTextureListener(this);
// canvas.drawBitmap(pathStartRes,null,getBitmapRectF(poiPoint.getAx(),poiPoint.getAy(),pathStartRes),mPaint); canvas.drawBitmap(pathStartRes, (float) (poiPoint.getAx() - pathStartRes.getWidth() / 2), (float) (poiPoint.getAy() - pathStartRes.getHeight()), mPaint); // canvas.drawRect(getBitmapRectF(poiPoint.getAx(),poiPoint.getAy(),pathEndRes),mPaint); } else if (i > 0 && i == testPOIS.size() - 1) { // canvas.drawBitmap(pathStartRes,null,getBitmapRectF(poiPoint.getAx(),poiPoint.getAy(),pathStartRes),mPaint); // mPaint.setColor(Color.BLUE); // canvas.drawRect(getBitmapRectF(poiPoint.getAx(),poiPoint.getAy(),pathEndRes),mPaint); canvas.drawBitmap(pathEndRes, (float) (poiPoint.getAx() - pathEndRes.getWidth() / 2), (float) (poiPoint.getAy() - pathEndRes.getHeight()), mPaint); } }
}