Delete some scene image

752
1
Jump to solution
08-30-2021 02:47 AM
VanyaIvanov
Occasional Contributor

I want to delete any scene image by clicking on it or nearby. How can i do it?

For example i have a method for adding an image to the Scene

public void AddImage(String imgPath, double longitude, double latitude) {
GraphicsOverlay graphicsOverlay = new GraphicsOverlay();
sceneView.getGraphicsOverlays().add(graphicsOverlay);

PictureMarkerSymbol markerSymbol = new PictureMarkerSymbol(imgPath);

markerSymbol.setHeight(20);
markerSymbol.setWidth(20);

markerSymbol.loadAsync();

markerSymbol.addDoneLoadingListener(() -> {
if (markerSymbol.getLoadStatus() == com.esri.arcgisruntime.loadable.LoadStatus.LOADED) {
com.esri.arcgisruntime.geometry.Point symbolPoint = new com.esri.arcgisruntime.geometry.Point(longitude, latitude, SpatialReferences.getWgs84());
Graphic symbolGraphic = new Graphic(symbolPoint, markerSymbol);
graphicsOverlay.getGraphics().add(symbolGraphic);
sceneView.getGraphicsOverlays().add(graphicsOverlay);

} else {
System.out.println("Failed to load: " + markerSymbol.getLoadError().getCause());
}
});
}

Also i want to have a method to delete image from the Scene by clicking button Delete and clicking on that image icon on the Scene after that. 

public void DeleteBtn_Click(javafx.event.ActionEvent actionEvent) {
sceneView.setInteractionListener(new SceneView.DefaultInteractionListener(sceneView) {
public void onMousePressed(javafx.scene.input.MouseEvent e) {
javafx.geometry.Point2D screenPoint = new javafx.geometry.Point2D(Math.round(e.getX()),
Math.round(e.getY()));
DeleteImage(screenPoint);///so i need a method that get screenPoint and deletes an image near the screenPoint coordinates
}
});

}

So i need a method that gets javafx.geometry.Point2D point and deletes an image located near the coordinates of this point. I didnt find any java arcgis api functions suitable for this.

 

 
 
0 Kudos
1 Solution

Accepted Solutions
VanyaIvanov
Occasional Contributor

Im my case i used delete button on the interface

boolean isDeleteElement = false;
@FXML
private void DeleteElementbyClick()
{
if(isDeleteElement ==true)
{
isDeleteElement = false;
}
else {
isDeleteElement = true;
}
}


//And i used the mouse handler for deleting clicked object from the scene
sceneView.setInteractionListener(new SceneView.DefaultInteractionListener(sceneView)
{

public void onMousePressed(javafx.scene.input.MouseEvent e)
{

if(e.getButton() == MouseButton.PRIMARY) {


if(isDeleteElement ==true)
{
javafx.geometry.Point2D screenPoint = new javafx.geometry.Point2D(Math.round(e.getX()),
Math.round(e.getY()));
com.esri.arcgisruntime.geometry.Point surfacePoint = sceneView.screenToBaseSurface(screenPoint);


// identify graphics on the graphics overlay
identifyGraphics = sceneView.identifyGraphicsOverlayAsync(graphicsOverlay, screenPoint, 10, false);
identifyGraphics.addDoneListener(() -> {

try {
// get the list of graphics returned by identify
IdentifyGraphicsOverlayResult result = identifyGraphics.get();
List<Graphic> graphics = result.getGraphics();

if (!graphics.isEmpty()) {

for(int i = 0; i<graphics.size(); i++) {

if(myGraphics.contains(graphics.get(i))) {
for (int j = 0; j < myGraphics.size(); j++)
graphicsOverlay.getGraphics().remove(myGraphics.get(j));
myGraphics.clear();
}
else {
graphicsOverlay.getGraphics().remove(graphics.get(i));//just delete a part of the complex graphic object you clicked on by mouse
}

}
}
}
catch (Exception ex) {
ex.printStackTrace();
}
});
}
}
else {
// let the default listener you've overridden deal with other events
super.onMousePressed(e);
}
}

myGraphic is an ArrayList<Graphic> that contains all graphic elements of some graphical object you want to delete(for example trapezium that consists of 4 lines).

 

View solution in original post

0 Kudos
1 Reply
VanyaIvanov
Occasional Contributor

Im my case i used delete button on the interface

boolean isDeleteElement = false;
@FXML
private void DeleteElementbyClick()
{
if(isDeleteElement ==true)
{
isDeleteElement = false;
}
else {
isDeleteElement = true;
}
}


//And i used the mouse handler for deleting clicked object from the scene
sceneView.setInteractionListener(new SceneView.DefaultInteractionListener(sceneView)
{

public void onMousePressed(javafx.scene.input.MouseEvent e)
{

if(e.getButton() == MouseButton.PRIMARY) {


if(isDeleteElement ==true)
{
javafx.geometry.Point2D screenPoint = new javafx.geometry.Point2D(Math.round(e.getX()),
Math.round(e.getY()));
com.esri.arcgisruntime.geometry.Point surfacePoint = sceneView.screenToBaseSurface(screenPoint);


// identify graphics on the graphics overlay
identifyGraphics = sceneView.identifyGraphicsOverlayAsync(graphicsOverlay, screenPoint, 10, false);
identifyGraphics.addDoneListener(() -> {

try {
// get the list of graphics returned by identify
IdentifyGraphicsOverlayResult result = identifyGraphics.get();
List<Graphic> graphics = result.getGraphics();

if (!graphics.isEmpty()) {

for(int i = 0; i<graphics.size(); i++) {

if(myGraphics.contains(graphics.get(i))) {
for (int j = 0; j < myGraphics.size(); j++)
graphicsOverlay.getGraphics().remove(myGraphics.get(j));
myGraphics.clear();
}
else {
graphicsOverlay.getGraphics().remove(graphics.get(i));//just delete a part of the complex graphic object you clicked on by mouse
}

}
}
}
catch (Exception ex) {
ex.printStackTrace();
}
});
}
}
else {
// let the default listener you've overridden deal with other events
super.onMousePressed(e);
}
}

myGraphic is an ArrayList<Graphic> that contains all graphic elements of some graphical object you want to delete(for example trapezium that consists of 4 lines).

 

0 Kudos