Picture Marker Symbol change location on single tab

361
1
04-09-2019 04:23 AM
AhmedSaeed
New Contributor

I have Picture Marker Symbol and it is appearing fine on initial setup.

Now I want to change it's location. I am trying with following method

mMapView.setOnTouchListener(new DefaultMapViewOnTouchListener(getContext(), mMapView) {
    @Override
    public boolean onSingleTapConfirmed(MotionEvent e) {
        android.graphics.Point screenPoint = new android.graphics.Point(
                Math.round(e.getX()),
                Math.round(e.getY()));
        Point mapPoint = mMapView.screenToLocation(screenPoint);

        pinStarBlueSymbol.addDoneLoadingListener(new Runnable() {
            @Override
            public void run() {
                //add a new graphic with the same location as the initial viewpoint
                Point pinStarBluePoint = new Point(mapPoint.getX(), mapPoint.getY(), SpatialReferences.getWgs84());
                Graphic pinStarBlueGraphic = new Graphic(pinStarBluePoint, pinStarBlueSymbol);
                mGraphicsOverlay.getGraphics().add(pinStarBlueGraphic);
            }
        });

        return super.onSingleTapConfirmed(e);
    }
});

I am assuming it will draw multiple picture marker, but it shows only single one.

If I try to use simple marker, it is working fine.

0 Kudos
1 Reply
JeffFord1
New Contributor

I believe it's because you have the code to add the graphic wrapped inside of the done loading listener of the picture marker symbol. That listener will only fire once per loadAsync() call. You'll want to separate the logic of loading the symbol from creating a new graphic. For example, load the symbol outside of the onSingleTapConfirmed callback and then just use the symbol directly.

    mMapView.setOnTouchListener(new DefaultMapViewOnTouchListener(getContext(), mMapView) {
      @Override
      public boolean onSingleTapConfirmed(MotionEvent e) {
        android.graphics.Point screenPoint = new android.graphics.Point(
                Math.round(e.getX()),
                Math.round(e.getY()));
        Point mapPoint = mMapView.screenToLocation(screenPoint);

        //add a new graphic with the same location as the initial viewpoint
        Point pinStarBluePoint = new Point(mapPoint.getX(), mapPoint.getY(), SpatialReferences.getWgs84());
        Graphic pinStarBlueGraphic = new Graphic(pinStarBluePoint, pinStarBlueSymbol);
        mGraphicsOverlay.getGraphics().add(pinStarBlueGraphic);
        return super.onSingleTapConfirmed(e);
      }
    });

 

0 Kudos