Select to view content in your preferred language

SketchEdit not work with Magnifier in draw new Graphic?

807
5
07-14-2019 09:41 PM
PhamTheVinh
Emerging Contributor

Cannot add new vertex when draw new graphic with Magnifier. Without Magnifier everything is fine. We test on 100.5. Please help.

0 Kudos
5 Replies
ChanganShi
Esri Contributor

Currently, SketchEdtior doesn't work with the magnifier seamlessly.  By default, when the magnifier is released up, it doesn't do anything.

There is a workaround for your consideration : 

1. The workflow is to create a new inner TouchListener class to the class where your MapView resides, swap the default sketch touch listener when you want to enable the magnifier to add a vertex when it is released, and swap back the original sketch touch listener. The like this : 

private DefaultMapViewOnTouchListener mSketchEventListenerRestore;
private AddVertexMagnifierListener mAddVertexMagnifierListener;


class
AddVertexMagnifierListener extends DefaultMapViewOnTouchListener {

/**
* Constructs a DefaultMapViewOnTouchListener with the given Context and MapView.
*
* @param context the context from which this is being created
* @param mapView the MapView with which to interact
* @since 100.0.0
*/
public AddVertexMagnifierListener(Context context, MapView mapView) {
super(context, mapView);
}

@Override public boolean onUp(MotionEvent e) {
boolean ret = super.onUp(e);
//Check condition to add a vertex when the magnifier is up.
boolean isStarted = mMapView.isMagnifierEnabled(); //&& SketchEditor is started
if (isStarted) {
Point point = mMapView.screenToLocation(new android.graphics.Point((int)e.getX(), (int)e.getY()));
mSketchEditor.insertVertexAfterSelectedVertex(point);
}
return ret;
}
}

2. When you start the SketchEditor, save the default the listener, 

mSketchEditor.start(SketchCreationMode.POLYGON, mSketchEditor.getSketchEditConfiguration());
//save the default sketch listener
sketchEventListenerRestore = (DefaultMapViewOnTouchListener) mMapView.getOnTouchListener();


3. When you enable the magnifier,  use the new touch listener or use the original one.

/**
 * Toggles showing the magnifier
 */
private void toggleMagnifier() {
  mMapView.setMagnifierEnabled(!mMapView.isMagnifierEnabled());

  if (mMapView.isMagnifierEnabled()) {
    if (mAddVertexMagnifierListener == null) {
      mAddVertexMagnifierListener = new AddVertexMagnifierListener(this, mMapView);
    }
    mMapView.setOnTouchListener(mAddVertexMagnifierListener);
  } else {
    mMapView.setOnTouchListener(mSketchEventListenerRestore);
  }

  Toast.makeText(this, "Magnifier="+mMapView.isMagnifierEnabled(), Toast.LENGTH_LONG).show();
}

Hope this is helpful to you.

We may consider making the magnifier work closely with SketchEditor in the future release. 

0 Kudos
PhamTheVinh
Emerging Contributor

Dear Changan Shi!

Thanks for your quick reply but I still cannot work workaround this error because when call 

SketchEditor.start

The override function onUp of DefaultMapViewOnTouchListener is not called. (So I cannot handler the onUp event)

Please help!

0 Kudos
ChanganShi
Esri Contributor

Look at the branch https://github.com/Esri/arcgis-runtime-samples-android/tree/cs/sketch_editor_magnifier_work_around,

Go to sketch-editor sample,  which illustrates the workaround in the main activity.  There is a button in the MapView to allow to enable magnifier during sketching. When the release is up, the magnifier will add a sketch vertex.

0 Kudos
PhamTheVinh
Emerging Contributor

Dear Changan Shi

Thanks for you support, but the Add feature by SketchEditor with Magnifier not working properly. user can add vertex with Magnifier but user cannot modify vertex (cannot select vertex to move). Please help! 

0 Kudos
ChanganShi
Esri Contributor

Could you try this, after a vertex is inserted, switch back to use original gesture listener.

@Override public boolean onUp(MotionEvent e) {
boolean ret = super.onUp(e);
//Check any other condition to add a vertex when the magnifier is up.
boolean isStarted = mMapView.isMagnifierEnabled(); //&& SketchEditor is started
if (isStarted) {
Point point = mMapView.screenToLocation(new android.graphics.Point((int)e.getX(), (int)e.getY()));

mSketchEditor.insertVertexAfterSelectedVertex(point);

if (mSketchEventListenerRestore != null) {
mMapView.setOnTouchListener(mSketchEventListenerRestore);
}
}
return ret;
}
0 Kudos