javascript - 在我的本地驱动器上使用 openlayers 显示 kml 文件

标签 javascript openlayers

我正在尝试运行此示例:KML layer in Openlayers doesn't work on localhost本地。我做了一些研究,发现这个人也有类似的问题。不过他提到,如果文件在本地链接,就会出现此问题。因此我认为如果它们没有在本地链接我应该没问题。我尝试直接使用来自 openlayers 网站的示例中的 javascript 文件:http://openlayers.org/dev/examples/kml-layer.html这是行不通的。

问题是我可以看到 basemap ,但 kml 文件不会显示在 map 上。

我在jsfiddle上放置了一个示例:http://jsfiddle.net/Hn5pG/

<!DOCTYPE html>
<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">
        <link rel="stylesheet" href="http://openlayers.org/dev/theme/default/style.csss" type="text/css">
        <link rel="stylesheet" href="http://openlayers.org/dev/examples/style.css" type="text/css">
    </head>
    <body>

    <h1 id="title">KML Layer Example</h1>

    <div id="tags">KML</div>

    <p id="shortdesc">
        Demonstrates loading and displaying a KML file on top of a basemap.
    </p>

    <div id="map" class="smallmap"></div>

    <div id="docs">
        <p>
            A vector layer can be populated with features from a KML document
            by configuring the layer with an HTTP protocol that points to the
            KML document and is configured with a KML format for parsing features.
            The fixed strategy is used to load all features at once.
        </p>
        <p>
            View the <a href="kml-layer.js" target="_blank">kml-layer.js</a>
            source to see how this is done.
        </p>
    </div>

    <script src="http://openlayers.org/dev/OpenLayers.js"></script>
    <script src="http://openlayers.org/dev/examples/kml-layer.js"></script>
    </body>
</html>

我是否误解了什么?我在工作中只能访问 Firefox 和 Internet Explorer,并且如果可能的话,需要能够在不托管的情况下对其进行测试。

谢谢

最佳答案

我发现了这个问题。重新托管页面时,我没有链接到 styles.kml 文件。加载此文件后,将显示 kml。

我仍然不明白为什么我不能使用他们的 js 文件来做同样的事情。

关于javascript - 在我的本地驱动器上使用 openlayers 显示 kml 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13128731/

相关文章:

javascript - 如何在不使用 Electron 锻造重定向到根目录的情况下进行热重装并使用react

javascript - safari 11 打开多个弹窗

javascript - 通过 javascript 旋转 OpenLayers3 map - onload 和通过函数

javascript - 如何使用 Three.js 将纬度/经度转换为 3D 像素

search - Drupal 7 GeoField Proximity 使用搜索 API 索引

javascript - 如何防止 CSS/HTML 下拉菜单部分显示在页面外?

javascript - 从js上传图像文件到azure blob存储

javascript - 如何使用递归js找到最大嵌套

javascript - 获取 OpenLayers GET 请求的 responseText JSON 元素

javascript - 用于标记和向量的 Openlayers zIndex