javascript - 带有 HTML <!DOCTYPE> 声明的 OpenLayers 不工作

标签 javascript html css thymeleaf openlayers

我有一个不显示 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 &lt;!DOCTYPE> 声明的 OpenLayers 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43000348/

相关文章:

javascript - Leaflet:加载geoJSON文件和特定的PopUp

javascript - 用 jquery 格式化钱

javascript - 如何为我的悬停功能设置 jQuery 动画?

javascript - 您最喜欢兼容 Prototype 框架的 javascript 日期选择器是什么?

html - CSS 下拉菜单在 IE8 中未对齐

javascript - 追加和删除元素

css - 在单行表中居中图像

javascript - 使用 Django、CSS 和 Javascript 使 HTML 表单文本字段的存在依赖于复选框选择

javascript - 如果不是 "my operating system"更改 css - jquery

javascript - React-redux 持续存在,仅重新水合处于 redux 状态的某些节点