leaflet.js中如何显示地图比例尺

问题描述 投票:0回答:1

不知leafleat.js中如何显示比例尺地图。那就是:我想要这个 而不是这个 (带到传单教程)。见图片的左下角。

javascript leaflet openstreetmap
1个回答
10
投票

您可以使用

L.control.scale()

var map = L.map('map').setView([51.505, -0.09], 13);

L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
    attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);

L.control.scale().addTo(map);
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" integrity="sha256-kLaT2GOSpHechhsozzB+flnD+zUyjE2LlfWPgU04xyI=" crossorigin="" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js" integrity="sha256-WBkoXOwTeyKclOHuWtc+i2uENFpDZ9YPdf5Hf+D7ewM=" crossorigin=""></script>

<div id="map" style="width: 100%; height: 150px;"></div>

© www.soinside.com 2019 - 2024. All rights reserved.