arcgis runtime for android 100.2版本变更基础使用

arcgis runtime for android版本从10到100变化很大,很多用法都进行了改变。10版本对于FeatureLayer中的中文标记总是乱码,100以后的版本对于乱码问题进行了修改,可以很好的显示中文,但是从10变到100很多方法的使用发生了变化。所以本篇记录自己使用到的一些方法的变更。

加载arcgis的方法参考Arcgis官网。本文导入arcgis版本为100.2.1。

1.地图授权(去官网注册账号后得到一串字符),去掉水印以及下方标志

ArcGISRuntimeEnvironment.setLicense("runtimelite,1000,rud##########,none,####################");//去掉水印
mapView.setAttributionTextVisible(false);//去掉下方标志

2.加载tpk文件

ArcGISMap map = new ArcGISMap();
local = new ArcGISTiledLayer(Environment.getExternalStorageDirectory()+ "/***.tpk");
map.getOperationalLayers().add(local);
mapView.setMap(map);

 隐藏不显示图层

local.setVisible(false);

3.加载geodatabase文件

Geodatabase db=new Geodatabase(Environment.getExternalStorageDirectory()+ "/***.geodatabase");
db.loadAsync();
db.addDoneLoadingListener(new Runnable() {
    @Override
    public void run() {

        for(int i = 0;i < db.getGeodatabaseFeatureTables().size();i++){
            GeodatabaseFeatureTable featureTable= db.getGeodatabaseFeatureTables().get(i);
            FeatureLayer featureLayer= new FeatureLayer(featureTable);
            featureLayer.setLabelsEnabled(true);//如果图层中有label标注,请打开显示
            map.getOperationalLayers().add(featureLayer);
        }
    }
});
mapView.setMap(map);

4.设置地图中心点以及缩放比例

Point point = new Point(105.95,30.71, SpatialReferences.getWgs84());
mapView.setViewpointCenterAsync(point, 320000);//第二个参数为缩放比例

也可以单独进行缩放

mapView.setViewpointScaleAsync(320000);

设置中心以及缩放比例一定要在mapView.setMap后设置,否则无效。缩放比例值越小越放大,缩放值从4000至320000感觉已经够放大够缩小的了。

5.去掉地图的网格

BackgroundGrid backgroundGrid = new BackgroundGrid();
backgroundGrid.setColor(0xf6f6f6f6);
backgroundGrid.setGridLineWidth(0);
mapView.setBackgroundGrid(backgroundGrid);

6.图形图层

从10版本的GraphicsLayer更换到100的GraphicsOverlay。

GraphicsOverlay overLay = new GraphicsOverlay();

添加图层

mapView.getGraphicsOverlays().add(overLay);

Graphic的初始化

Graphic graphic = new Graphic(geometry, attributes, symbol);

图层中图标进行添加、修改、删除(overLay.getGraphics()获取的是一个list型数据,对图标的增删改就是对list进行修改)

overLay.getGraphics().add(graphic);
overLay.getGraphics().set(id, graphic);//修改整个graphic
overLay.getGraphics().get(id).setSymbol(symbol);//修改graphic中的symbol
overLay.getGraphics().remove(id);//移除具体位置的图标
overLay.getGraphics().clear();//清除所有

获取Attributes

String num = (String)graphic.getAttributes().get("NUM");

Symbol初始化的变更

SimpleLineSymbol需要添加lineSymbol的style,第一个参数style分别有SOLID(实线)、DASH(虚线)、DASH_DOT(点化线)、DASH_DOT_DOT(双点化线)、DOT(点线),第三个参数为线条宽度

lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, getResources().getColor(R.color.red), 3);

SimpleMarkerSymbol需要将10版本的第三个参数style提到第一个参数。

symbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.TRIANGLE, getResources().getColor(R.color.yellow), 14);

 PictureMarkerSymbol

picSymbol = new PictureMarkerSymbol(new BitmapDrawable(getResources(), BitmapFactory.decodeResource(getResources(), R.mipmap.png)));

 画线Polyline也进行了更改

PointCollection points = new PointCollection(SpatialReferences.getWgs84());
Point point = new Point(lon, lat);
points.add(point);
Polyline pline = new Polyline(points);
Graphic graphic = new Graphic(pline, attributes, lineSymbol);
overLay.getGraphics().add(graphic);

7.选中GraphicsOverlay中图标

mapView.setOnTouchListener(new DefaultMapViewOnTouchListener(this, mapView){
    @Override
    public boolean onSingleTapConfirmed(MotionEvent v) {
        android.graphics.Point screenPoint = new android.graphics.Point(Math.round(v.getX()), Math.round(v.getY()));//获取点击屏幕的点
        try {
            ListenableFuture<IdentifyGraphicsOverlayResult> result = mapView.identifyGraphicsOverlayAsync(overlay, screenPoint, 10, false);
            List<Graphic> graphics = result.get().getGraphics();
            if(graphics.size() > 0){
                Graphic graphic= graphics.get(0);//选取第一个为选中的图标进行操作
            }
        }catch (Exception e) {
            e.printStackTrace();
        }
    }
});

8.选中FeatureLayer中图标

mapView.setOnTouchListener(new DefaultMapViewOnTouchListener(this, mapView){
    @Override
    public boolean onSingleTapConfirmed(MotionEvent v) {
        android.graphics.Point screenPoint = new android.graphics.Point(Math.round(v.getX()), Math.round(v.getY()));
        try {
            ListenableFuture<IdentifyLayerResult> featureQueryResult = mapView.identifyLayerAsync(featureLayer,screenPoint,10,false);
            for(Object element: featureQueryResult.get().getElements()){
                if(element instanceof Feature){
                    Feature feature = (Feature) element;
                    Graphic graphic = new Graphic(feature.getGeometry(), lineSymbol);//通过feature.getGeometry()获取到图形,可以通过这个图形构建一个新的Graphic,覆盖到原来的Graphic上达到高亮的效果
                }
            }
        }catch (Exception e) { 
            e.printStackTrace(); 
        }
    }
});

9.点击屏幕点与地图坐标转换

屏幕点转坐标

Point locPoint = mapView.screenToLocation(screenPoint);

坐标转屏幕点

Point screenPoint = mapView.locationToScreen(locPoint);

以上为基本用到的更新的内容,定位相关内容基本没有发生更改,就不做记录。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值