使标记在 Mapbox 中可点击
Making markers clickable in Mapbox
我正在努力使 this Mapbox map 上的标记可点击而不破坏滚动效果。我想让点击其中一个标记成为可能,然后滚动到正确的部分。
有人知道怎么解决吗?
将此添加到您的 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()
});
注意:照原样,mapbox 示例中发布的代码将不起作用,因为它们对 'article' 的 css 定义。您必须像我在 jsfiddle 中所做的那样删除 right:0
,这样文章元素就不会覆盖屏幕并防止点击在标记上注册。
我正在努力使 this Mapbox map 上的标记可点击而不破坏滚动效果。我想让点击其中一个标记成为可能,然后滚动到正确的部分。
有人知道怎么解决吗?
将此添加到您的 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()
});
注意:照原样,mapbox 示例中发布的代码将不起作用,因为它们对 'article' 的 css 定义。您必须像我在 jsfiddle 中所做的那样删除 right:0
,这样文章元素就不会覆盖屏幕并防止点击在标记上注册。