从html文档访问父目录以设置URL参数

时间:2019-04-09 14:09:12

标签: javascript html openlayers openstreetmap

我正在尝试使用渲染的图块将地图放在具有openlayers的页面上。我已经将map.html文档(例如来自网站的文档)放置在目录中,在该目录中我还绘制了图块。这很完美。

    <!doctype html>
<html lang="en">
  <head>
    <link rel="stylesheet" href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css" type="text/css">
    <style>
      .map {
        height: 400px;
        width: 100%;
      }
    </style>
    <script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
    <title>OpenLayers example</title>
  </head>
  <body>
    <h2>My Map</h2>
    <div id="map" class="map"></div>
    <script type="text/javascript">
      var map = new ol.Map({
        target: 'map',
        layers: [
          new ol.layer.Tile({
            source: new ol.source.OSM({
                                        /*attributions: [
                                          'All maps © <a href="https://www.osm.org/">OpenStreetMaps</a>',
                                          ATTRIBUTION
                                        ],*/
                                        url: "./tiles/{x}/{y}/{z}.png"
                                      })
          })
        ],
        view: new ol.View({
          center: ol.proj.fromLonLat([37.41, 8.82]),
          zoom: 4
        })
      });
    </script>
  </body>
</html>

我还制作了渲染图块的副本,并将其放置在html文件的父目录中。现在,当我尝试访问父目录以调用磁贴时,它不起作用。浏览器显示空白页。路径出了什么问题?

source: new ol.source.OSM({
                                        /*attributions: [
                                          'All maps © <a href="https://www.osm.org/">OpenStreetMaps</a>',
                                          ATTRIBUTION
                                        ],*/
                                        url: "../tiles/{x}/{y}/{z}.png"
                                      })
          })

0 个答案:

没有答案