Android Arcgis集成天地图

当初开发的时候在网上搜索了很久,没有看到合适的arcgis相关的资料,很多资料都是之前旧版本的arcgis,大部分的代码也不能用,所以工作完成之后在这里稍微总结一下

  1. 天地图相关

    天地图官网
    代码所用的服务地址

  2. arcigs相关

    1. TianDiMapUtils

      TileInfo参数
      参数类型参数名解释备注
      intDPI分辨率
      TileInfo.ImageFormatimageFormat切片的加载方式?不太确定
      ListlevelOfDetails主要缩放等级
      Pointorigin起始点这里在异步加载的时候,点有时候不可用,不知道什么原因
      SpatialReferencespatialReference坐标系类型
      inttileHeight切片高
      inttileWidth切片宽
      WebTiledLayer参数
      参数类型参数名解释备注
      StringtemplateUri地图地址
      IterablesubDomains不知道术语,见备注天地图WMTS服务有八个域名可以用来访问,0~8中任何一个都可以进行切片
      TileInfotileInfo关键信息见上文
      EnvelopefullExtent地图范围
      Graphic
      参数类型参数名解释备注
      Geometrygeometry地图信息一般用Point即可
      Map<String, Object>attributes额外信息直接放对象会报错,不知道原因
      Symbolsymbolmarker图片PictureMarkerSymbol iconPump = new PictureMarkerSymbol(new BitmapDrawable(changeSize(R.drawable.gis_ic_bengzhan)));

      new Graphic(point, stringStringHashMap, iconWaterStation)

    2. ArcGisUtil

      • 使用 Lifecycle 解决生命周期问题,把生命周期的控制抽出到工具类中
      • arcgis中没有像百度、高德中那种marker点击事件,所以需要根据点击坐标自己实现
        关键代码解释
       mapView.setOnTouchListener(DefaultMapViewOnTouchListener defaultMapViewOnTouchListener,MapView mapView){
          @Override
          public boolean onSingleTapConfirmed(MotionEvent motionEvent) {
              //地图手势处理
              onClickMap(motionEvent);
              return true;
          }
       }
      

      处理手势事件

      private void onClickMap(MotionEvent motionEvent) {
         android.graphics.Point screenPoint = new android.graphics.Point(Math.round(motionEvent.getX()),
             Math.round(motionEvent.getY()));
      
         // create a map point from screen point
         Point mapPoint = mapView.screenToLocation(screenPoint);
         // convert to WGS84 for lat/lon format
         Point wgs84Point = (Point) GeometryEngine.project(mapPoint, SpatialReferences.getWgs84());
         Graphic graphicsFromLayer = getGraphicsFromLayer1(mapView.getGraphicsOverlays(), Math.round(motionEvent.getX()), Math.round(motionEvent.getY()));
      
         if (graphicsFromLayer != null) {
             Point point = (Point) graphicsFromLayer.getGeometry();
             onClickMapListener.onClickMap(graphicsFromLayer, point);
         }
      }
      

      从一个图层里里 查找获得 Graphics对象. x,y是屏幕坐标,layer是GraphicsLayer目标图层(要查找的)。相差的距离是50像素。

      public Graphic getGraphicsFromLayer1(List<GraphicsOverlay> graphicsOverlay, double xScreen, double yScreen) {
          //遍历arcgis地图,
          for (GraphicsOverlay g : graphicsOverlay) {
          for (Graphic graphic : g.getGraphics()) {
              Point geometry = (Point) graphic.getGeometry();
              android.graphics.Point point = mapView.locationToScreen(geometry);
              double x1 = point.x;
              double y1 = point.y;
              if (Math.sqrt((xScreen - x1) * (xScreen - x1) + (yScreen - y1) * (yScreen - y1)) < 50) {
                  //触发了点击
                  return graphic;
              }
          }
      }
      return null;
      

      展示地图弹窗

      public Callout showTextPop(String text, Point arcgisPoint) {
              TextView calloutContent = new TextView(mapView.getContext());
              calloutContent.setTextColor(Color.BLACK);
              calloutContent.setSingleLine();
              // format coordinates to 4 decimal places
              calloutContent.setText(text);
              return showPop(calloutContent, arcgisPoint);
          }
      
  3. 最后上代码 代码地址

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值