html - 仅在此传单地图中使用 OpenStreetMap?
问题描述
我是使用地图图层和图块创建地图的新手,所以请多多包涵。
所以我正在制作一张地图来显示点,我读过它OpenStreetMap
是免费的,mapbox
但不是。出于这个原因,我们只想使用OpenStreetMap
.
这个 HTML 示例绘制了一张地图并绘制了点,但代码说它使用了这两种技术。这是代码。
两个问题:
说 mapbox 和 OpenStreetMap 本质上是一样的,因为它们都提供用于绘制地图的图块,这是否正确?
我想删除 mapbox 并在此示例中仅使用 OpenStreetMap。这可能吗?
<!DOCTYPE html>
<html>
<head>
<title>Leaflet - Points</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css" integrity="sha512-dsdfsdjflsdfjsljfsdl+asfsfsflskjfsld==" crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.3.1/dist/leaflet.js" integrity="sha512-/wrwrwerwer+wwerwrwerwer+dasdasdas==" crossorigin=""></script>
<style>
html, body {
height: 100%;
margin: 0;
}
#map {
width: 1200px;
height: 800px;
}
</style>
</head>
<body>
<div id='map'></div>
<script src="points.js" type="text/javascript"></script>
<script>
var map = L.map('map').setView([18.4148, -66.1241], 11);
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.qweqeqweqweqwe.qeqqqwe', {
maxZoom: 18,
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>, ' +
'Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
id: 'mapbox.streets'
}).addTo(map);
L.geoJSON([bicycleRental], {
pointToLayer: function (feature, latlng) {
return L.circleMarker(latlng, {
radius: 7,
fillColor: "#ff7800",
color: "#000",
weight: 1,
opacity: 1,
fillOpacity: 0.8
});
}
}).addTo(map);
</script>
</body>
</html>
解决方案
要使用 OpenStreetMap 瓦片,您必须设置:
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>',
subdomains: ['a','b','c']
}).addTo(map);
而不是 mapbox 服务器。检查传单主页上的示例https://leafletjs.com/index.html
推荐阅读
- amazon-web-services - API Gateway 自定义标头不会持续存在
- express - 我的嵌套文档不显示,猫鼬,快递
- python - python中最近的时间戳
- python - 如何更改选择器以使网站显示登录而不是使用 selenium python 和 chromedriver 进行注册?
- react-native - 如何在反应本机抽屉中禁用或删除或隐藏项目选定空间
- html - 如何访问 Handlebars 中嵌套循环内的数据?
- sharepoint - SharePoint 新式页面无法正确加载
- azure - 为什么在 Azure 中尝试通过 ARM-Template 创建 VM 时会触发错误“不是有效的资源引用。(代码:InvalidParameter)”?
- reactjs - React Native Redux - 为什么我不能访问我的 redux 存储中的数据并显示它?
- flutter - 上下文不包含块