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

2020-07-28  本文已影响0人  HMZZS
maven {url 'https://esri.bintray.com/arcgis'}
implementation 'com.esri.arcgisruntime:arcgis-android:100.8.0'
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();
        }
    }

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

上一篇下一篇

猜你喜欢

热点阅读