Android基于mAppWidget实现手绘地图(十六)–处理一次触摸多个地图对象

最好的处理方式就是弹出一个对话框,将用户触摸过的控件罗列出来。你可以通过实现OnMapTouchListener来处理。

参考以下代码,实现上述功能:

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();
                   
       // Handle single object touch event here
       } else if (objectTouchEvents.size() > 1) {
             List ids = new ArrayList();
             // Getting id's of the touched objects
             for (ObjectTouchEvent objectTouchEvent:objectTouchEvents){
                  // Id of the layer the object belongs to
                  long layerId = objectTouchEvent.getLayerId();
                  // Id of the object
                  Object objectId = objectTouchEvent.getObjectId();
                  ids.add(objectId);
             }
                   
             // Show dialog with the list of objects here using ids
       } else {
             // Ignore touch event
       }
   }
});
原文地址:https://www.cnblogs.com/Joanna-Yan/p/4730442.html