繁体   English   中英

OpenLayers不显示kml层

[英]OpenLayers not displaying kml layer

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

这是我的kml文件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代码:

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图层尚未显示。 有谁知道可能出什么问题了?

也许添加到您的代码中:

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

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

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

尝试删除策略:[new OpenLayers.Strategy.Fixed()]

这个怎么样:

<?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>

那对我的朋友有用吗?

暂无
暂无

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

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