我有一个不显示 map 的 Thymeleaf 模板。它只在我删除 <!DOCTYPE HTML>
时显示 map
<!DOCTYPE HTML>
<html>
<head>
<title>OpenLayers 2 Example</title>
<script src="http://openlayers.org/api/OpenLayers.js"></script>
</head>
<body>
<div style="width:100%; height:100%" id="map"></div>
<script defer="defer" type="text/javascript">
var map = new OpenLayers.Map('map');
var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://vmap0.tiles.osgeo.org/wms/vmap0", {layers: 'basic'} );
map.addLayer(wms);
map.zoomToMaxExtent();
</script>
</body>
</html>
最佳答案
确保您的 body 有尺寸,例如通过添加以下 css:
html, body: {
width: 100%;
height: 100%;
margin: 0;
}
关于javascript - 带有 HTML <!DOCTYPE> 声明的 OpenLayers 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43000348/