我正在尝试在地图上方添加一个按钮,用于显示用户的当前位置。
基本上我想复制内置按钮的功能,但要做一个更明显的功能。
这是我的代码:
<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.scrollWheelZoom.disable();
任何想法?
答案 0 :(得分:1)
该问题是在一年前发布的,但如果人们仍在寻找答案,我会发现以下内容:
http://codepen.io/leemark/pen/vcbuf
$('.pure-button').on('click', function(){
mymap.locate({setView: true, maxZoom: 15});
});
在示例中,这是对按钮的click事件的调用。您可以使用他们的按钮或创建一个不同的按钮。
我不确定它是不是我想要的,也不确定我是否会实现它。但它似乎回答了原来的帖子。
答案 1 :(得分:0)
我建议您浏览leaflet-locate repository and reading the documentation,其中包含您可以自行触发的.locate()
方法,例如$('a.somelink').click(function() { locateControl.locate(); });