我已将跟踪(geoJSON数据)添加到传单(1.5.1)地图中。有没有一种方法可以计算缩放比例和地图中心,以便显示整个轨迹?
到目前为止,这就是我的状态:
<script>
var map = new L.Map('map');
var osm = new L.TileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
minZoom: 0,
maxZoom: 20,
attribution: 'Map data © <a href="https://openstreetmap.org">OpenStreetMap</a> contributors'
});
map.setView(new L.LatLng(49.058744, 8.264556), 12);
map.addLayer(osm);
var track = {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"properties": {
"name": "Point",
"stroke": "#FF0000",
"stroke-width": "4"
},
"geometry": {
"type": "LineString",
"coordinates": [[8.264556,49.058744],[8.264556,49.058745],[8.264574,49.058747],[8.264599,49.058747],[8.264621,49.058743],[8.264628,49.058732]]
}
}
]};
L.geoJSON(track).addTo(map);
</script>