具有HTML声明的OpenLayers无法正常工作

时间:2017-03-24 13:09:04

标签: javascript html css thymeleaf openlayers

我有这个没有显示地图的Thymeleaf模板。它仅在我删除<!DOCTYPE HTML>

时显示地图
  <!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>

1 个答案:

答案 0 :(得分:0)

确保您的身体有尺寸,例如:通过添加以下css:

html, body: {
  width: 100%;
  height: 100%;
  margin: 0;
}