MapView.removeAll() 从地图中删除所有图层。那不是你想要的。
MapView.removeAll()
相反,尝试循环遍历 MapView 的图层和每个类型的图层 GraphicsLayer (但不是类型 ArcGISFeatureLayer ),删除图层或从图层中删除图形。做这样的事情:
MapView
GraphicsLayer
ArcGISFeatureLayer
private void somewhereInYourExistingCode() { ... for (Layer layer : map.getLayers()) { clearGraphics(layer); } ... } private void clearGraphics(Layer layer) { /** * ArcGISFeatureLayer extends GraphicsLayer, but what you're * probably looking for is GraphicsLayer objects that are * not of type ArcGISFeatureLayer. */ if (layer instanceof GraphicsLayer && !(layer instanceof ArcGISFeatureLayer)) { // You can call map.removeLayer(layer), or... ((GraphicsLayer) layer).removeAll(); } else if (layer instanceof GroupLayer) { GroupLayer groupLayer = (GroupLayer) layer; for (Layer sublayer : groupLayer.getLayers()) { // Recursive call clearGraphics(sublayer); } } }