简体   繁体   English

具有HTML的OpenLayers <!DOCTYPE> 声明无效

[英]OpenLayers with HTML <!DOCTYPE> Declaration NOT WORKING

I have this Thymeleaf template that does not show the map. 我有这个Thymeleaf模板,不显示地图。 It only show the map when I delete <!DOCTYPE HTML> 仅在删除<!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>

Make sure your body has a dimension, eg by adding the following css: 确保您的身体有尺寸,例如添加以下css:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM