google-maps之Google Map OpenLayers Kml 图标名称

over140 阅读:103 2024-02-27 23:08:18 评论:0

KML 文件:

<?xml version="1.0" encoding="UTF-8"?> 
<kml xmlns="http://earth.google.com/kml/2.2"> 
<Document> 
    <name>Name</name> 
    <description><![CDATA[]]></description> 
    <Style id="style140"><IconStyle> 
        <Icon> 
            <name>Name</name> 
            <href>icon/green.png</href> 
        </Icon> 
        </IconStyle> 
    </Style> 
    <Placemark> 
        <name>Name</name> 
        <description>Desc Name</description> 
        <styleUrl>#style140</styleUrl> 
        <Point> 
            <coordinates>12.7548360932222,59.2701399304516,0.000000</coordinates> 
        </Point> 
    </Placemark> 
</Document> 
</kml> 

我得到了这个输出:

但我想要这个:

所以你可以看到点的名称。 kml 文件有什么问题?

谢谢!

请您参考如下方法:

我不知道这是否有帮助,但我发现您要使用的方法不起作用。我能够在 javascript 中以编程方式设置它。这使您可以在自己创建的红圈图标上方添加一个标签。

希望这对您有所帮助!

javascript(减去构建 map 对象等的其他代码):

function addLayer(){     
    var myStyles = new OpenLayers.StyleMap({  
    "default": new OpenLayers.Style({  
        strokeColor: "#FFCC33",  
        strokeWidth:10,  
        strokeOpacity:1,  
        fillColor:"#003399",  
        fillOpacity: 1,  
        externalGraphic: "icons/redcircle.png", 
        labelYOffset: 15, 
        pointRadius: 5, 
        label:"${label}",                    
    }) 
}); 
 
currentLayer = new OpenLayers.Layer.Vector("KML", { 
    styleMap: myStyles, 
    projection: map.displayProjection,       
    strategies: [new OpenLayers.Strategy.Fixed()],           
    protocol: new OpenLayers.Protocol.HTTP({ 
        url: "/kml/mymap.kml", 
        format: new OpenLayers.Format.KML({ 
            extractStyles: true, 
            extractAttributes: true              
        })           
    })           
}); 

KML 文件:

<?xml version="1.0" encoding="UTF-8"?> 
<kml xmlns="http://earth.google.com/kml/2.2"> 
<Document> 
    <description><![CDATA[]]></description> 
    <Placemark> 
        <label>Name</label> 
        <description>Desc Name</description> 
        <Point> 
            <coordinates>-122.98676101, 49.16702016,0.000000</coordinates> 
        </Point> 
    </Placemark> 
</Document> 
</kml> 


标签:Map
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

关注我们

一个IT知识分享的公众号