我正试图在地图上方添加一个按钮,以显示用户的当前位置。
基本上,我想复制内置按钮的功能,但要做一个更明显的按钮。
这是我的代码:
<script>
var map = L.mapbox.map('map', 'plisvb.hopljoko');
L.control.locate({
drawCircle: true, // controls whether a circle is drawn that shows the uncertainty about the location
setView: true, // automatically sets the map view to the user's location, enabled if `follow` is true
keepCurrentZoomLevel: false, // keep the current map zoom level when displaying the user's location. (if `false`, use maxZoom)
icon: 'icon-location', // `icon-locate` or `icon-direction`
iconLoading: 'icon-spinner animate-spin', // class for loading icon
circlePadding: [0, 0], // padding around accuracy circle, value is passed to setBounds
locateOptions: {
maxZoom: 15
},
strings: {
title: "Click to see your current location", // title of the locate control
popup: "Your current location", // text to appear if user clicks on circle
outsideMapBoundsMsg: "You seem located outside the boundaries of the map" // default message for onLocationOutsideMapBounds
}
}).addTo(map);
map.scrollWheelZoom.disable();
</script>
有什么想法吗?
这个问题是一年前发布的,但如果人们仍在寻找答案,我发现了以下内容:http://codepen.io/leemark/pen/vcbuf
$('.pure-button').on('click', function(){
mymap.locate({setView: true, maxZoom: 15});
});
在提供的示例中,这是对按钮的单击事件的调用。你可以使用他们的按钮,也可以创建一个不同外观的按钮。
我不确定它是否正是我想要的,也不确定我是否会实现它。然而,它似乎回答了最初的帖子。
我建议浏览到传单定位存储库并阅读文档,其中包括您可以自己触发的.locate()
方法,如$('a.somelink').click(function() { locateControl.locate(); });