简体   繁体   English

如何从本地来源将KML添加到OpenLayers地图?

[英]How do I add a KML to an OpenLayers map from a local source?

I am looking at this example from openlayers themselves. 我正在从openlayers本身看这个例子。 You can see the source by clicking on the "kml-layer.js" link at the bottom. 您可以通过单击底部的“ kml-layer.js”链接来查看源。 The source code when i do this looks like this: 我执行此操作时的源代码如下所示:

var map = new OpenLayers.Map({
    div: "map",
    layers: [
        new OpenLayers.Layer.WMS(
            "WMS", "http://vmap0.tiles.osgeo.org/wms/vmap0",
            {layers: "basic"}
        ),
        new OpenLayers.Layer.Vector("KML", {
            strategies: [new OpenLayers.Strategy.Fixed()],
            protocol: new OpenLayers.Protocol.HTTP({
                url: "kml/lines.kml",
                format: new OpenLayers.Format.KML({
                    extractStyles: true, 
                    extractAttributes: true,
                    maxDepth: 2
                })
            })
        })
    ],
    center: new OpenLayers.LonLat(-112.169, 36.099),
    zoom: 11
});

It seems that this will only work if sourcing a kml via HTTP, but what if I want to source it from my own hard drive while I work on the map itself? 看来,这仅在通过HTTP采购kml时才有效,但是如果我想在地图上工作时从自己的硬盘驱动器中获取它,该怎么办? I can't seem to find much documentation on how to do this, can someone help out? 我似乎找不到太多有关此操作的文档,有人可以帮忙吗?

Thanks 谢谢

While this functionality requires hosting, there is a small work around. 尽管此功能需要托管,但可以做一些小工作。 If the data is public, and you don't want to use Python, you can create a free google website, and upload the KML to there and direct a link to it. 如果数据是公开的,并且您不想使用Python,则可以创建一个免费的Google网站,然后将KML上传到该网站并直接指向该网站的链接。 This used to work for me. 这曾经为我工作。

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

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