【问题标题】:Stop to pass the click event to annotation (prevent from popup)停止将点击事件传递给注释(防止弹出)
【发布时间】:2016-02-14 08:12:17
【问题描述】:

我正在使用 ti.Map

当用户点击注释时我想做一些事情。

//make mapview
    var mapView = Map.createView({
        mapType:Map.NORMAL_TYPE,
    });

//make anotation
    annot= Map.createAnnotation({
            latitude: myLatitude
            longitude: myLongitude
            title: myTitle
            width:'100dp',
            height:'100dp'
    });

// add annotation
    mapView.addAnnotation(annot);

//handle the annotation click 
    mapView.addEventListener('click', function(evt) {
        if (evt.clicksource == "pin"){ // if user click annotation
            //do something
            return; //I try this 
        }
    });

效果很好。

但是,在执行某些操作后,会出现注释弹出窗口(作为默认行为)

我想停止注释弹出窗口。

1)我试图阻止事件传递给注释类。

2)停止注解不响应点击事件。

我该如何解决?

【问题讨论】:

    标签: google-maps titanium apple-maps


    【解决方案1】:

    如果您想停止注释弹出窗口,只需尝试评论annot 的属性title。我试过了,它工作正常。

    //make anotation
    annot= Map.createAnnotation({
            latitude: 19.151201,
            longitude: 72.938237,
            // title: 'myTitle',
            width:'100dp',
            height:'100dp'
    });
    
    //handle the annotation click 
    mapView.addEventListener('click', function(evt) {
        if (evt.clicksource == "pin"){ // if user click annotation
            //do something
            alert('Pin clicked');
            return; //I try this 
        }
    });
    

    只有警报是可见的,没有注释弹出窗口。

    一些更新的代码:

    annot= Map.createAnnotation({
        latitude: 19.151201,
        longitude: 72.938237,
        title: ' ',
        backgroundColor : 'transparent'
    });
    // add annotation
    mapView.addAnnotation(annot);
    
    //handle the annotation click 
    mapView.addEventListener('click', function(evt) {
    if (evt.clicksource == "pin"){ // if user click annotation
        alert('Pin clicked');
        evt.annotation.title = "";
        // return; //I try this 
    }else if (evt.clicksource == "map"){
        alert('map');
        evt.annotation.title = " ";
    }
    });
    

    【讨论】:

    • 感谢您的评论。我注释掉了标题,所以弹出窗口没有出现,但是 mapView 的“点击”事件没有被触发....
    • @whitebear 你用的是哪个SDK?
    • 5.1.1GA 和 ti map 2.4.1(iOS)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-09
    • 2011-12-20
    • 2012-01-17
    • 1970-01-01
    • 2015-04-28
    • 1970-01-01
    • 2018-05-10
    相关资源
    最近更新 更多