【问题标题】:Displaying kml files with openlayers on my local drive在我的本地驱动器上显示带有 openlayers 的 kml 文件
【发布时间】:2012-10-29 20:00:05
【问题描述】:

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

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

我在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,并且如果可能的话,我需要能够在不托管的情况下对其进行测试。

谢谢

【问题讨论】:

    标签: javascript openlayers


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多