arcgis的graphics创建、选中和移动

在这里插入图片描述
有时我们需要在arcgis地图上创建点线面(多边形)等图形。下面我们根据官方文档,梳理一下具体思路。包括Graphic创建,在地图上被选中,移动Graphic的位置的整个思路及代码。
一、创建GraphicsOverlay

  1. 创建GraphicsOverlay对象,并把此对象加入mapView中
// create a graphics overlay
graphicsOverlay = new GraphicsOverlay();
  1. 创建Graphic对象,Graphic对象可以包括点Point或线polyline或多边形(面)polygon。下面以点Point为例列出代码。最后把Graphic对象放入刚才创建的GraphicsOverlay对象中。其中可以对点线面的样式进行描述。
// create a map point for the Santa Monica pier
Point pierPoint = new Point(-118.4978, 34.0086, SpatialReferences.getWgs84());

// create a red (0xFFFF0000) circle simple marker symbol
SimpleMarkerSymbol redCircleSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, 0xFFFF0000, 10);

// create a graphic from the point and symbol
Graphic pierGraphic = new Graphic(pierPoint, redCircleSymbol);

// add the graphic to the graphics overlay
graphicsOverlay.getGraphics().add(pierGraphic);
  1. 把 graphicsOverlay 对象 加入mapView中。这样地图上就会显示相应的点或线或面了。
 // add graphics overlay to the map view's graphics overlay collection
mapView.getGraphicsOverlays().add(graphicsOverlay);

二、在graphicsOverlay选中,识别选中的图形selectedGraphic
使用mapView的identifyGraphicsOverlayAsync方法进和识别选中。具体代码如下:

// identify graphics on the graphics overlay
final ListenableFuture<IdentifyGraphicsOverlayResult> identifyFuture = mGeoView.identifyGraphicsOverlayAsync(graphicsOverlay,
    screenPoint, 10, false, 10);

identifyFuture.addDoneListener(new Runnable() {
  @Override
  public void run() {
    try {
      // get the list of graphics returned by identify
      List<Graphic> identifiedGraphics = identifyFuture.get().getGraphics();

if (!identifiedGraphics.isEmpty()) {
	selectedGraphic=identifiedGraphics.get(0);
	selectedGraphic.setSelected(true);
}

     /* // iterate the graphics
      for (Graphic graphic : identifiedGraphics) {
        // Use identified graphics as required, for example access attributes or geometry, select, build a table, etc...
        graphic.setSelected(true);
      }*/
    } catch (InterruptedException | ExecutionException ex) {
      dealWithException(ex); // must deal with checked exceptions
    }

  }
});

三、移动点或线或面的位置
使用刚才识别或选中的点或线或面的selectedGraphic,修改位置。具体代码如下:

// create a point from location clicked
mapView.setOnMouseClicked(e -> {
  if (e.getButton() == MouseButton.PRIMARY) {
    Point2D geoViewPoint = new Point2D(e.getX(), e.getY());
    // add new location to selected graphic
    Point geoPoint = mapView.screenToLocation(geoViewPoint);
    selectedGraphic.setGeometry(geoPoint);
  }
});

愿意看官方英文文档的朋友,可以查看下面相关文档,也可以相互沟通学习。
https://developers.arcgis.com/android/maps-2d/add-graphics-to-a-map-view/

  • 56
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值