KML图层没有显示出来

时间:2015-10-16 19:09:18

标签: kml

我正在以KML格式创建矢量图层。我在下拉框中有源以避免CORS,但是当我在地图中加载它们时它们没有任何功能。关于这个问题的任何想法都将非常感激。

请参阅下文我是如何做到的。

var layers = [ 

wms_bmid_pipes = new ol.layer.Vector({
            source: new ol.source.Vector({
            url: 'https://dl.dropboxusercontent.com/s/ea4qzzuyk5i2mxt /geid_ws-bmid-pipes.kml?dl=0',
            format: new ol.format.KML() 
            })
        })
        ];

由于图层没有显示在地图中,我运行下面的代码来检查它有多少功能(此代码来自开放层网站)。事实证明,在控制台中我得到“更改后计数:0”,这意味着没有任何功能。

    wms_bmid_pipes.getSource().on('change', function(evt){
        var source = evt.target;
            if (source.getState() === 'ready') {
                var numFeatures = source.getFeatures().length; 
                console.log("Count after change: " + numFeatures);
            }
    });

重点是wms_bmid_pipes包含:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:ns2="http://www.google.com/kml/ext/2.2" xmlns:ns3="http://www.w3.org/2005/Atom" xmlns:ns4="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0">
<Document>
    <LookAt>
        <longitude>-119.3597596329119</longitude>
        <latitude>49.89850519575446</latitude>
        <altitude>19983.5008834143</altitude>
        <heading>0.0</heading>
        <tilt>0.0</tilt>
        <range>16147.716881798802</range>
        <altitudeMode>clampToGround</altitudeMode>
    </LookAt>
    <NetworkLink>
        <name>bmid-pipes</name>
        <visibility>1</visibility>
        <open>1</open>
        <LookAt>
            <longitude>-119.3597596329119</longitude>
            <latitude>49.89850519575446</latitude>
            <altitude>19983.5008834143</altitude>
            <heading>0.0</heading>
            <tilt>0.0</tilt>
            <range>16147.716881798802</range>
            <altitudeMode>clampToGround</altitudeMode>
        </LookAt>
        <Url>
            <href>http://localhost:8080/geoserver/geid_ws/wms?service=wms&amp;request=GetMap&amp;version=1.1.1&amp;format=application/vnd.google-earth.kml+xml&amp;layers=geid_ws:bmid-pipes&amp;styles=line&amp;height=2048&amp;width=2048&amp;transparent=false&amp;srs=EPSG:4326&amp;format_options=AUTOFIT:true;KMATTR:true;KMPLACEMARK:false;KMSCORE:40;MODE:refresh;SUPEROVERLAY:false</href>
            <refreshInterval>0.0</refreshInterval>
            <viewRefreshMode>onStop</viewRefreshMode>
            <viewRefreshTime>1.0</viewRefreshTime>
            <viewBoundScale>1.0</viewBoundScale>
        </Url>
    </NetworkLink>
</Document>
</kml>

1 个答案:

答案 0 :(得分:0)

KmlLayer要求公开提供KML。 http://localhost:8080未公开发布。

<Url>
    <href>http://localhost:8080/geoserver/geid_ws/wms?service=wms&amp;request=GetMap&amp;version=1.1.1&amp;format=application/vnd.google-earth.kml+xml&amp;layers=geid_ws:bmid-pipes&amp;styles=line&amp;height=2048&amp;width=2048&amp;transparent=false&amp;srs=EPSG:4326&amp;format_options=AUTOFIT:true;KMATTR:true;KMPLACEMARK:false;KMSCORE:40;MODE:refresh;SUPEROVERLAY:false</href>
    <refreshInterval>0.0</refreshInterval>
    <viewRefreshMode>onStop</viewRefreshMode>
    <viewRefreshTime>1.0</viewRefreshTime>
    <viewBoundScale>1.0</viewBoundScale>
</Url>
相关问题