使标记可在Mapbox中单击

时间:2015-02-17 18:33:43

标签: mapbox

我努力使this Mapbox map上的标记可以点击而不会破坏滚动效果。我希望能够单击其中一个标记,然后滚动到右侧部分。

有谁知道如何修复它?

1 个答案:

答案 0 :(得分:0)

将此添加到您的javascript:

 /* Bind event handler to the featurelayer that holds the markers */
placesLayer.on('click', function(e) {
    //Get the id of the clicked marker
    var id = e.layer.feature.properties.id;

    //Scroll to the element
    document.getElementById(id).scrollIntoView()
});

http://jsfiddle.net/1oxkgfkw/

注意:因为他们对'article'的css定义,mapbox示例中发布的代码将无效。您必须像在jsfiddle中一样删除right:0,因此文章元素不会覆盖屏幕并阻止点击在标记上注册。

相关问题