美文网首页
ArcGis for Android在地图上添加自定义图标

ArcGis for Android在地图上添加自定义图标

作者: HMZZS | 来源:发表于2020-07-28 14:27 被阅读0次
  • 导包在项目目录下build.gradle内添加
maven {url 'https://esri.bintray.com/arcgis'}
  • 导包在app目录下的build.gradle内添加
implementation 'com.esri.arcgisruntime:arcgis-android:100.8.0'
  • 在onCreate中调用地图的setOnTouchListener函数具体代码如下
mMapView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {

                showImageAtMap(R.drawable.map_start, motionEvent);

                return false;
            }
        });
private void showImageAtMap(int res, MotionEvent e) {
        BitmapDrawable startDrawable = (BitmapDrawable) ContextCompat.getDrawable(getContext(), res);
        final PictureMarkerSymbol pinSourceSymbol;
        try {
            pinSourceSymbol = PictureMarkerSymbol.createAsync(startDrawable).get();
            pinSourceSymbol.loadAsync();
            pinSourceSymbol.addDoneLoadingListener(new Runnable() {
                @Override
                public void run() {
                    //添加新图形
                    Point point = mMapView.screenToLocation(new android.graphics.Point(Math.round(e.getX()), Math.round(e.getY())));
                    Graphic pinSourceGraphic = new Graphic(point, pinSourceSymbol);
                    mGraphicsOverlay.getGraphics().add(pinSourceGraphic);
                }
            });
            pinSourceSymbol.setOffsetY(20);
        } catch (InterruptedException | ExecutionException ex) {
            ex.printStackTrace();
        }
    }

单击地图即可在所点击的位置进行添加图片

  • 如图所示


    GIF.gif

相关文章

网友评论

      本文标题:ArcGis for Android在地图上添加自定义图标

      本文链接:https://www.haomeiwen.com/subject/clefrktx.html