我是一个非常新的传单,所以我只是试图掌握基础知识。在阅读Leaflet提供的在线教程时,我很难加载地图。如果我使用坐标,如果我没有问题,但是如果我改变坐标,什么也不会加载。
有人能帮上忙吗?这就是我所拥有的:
<!DOCTYPE html>
<html>
<head>
<title>Leaflet Web Map</title>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
<style>
#map {
width: 960px;
height:500px;
}
</style>
</head>
<body>
<div id="map"></div><script>
var map = L.map('map',{
center: [43.64701, -79.39425],
zoom: 15
});
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
</script>这不会加载任何麻烦,但如果我更改坐标,它就不会加载。
发布于 2017-02-10 06:11:33
要更改地图中心,您应该在地图属性center: [43.00, -79.00]中进行更改。
var map = L.map('map',{
center: [43.00, -79.00],
zoom: 15
});您应该记住,第一个坐标latitude的取值范围为(-90,90),而第二个坐标latitude的取值范围为(-180,180)。但不管怎样,如果超过了第二个坐标,应用程序就会计算它的值,就好像它在给定的范围内一样。
也许你弄混了一些东西并试图在这里改变它,L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png',..?这一行代表加载底图分块,而不是居中地图。
发布于 2017-04-20 20:24:50
试着
var tileLayer = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png',
{
attribution: false
});
var map = L.map('map',
{
zoomControl: true,
layers: [tileLayer],
maxZoom: 18,
minZoom: 6
})
.setView([43.64701, -79.39425], 15);
setTimeout(function () { map.invalidateSize() }, 800);发布于 2017-02-08 22:42:44
我无法重现你的问题。更改中心仍会加载贴图。(单击下面的“运行代码片段”按钮)
var map = L.map('map', {
//center: [43.64701, -79.39425], //comment out one of the centers
center: [40, -80],
zoom: 15
});
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);<!DOCTYPE html>
<html>
<head>
<title>Leaflet Web Map</title>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
<style>
#map {
width: 960px;
height: 500px;
}
</style>
</head>
<body>
<div id="map"></div>
</body>
</html>
我注意到你没有end body,end html标签,所以我添加了它们。
你想改变的坐标是什么?
https://stackoverflow.com/questions/42115723
复制相似问题