You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 26, 2023. It is now read-only.
The sketch-editor appears to have a bug when dragging previously captured freehand polylines.
Problem summary: When editing an existing (i.e., previously saved) freehand polyline - it is never "dropped" after being dragged.
Problem:
Start the sketch-editor by passing in an existing freehand polyline graphic from the GraphicsOverlay. (mSketchEditor.start(existingFreehandPolygonGraphic.getGeometry(),sketchCreationMode.FREEHAND_LINE)) Tap to select the freehand polyline. Tap and hold to drag it to another location. Lift your finger to stop dragging - the polyline is never "dropped", i.e., it is still in a dragged state (dashed lines).
The code below was based on the sketch-editor example:
packagecom.esri.arcgisruntime.sample.sketcheditor;
importandroid.content.Context;
importandroid.graphics.Color;
importandroid.os.Bundle;
importandroid.support.design.widget.Snackbar;
importandroid.support.v7.app.AppCompatActivity;
importandroid.util.Log;
importandroid.view.Menu;
importandroid.view.MenuInflater;
importandroid.view.MenuItem;
importandroid.view.MotionEvent;
importandroid.widget.ImageButton;
importandroid.widget.TextView;
importcom.esri.arcgisruntime.concurrent.ListenableFuture;
importcom.esri.arcgisruntime.geometry.Geometry;
importcom.esri.arcgisruntime.geometry.GeometryEngine;
importcom.esri.arcgisruntime.geometry.GeometryType;
importcom.esri.arcgisruntime.geometry.Point;
importcom.esri.arcgisruntime.geometry.SpatialReferences;
importcom.esri.arcgisruntime.mapping.ArcGISMap;
importcom.esri.arcgisruntime.mapping.Basemap;
importcom.esri.arcgisruntime.mapping.popup.Popup;
importcom.esri.arcgisruntime.mapping.view.Callout;
importcom.esri.arcgisruntime.mapping.view.DefaultMapViewOnTouchListener;
importcom.esri.arcgisruntime.mapping.view.Graphic;
importcom.esri.arcgisruntime.mapping.view.GraphicsOverlay;
importcom.esri.arcgisruntime.mapping.view.IdentifyGraphicsOverlayResult;
importcom.esri.arcgisruntime.mapping.view.MapView;
importcom.esri.arcgisruntime.mapping.view.SketchCreationMode;
importcom.esri.arcgisruntime.mapping.view.SketchEditConfiguration;
importcom.esri.arcgisruntime.mapping.view.SketchEditor;
importcom.esri.arcgisruntime.mapping.view.SketchGeometryChangedEvent;
importcom.esri.arcgisruntime.mapping.view.SketchGeometryChangedListener;
importcom.esri.arcgisruntime.symbology.SimpleFillSymbol;
importcom.esri.arcgisruntime.symbology.SimpleLineSymbol;
importcom.esri.arcgisruntime.symbology.SimpleMarkerSymbol;
importjava.util.HashMap;
importjava.util.List;
importjava.util.Map;
importjava.util.concurrent.ExecutionException;
publicclassMainActivityextendsAppCompatActivity {
privatefinalStringTAG = MainActivity.class.getSimpleName();
privateSimpleMarkerSymbolmPointSymbol;
privateSimpleLineSymbolmLineSymbol, mLineSymbol2;
privateSimpleFillSymbolmFillSymbol, mFillSymbol2;
privateMapViewmMapView;
privateSketchEditormSketchEditor;
privateGraphicsOverlaymGraphicsOverlay;
privateMenuItemcancel, stop, redo, undo;
privateCalloutmCallout;
privatebooleanbSketchEdit = false;
privateGraphicoriginalGraphic;
privateImageButtonmPointButton;
privateImageButtonmMultiPointButton;
privateImageButtonmPolylineButton;
privateImageButtonmPolygonButton;
privateImageButtonmFreehandLineButton;
privateImageButtonmFreehandPolygonButton;
@OverrideprotectedvoidonCreate(BundlesavedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.setTitle("");
// define symbolsmPointSymbol = newSimpleMarkerSymbol(SimpleMarkerSymbol.Style.SQUARE, Color.RED, 20);
mLineSymbol2 = newSimpleLineSymbol(SimpleLineSymbol.Style.SOLID, 0xFFFF8800, 4);
mLineSymbol = newSimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.MAGENTA, 4, SimpleLineSymbol.MarkerStyle.ARROW, SimpleLineSymbol.MarkerPlacement.END);
mFillSymbol = newSimpleFillSymbol(SimpleFillSymbol.Style.CROSS, Color.CYAN, newSimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.BLUE, 4));
mFillSymbol2 = newSimpleFillSymbol(SimpleFillSymbol.Style.CROSS, Color.GREEN, mLineSymbol2);
// inflate map view from layoutmMapView = findViewById(R.id.mapView);
// create a map with the Basemap Type topographicArcGISMapmap = newArcGISMap(Basemap.Type.LIGHT_GRAY_CANVAS, 34.056295, -117.195800, 16);
// set the map to be displayed in this viewmMapView.setMap(map);
mGraphicsOverlay = newGraphicsOverlay();
mMapView.getGraphicsOverlays().add(mGraphicsOverlay);
mMapView.setOnTouchListener(newMapSingleTapListener(this, mMapView));
// create a new sketch editor and add it to the map viewmSketchEditor = newSketchEditor();
mMapView.setSketchEditor(mSketchEditor);
mSketchEditor.addGeometryChangedListener(newSketchGeometryChangedListener() {
@OverridepublicvoidgeometryChanged(SketchGeometryChangedEventsketchGeometryChangedEvent) {
if (mSketchEditor != null) {
cancel.setEnabled(true);
stop.setEnabled(bSketchEdit || mSketchEditor.isSketchValid()); //TODO better way?undo.setEnabled(mSketchEditor.canUndo());
redo.setEnabled(mSketchEditor.canRedo());
}
}
});
// get buttons from layoutsmPointButton = findViewById(R.id.pointButton);
mMultiPointButton = findViewById(R.id.pointsButton);
mPolylineButton = findViewById(R.id.polylineButton);
mPolygonButton = findViewById(R.id.polygonButton);
mFreehandLineButton = findViewById(R.id.freehandLineButton);
mFreehandPolygonButton = findViewById(R.id.freehandPolygonButton);
// add click listenersmPointButton.setOnClickListener(view -> createModePoint());
mMultiPointButton.setOnClickListener(view -> createModeMultipoint());
mPolylineButton.setOnClickListener(view -> createModePolyline());
mPolygonButton.setOnClickListener(view -> createModePolygon());
mFreehandLineButton.setOnClickListener(view -> createModeFreehandLine());
mFreehandPolygonButton.setOnClickListener(view -> createModeFreehandPolygon());
}
/** * When the point button is clicked, reset other buttons, show the point button as selected, and start point * drawing mode. */privatevoidcreateModePoint() {
resetButtons();
mPointButton.setSelected(true);
mSketchEditor.stop(); // will this fix a bug with changing draw modes w/o stoppingmSketchEditor.start(SketchCreationMode.POINT);
}
/** * When the multipoint button is clicked, reset other buttons, show the multipoint button as selected, and start * multipoint drawing mode. */privatevoidcreateModeMultipoint() {
resetButtons();
mMultiPointButton.setSelected(true);
mSketchEditor.stop(); // will this fix a bug with changing draw modes w/o stoppingmSketchEditor.start(SketchCreationMode.MULTIPOINT);
}
/** * When the polyline button is clicked, reset other buttons, show the polyline button as selected, and start * polyline drawing mode. */privatevoidcreateModePolyline() {
resetButtons();
mPolylineButton.setSelected(true);
mSketchEditor.stop(); // will this fix a bug with changing draw modes w/o stoppingmSketchEditor.start(SketchCreationMode.POLYLINE);
}
/** * When the polygon button is clicked, reset other buttons, show the polygon button as selected, and start polygon * drawing mode. */privatevoidcreateModePolygon() {
resetButtons();
mPolygonButton.setSelected(true);
mSketchEditor.stop(); // will this fix a bug with changing draw modes w/o stoppingmSketchEditor.start(SketchCreationMode.POLYGON);
}
/** * When the freehand line button is clicked, reset other buttons, show the freehand line button as selected, and * start freehand line drawing mode. */privatevoidcreateModeFreehandLine() {
resetButtons();
mFreehandLineButton.setSelected(true);
mSketchEditor.stop(); // will this fix a bug with changing draw modes w/o stoppingmSketchEditor.start(SketchCreationMode.FREEHAND_LINE);
}
/** * When the freehand polygon button is clicked, reset other buttons, show the freehand polygon button as selected, * and enable freehand polygon drawing mode. */privatevoidcreateModeFreehandPolygon() {
resetButtons();
mFreehandPolygonButton.setSelected(true);
mSketchEditor.stop(); // will this fix a bug with changing draw modes w/o stoppingmSketchEditor.start(SketchCreationMode.FREEHAND_POLYGON);
}
/** * When the undo button is clicked, undo the last event on the SketchEditor. */privatevoidundo() {
if (mSketchEditor.canUndo()) {
mSketchEditor.undo();
}
}
/** * When the redo button is clicked, redo the last undone event on the SketchEditor. */privatevoidredo() {
if (mSketchEditor.canRedo()) {
mSketchEditor.redo();
}
}
/** * When the stop button is clicked, check that sketch is valid. If so, get the geometry from the sketch, set its * symbol and add it to the graphics overlay. */privatevoidstop() {
bSketchEdit = false;
originalGraphic = null;
if (!mSketchEditor.isSketchValid()) {
reportNotValid();
mSketchEditor.stop();
resetButtons();
disableMenuOptions();
return;
}
// get the geometry from sketch editorGeometrysketchGeometry = mSketchEditor.getGeometry();
// mSketchEditor.stop();// resetButtons();if (sketchGeometry != null) {
// create a graphic from the sketch editor geometryMap<String, Object> mapAttributes = newHashMap<String, Object>();
mapAttributes.put("GeometryType", sketchGeometry.getGeometryType().name());
mapAttributes.put("SketchCreationMode", mSketchEditor.getSketchCreationMode().name());
Graphicgraphic = newGraphic(sketchGeometry, mapAttributes);
// assign a symbol based on geometry typeif (graphic.getGeometry().getGeometryType() == GeometryType.POLYGON) {
graphic.setSymbol(mFillSymbol);
} elseif (graphic.getGeometry().getGeometryType() == GeometryType.POLYGON
&& mSketchEditor.getSketchCreationMode().equals(SketchCreationMode.FREEHAND_POLYGON)) {
graphic.setSymbol(mFillSymbol2);
} elseif (graphic.getGeometry().getGeometryType() == GeometryType.POLYLINE
&& mSketchEditor.getSketchCreationMode().equals(SketchCreationMode.FREEHAND_LINE)) {
graphic.setSymbol(mLineSymbol2);
} elseif (graphic.getGeometry().getGeometryType() == GeometryType.POLYLINE) {
graphic.setSymbol(mLineSymbol);
} elseif (graphic.getGeometry().getGeometryType() == GeometryType.POINT ||
graphic.getGeometry().getGeometryType() == GeometryType.MULTIPOINT) {
graphic.setSymbol(mPointSymbol);
}
// add the graphic to the graphics overlaymGraphicsOverlay.getGraphics().add(graphic);
}
mSketchEditor.stop();
resetButtons();
disableMenuOptions();
}
/** * When the cancel button is clicked, cancel the SketchEditor. */privatevoidcancel() {
mSketchEditor.stop();
resetButtons();
if (bSketchEdit) {
// add the graphic to the graphics overlaymGraphicsOverlay.getGraphics().add(originalGraphic);
originalGraphic = null;
}
bSketchEdit = false;
disableMenuOptions();
}
/** * Called if sketch is invalid. Reports to user why the sketch was invalid. */privatevoidreportNotValid() {
StringvalidIf;
if (mSketchEditor.getSketchCreationMode() == SketchCreationMode.POINT) {
validIf = "Point only valid if it contains an x & y coordinate.";
} elseif (mSketchEditor.getSketchCreationMode() == SketchCreationMode.MULTIPOINT) {
validIf = "Multipoint only valid if it contains at least one vertex.";
} elseif (mSketchEditor.getSketchCreationMode() == SketchCreationMode.POLYLINE
|| mSketchEditor.getSketchCreationMode() == SketchCreationMode.FREEHAND_LINE) {
validIf = "Polyline only valid if it contains at least one part of 2 or more vertices.";
} elseif (mSketchEditor.getSketchCreationMode() == SketchCreationMode.POLYGON
|| mSketchEditor.getSketchCreationMode() == SketchCreationMode.FREEHAND_POLYGON) {
validIf = "Polygon only valid if it contains at least one part of 3 or more vertices which form a closed ring.";
} else {
validIf = "No sketch creation mode selected.";
}
Stringreport = "Sketch geometry invalid:\n" + validIf;
SnackbarreportSnackbar = Snackbar.make(findViewById(R.id.toolbarInclude), report, Snackbar.LENGTH_INDEFINITE);
reportSnackbar.setAction("Dismiss", view -> reportSnackbar.dismiss());
TextViewsnackbarTextView = reportSnackbar.getView().findViewById(android.support.design.R.id.snackbar_text);
snackbarTextView.setSingleLine(false);
reportSnackbar.show();
Log.e(TAG, report);
}
/** * De-selects all buttons. */privatevoidresetButtons() {
mPointButton.setSelected(false);
mMultiPointButton.setSelected(false);
mPolylineButton.setSelected(false);
mPolygonButton.setSelected(false);
mFreehandLineButton.setSelected(false);
mFreehandPolygonButton.setSelected(false);
}
/** * Disable menu options */privatevoiddisableMenuOptions() {
this.cancel.setEnabled(false);
if (bSketchEdit) {
this.stop.setEnabled(true); //TODO maybe do nothing here?
} else {
this.stop.setEnabled(false);
}
this.undo.setEnabled(false);
this.redo.setEnabled(false);
}
@OverridepublicbooleanonCreateOptionsMenu(Menumenu) {
MenuInflaterinflater = getMenuInflater();
inflater.inflate(R.menu.undo_redo_stop_menu, menu);
this.cancel = menu.findItem(R.id.cancel);
this.stop = menu.findItem(R.id.stop);
this.undo = menu.findItem(R.id.undo);
this.redo = menu.findItem(R.id.redo);
disableMenuOptions();
returnsuper.onCreateOptionsMenu(menu);
}
@OverridepublicbooleanonOptionsItemSelected(MenuItemitem) {
intid = item.getItemId();
if (id == R.id.undo) {
undo();
} elseif (id == R.id.redo) {
redo();
} elseif (id == R.id.stop) {
stop();
} elseif (id == R.id.cancel) {
cancel();
}
returnsuper.onOptionsItemSelected(item);
}
@OverrideprotectedvoidonPause() {
mMapView.pause();
super.onPause();
}
@OverrideprotectedvoidonResume() {
super.onResume();
mMapView.resume();
}
@OverrideprotectedvoidonDestroy() {
super.onDestroy();
mMapView.dispose();
}
classMapSingleTapListenerextendsDefaultMapViewOnTouchListener {
publicMapSingleTapListener(Contextcontext, MapViewmapView) {
super(context, mapView);
}
@OverridepublicbooleanonSingleTapConfirmed(MotionEvente) {
// get the screen point where user tappedandroid.graphics.PointscreenPoint = newandroid.graphics.Point((int) e.getX(), (int) e.getY());
finalPointmapPoint = mMapView.screenToLocation(screenPoint);
// convert to WGS84 for lat/lon formatfinalPointwgs84Point = (Point) GeometryEngine.project(mapPoint, SpatialReferences.getWgs84());
Log.d(TAG, String.format("Lat: %.6f, Lon: %.6f)", wgs84Point.getY(), wgs84Point.getX()));
// create a selection toleranceinttolerance = 10;
doublemapTolerance = tolerance * mMapView.getUnitsPerDensityIndependentPixel();
// identify graphics on the graphics overlayfinalListenableFuture<IdentifyGraphicsOverlayResult> identifyGraphic = mMapView.identifyGraphicsOverlayAsync(mGraphicsOverlay, screenPoint, tolerance, false, 4);
identifyGraphic.addDoneListener(newRunnable() {
@Overridepublicvoidrun() {
try {
IdentifyGraphicsOverlayResultgrOverlayResult = identifyGraphic.get();
List<Popup> popup = grOverlayResult.getPopups();
// get the list of graphics returned by identify graphic overlayList<Graphic> graphic = grOverlayResult.getGraphics();
// get size of list in resultsintidentifyResultSize = graphic.size();
Stringmessage = "Tapped on " + identifyResultSize + " graphic%1$s";
if (!graphic.isEmpty()) { // show a toast message if graphic was returnedmessage = String.format(message, (identifyResultSize == 1 ? "" : "s"));
Log.d(TAG, message);
inti = 0;
for (Graphicgr : graphic) {
// Log.d(TAG, "(" + (i + 1) + ") " + gr.getGeometry().toJson());// message += "\n(" + (i + 1) + "): " + gr.getAttributes().get("name").toString();for (Map.Entry<String, Object> entry : gr.getAttributes().entrySet()) {
message += "\n(" + (i + 1) + ") " + entry.getKey() + " = " + entry.getValue().toString();
}
i++;
// Log.d(TAG, message);
}
// For now, just work with 1st Graphic object...originalGraphic = graphic.get(0);
Map<String, Object> mapAttributes = originalGraphic.getAttributes();
if (mapAttributes != null && mapAttributes.containsKey("GeometryType") && mapAttributes.containsKey("SketchCreationMode")) {
Log.d(TAG, "GeometryType: " + mapAttributes.get("GeometryType").toString());
Log.d(TAG, "SketchCreationMode: " + mapAttributes.get("SketchCreationMode").toString());
GeometryTypegeometryType = GeometryType.valueOf(mapAttributes.get("GeometryType").toString());
SketchCreationModesketchCreationMode = SketchCreationMode.valueOf(mapAttributes.get("sketchCreationMode").toString());
if (sketchCreationMode.equals(SketchCreationMode.POINT)) {
mPointButton.setSelected(true);
} elseif (sketchCreationMode.equals(SketchCreationMode.MULTIPOINT)) {
mMultiPointButton.setSelected(true);
} elseif (sketchCreationMode.equals(SketchCreationMode.POLYLINE)) {
mPolylineButton.setSelected(true);
} elseif (sketchCreationMode.equals(SketchCreationMode.POLYGON)) {
mPolygonButton.setSelected(true);
} elseif (sketchCreationMode.equals(SketchCreationMode.FREEHAND_LINE)) {
mFreehandLineButton.setSelected(true);
} elseif (sketchCreationMode.equals(SketchCreationMode.FREEHAND_POLYGON)) {
mFreehandPolygonButton.setSelected(true);
}
SketchEditConfigurationsketchEditConfiguration = newSketchEditConfiguration();
mSketchEditor.start(originalGraphic.getGeometry(), sketchCreationMode, sketchEditConfiguration);
// mSketchEditor.start(originalGraphic.getGeometry(), sketchCreationMode);// mSketchEditor.start(originalGraphic.getGeometry());mGraphicsOverlay.getGraphics().remove(originalGraphic);
bSketchEdit = true;
}
}
} catch (InterruptedException | ExecutionExceptionie) {
ie.printStackTrace();
}
}
});
returnsuper.onSingleTapConfirmed(e);
}
}
}
The text was updated successfully, but these errors were encountered:
celoftis
changed the title
sketch-editor, drag freehand polygon, no drop...
sketch-editor, drag freehand polyline, no drop...
Sep 15, 2018
The sketch-editor appears to have a bug when dragging previously captured freehand polylines.
Problem summary: When editing an existing (i.e., previously saved) freehand polyline - it is never "dropped" after being dragged.
Problem:
Start the sketch-editor by passing in an existing freehand polyline graphic from the GraphicsOverlay. (
mSketchEditor.start(existingFreehandPolygonGraphic.getGeometry(),sketchCreationMode.FREEHAND_LINE)
) Tap to select the freehand polyline. Tap and hold to drag it to another location. Lift your finger to stop dragging - the polyline is never "dropped", i.e., it is still in a dragged state (dashed lines).The code below was based on the sketch-editor example:
The text was updated successfully, but these errors were encountered: