简体   繁体   中英

Django-leaflet: map getBounds returning [object Object]

I am using django-leaflet to display a map in a template, where the goal is to only display the coordinates of the visible area of the map when the user moves the map.

For this I'm using the getBounds() method, but the function only returns [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 %}

Why is not showing the coordinates?

As the getBounds() returns a LatLngBounds , for viewing the coordinates it is necessary to convert to a string, using the method toBBoxString() .

function map_init (map, options) {
    map.on('moveend', function() { 
      alert(map.getBounds().toBBoxString());
    });
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM