如何免费使用传单地图?
How to use Leaflet Map for free?
Leaflet 是开源且免费的。然而,传单网站上的示例使用 Mapbox 来渲染地图。 Mapbox 比 Google 地图 (Mapbox pricing) 贵。
问题是:任何人都可以免费使用 Leaflet 吗?
您可以免费使用Leaflet 库,只有示例中使用的tileprovider Mapbox 提供tiles 要钱。您只需要一个免费的 tileprovider,例如 OpenStreetMap:
var map = new L.Map('leaflet', {
center: [0, 0],
zoom: 0,
layers: [
new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
'attribution': 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors'
})
]
});
body {
margin: 0;
}
html, body, #leaflet {
height: 100%;
}
<!DOCTYPE html>
<html>
<head>
<title>Leaflet 1.0.3</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link type="text/css" rel="stylesheet" href="//unpkg.com/leaflet@1.0.3/dist/leaflet.css" />
</head>
<body>
<div id="leaflet"></div>
<script type="application/javascript" src="//unpkg.com/leaflet@1.0.3/dist/leaflet.js"></script>
</body>
</html>
Leaflet 是开源且免费的。然而,传单网站上的示例使用 Mapbox 来渲染地图。 Mapbox 比 Google 地图 (Mapbox pricing) 贵。 问题是:任何人都可以免费使用 Leaflet 吗?
您可以免费使用Leaflet 库,只有示例中使用的tileprovider Mapbox 提供tiles 要钱。您只需要一个免费的 tileprovider,例如 OpenStreetMap:
var map = new L.Map('leaflet', {
center: [0, 0],
zoom: 0,
layers: [
new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
'attribution': 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors'
})
]
});
body {
margin: 0;
}
html, body, #leaflet {
height: 100%;
}
<!DOCTYPE html>
<html>
<head>
<title>Leaflet 1.0.3</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link type="text/css" rel="stylesheet" href="//unpkg.com/leaflet@1.0.3/dist/leaflet.css" />
</head>
<body>
<div id="leaflet"></div>
<script type="application/javascript" src="//unpkg.com/leaflet@1.0.3/dist/leaflet.js"></script>
</body>
</html>