我目前正在使用带有实时预览扩展程序的Atom,它可以准确地显示我的页面所谓的外观。也就是说,当我去实际网站时,我只看到标题,而不是地图。不知道发生了什么事。我试过CTRL-F5并重新加载页面没有任何效果。这就是我所拥有的。
的index.html
<!DOCTYPE html>
<html>
<head>
<title>Map Prototype</title>
<link rel="stylesheet" href="css/index.css" />
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.3/dist/leaflet.css" />
<link href="https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/sandstone/bootstrap.min.css" rel="stylesheet" integrity="sha384-G3G7OsJCbOk1USkOY4RfeX1z27YaWrZ1YuaQ5tbuawed9IoreRDpWpTkZLXQfPm3" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://unpkg.com/leaflet@1.0.3/dist/leaflet.js"></script>
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapse" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">...</button>
<a class="navbar-brand" href="index.html">Map Demo</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="index.html">Home</a></li>
<li><a href="http://vietnamwarstories.indiana.edu/" target="_blank">Website</a></li>
<li><a href="http://vietnamwarstories.indiana.edu/contact/" target="_blank">Contact</a></li>
</ul>
<ul class="nav navbar-nav navbar-right"></ul>
</div>
</nav>
<div id="map-container">
<div id="map"></div>
</div>
<script src="js/map.js"></script>
</body>
</html>
index.css
html, body {
padding: 0;
margin: 0;
}
#map-container {
height: 100%;
width: 100%;
}
#map {
width: 100%;
height: 100%;
}
map.js
var map = L.map ('map', { center: [16.056, 100.745], zoom: 6 });
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
答案 0 :(得分:1)
修正了它只需删除#map-container div并将html和body设置为100%,并映射到100%。
html, body {
padding: 0;
margin: 0;
height: 100%;
}
#map {
height: 100%;
}