Fit.Bounds
无效。
我有代码可以在Leaflet创建的地图上显示标记,但是Fit.Bounds
似乎不起作用。我不知道为什么,以及如何解决它。
<!-- INFA O WYDARZENIU MAPA OPENSTREET -->
<div id="mapid" style="width: 685px; max-width: 100%; height: 200px;"></div>
<script>
var mymap = L.map("mapid").setView([50.0287132, 19.953625399999964], 5);
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png?{foo}", {
foo: "bar",
attribution:
'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>'
}).addTo(mymap);
var fg = L.featureGroup().addTo(mymap);
L.marker([51.7790165, 19.443519100000003]).addTo(fg);
L.marker([50.0287132, 19.953625399999964]).addTo(fg);
// Fit all markers
setTimeout(function() {
map.fitBounds(fg.getBounds());
}, 1000);
</script>
<!-- INFA O WYDARZENIU KONIEC MAPY OPEN STREET -->