zoukankan      html  css  js  c++  java
  • Android基于mAppWidget实现手绘地图(九)–如何处理地图对象的touch事件

     为了响应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();
                   }
               }
           });
       }
  • 相关阅读:
    Java 字符串判空
    JavaScript try catch 常用场景(一)
    IE console 未定义
    共享锁与排它锁
    js 原型链
    js的原型模式
    js中RegExp类型
    js中Array对象方法详解
    js动态生成input指定My97DatePicker时间问题
    利用spring、cxf编写并发布webservice
  • 原文地址:https://www.cnblogs.com/Joanna-Yan/p/4730100.html
Copyright © 2011-2022 走看看