3

I'm trying to add a button above my map that would show the current location of the user.

Basically i want to duplicate the functionality of the built in button but make a more obvious one.

Here's my code:

<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>

any ideas?

4

2 回答 2

5

该问题是在一年前发布的,但如果人们仍在寻找答案,我发现以下内容: http://codepen.io/leemark/pen/vcbuf

$('.pure-button').on('click', function(){
mymap.locate({setView: true, maxZoom: 15});
});

在提供的示例中,这是对按钮单击事件的调用。您可以使用他们的按钮或创建一个不同的外观。

我不确定它是否正是我想要的,也不确定我是否会实现它。但是,它似乎回答了原始帖子。

于 2015-09-22T14:42:40.700 回答
0

我建议浏览到leaflet-locate 存储库并阅读文档,其中涵盖了.locate()您可以触发自己的方法,例如$('a.somelink').click(function() { locateControl.locate(); });

于 2014-04-17T22:14:53.590 回答