OpenLayers不显示kml层 [英] OpenLayers not displaying kml layer

查看:485
本文介绍了OpenLayers不显示kml层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用OpenLayers显示kml图层时遇到问题.

I am having problems displaying a kml layer using OpenLayers.

这是我的kml文件Light.kml:

Here is my kml file, Light.kml:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.0">
<Folder>
<open>1</open>
<visibility>1</visibility>
<GroundOverlay>
<name>2013-05-15 12:00:00Z</name>
<visibility>1</visibility>
<Icon><href>http://localhost/graphics/Light_0.jpg</href></Icon>
<LatLonBox>
<north>9.4896821975708</north>
<south>-66.0149154663086</south>
<east>197.33328247070312</east>
<west>90.69839477539062</west>
</LatLonBox>
<TimeStamp><when>2013-05-15T12:00:00Z</when></TimeStamp>
</GroundOverlay>
</Folder>
</kml>
</xml>

这是OpenLayers的javascript代码:

And here is the OpenLayers javascript code:

var map = new OpenLayers.Map({
    div: "map",
    layers: [
        new OpenLayers.Layer.WMS(
            "WMS", "http://vmap0.tiles.osgeo.org/wms/vmap0",
            {layers: "basic"},
            {wrapDateLine: true}
        )
    ],
    center: new OpenLayers.LonLat(140,-30),
    zoom: 3
});

var light = new OpenLayers.Layer.Vector("Light", {
strategies: [new OpenLayers.Strategy.Fixed()], protocol: new OpenLayers.Protocol.HTTP({
                url: "graphics/Light.kml",
                format: new OpenLayers.Format.KML({
                    extractStyles: true,
                    extractAttributes: true
                })
            })
        });
map.addLayers([light]);

该地图显示了kml图层未显示.有谁知道可能出什么问题了?

The map shows yet the kml layer is not displaying. Does anyone know what might be wrong?

推荐答案

也许添加到您的代码中:

Perhaps adding to your code:

light.setVisibility(true);
map.addLayer(light);

在我看来,您的代码中有错别字,请仅尝试使用map.addLayer.或者使用以下结构可以解决问题

It seems to me that you have a typo in your code, try only with map.addLayer. Or using the following structure could do the trick

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
});

这篇关于OpenLayers不显示kml层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆