为了响应touch事件,需要设置OnMapTouchListener

示例:

private void initMapEventsListener()
{
       mapWidget.setOnMapTouchListener(new OnMapTouchListener() {    
           public void onTouch(MapWidget map, MapTouchedEvent event) {
               
               List objectTouchEvents = event.getTouchedObjectIds();

               // X coordinate of the touch in original image coordinates
               int mapX = event.getMapX();  

   // Y coordinate of the touch in original image coordinates

   int mapY = event.getMapY();

   // X coordinate of the touch in screen coordinates                 

   int screenX = event.getScreenX();

   // Y coordinate of the touch in screen coordinates
               int screenY = event.getScreenY();
               
               if (objectTouchEvents.size() == 1) {
                   ObjectTouchEvent objectTouchEvent = objectTouchEvents.get(0);
                   // Id of the layer that the map object belongs to
                   long layerId = objectTouchEvent.getLayerId();
                   // Id of the map object that was touched.

                   Object objectId = objectTouchEvent.getObjectId();                     
                   Toast.makeText(BrowseMapDemoActivity.this, "Touched object " + objectId + " on layer" + layerId + ", x: " + mapX + " y: " + mapY, Toast.LENGTH_SHORT).show();
               }
           }
       });
   }

 

相关文章:

  • 2021-12-18
  • 2021-07-10
  • 2022-12-23
  • 2022-12-23
  • 2021-07-09
  • 2022-02-22
  • 2021-09-26
猜你喜欢
  • 2021-06-29
  • 2022-01-12
  • 2022-01-03
  • 2021-07-19
  • 2021-09-24
  • 2021-09-15
  • 2022-01-25
相关资源
相似解决方案