我使用django-leaflet在模板中显示地图,目标是仅在用户移动地图时显示地图可见区域的坐标。
为此,我使用了getBounds()方法,但函数只返回[Object Object]。
template.html:
{% load leaflet_tags %}
{% block extra_head %}
{% leaflet_js %}
{% leaflet_css %}
{% endblock %}
{% block body %}
{% leaflet_map "extent" callback="map_init" %}
{% endblock %}
{% block extra_script %}
<script>
function map_init (map, options) {
map.on('moveend', function() {
alert(map.getBounds());
});
}
</script>
{% endblock %}为什么不显示坐标?
发布于 2022-08-13 01:24:10
由于getBounds()返回一个LatLngBounds,为了查看坐标,必须使用toBBoxString()方法将其转换为字符串。
function map_init (map, options) {
map.on('moveend', function() {
alert(map.getBounds().toBBoxString());
});
}https://stackoverflow.com/questions/73340606
复制相似问题