zoukankan      html  css  js  c++  java
  • 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
           }
       }
    });
  • 相关阅读:
    HDU 4396
    Vijos1603 迷宫
    BZOJ1087 [SCOI2005] 互不侵犯King
    BZOJ2208 [JSOI2010] 连通数
    BZOJ1051 [HAOI2006] 受欢迎的牛
    BZOJ2751 [HAOI2012] 容易题(easy)
    BZOJ1015 [JSOI2008] 星球大战starwar
    BZOJ1012 [JSOI2008] 最大数maxnumber
    BZOJ1050 [HAOI2006] 旅行comf
    BZOJ2761 [JLOI2011] 不重复数字
  • 原文地址:https://www.cnblogs.com/Joanna-Yan/p/4730442.html
Copyright © 2011-2022 走看看