谷歌地图 OpenLayers Kml 图标名称

3

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>

我得到了这个输出:

enter image description here

但是我想要的是这个:

enter image description here

所以你可以看到点的名字。KML文件有什么问题吗?

谢谢!

3个回答

2

我不知道这是否有所帮助,但我发现你想使用的方法不起作用。我能够在javascript中以编程方式设置此选项。这允许您在自己创建的红色圆形图标正上方拥有一个标签。

希望这可以帮到您!

javascript(减去其他构建地图对象等代码):

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>

0

我发现在Google Earth中,地标名称的标签默认以白色和完全不透明度呈现。尝试在你的样式中指定一个Label Style元素来获取该颜色和不透明度。

<?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>
        <LabelStyle>
            <color>ffff55ff</color>
        </LabelStyle>
    </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>

那么这一定是与OpenLayers有关的特定问题。我认为值得一试,但遗憾的是,我不熟悉OpenLayers。抱歉。 - Stealth Rabbi

0

这是我解决问题的方法...希望能够对你有所帮助。

          var layerData = new OpenLayers.Layer.Vector("test1", {
                renderers: ["SVG", "Canvas", "VML"],
                strategies: [new OpenLayers.Strategy.Save({
                    auto:true
                }),new OpenLayers.Strategy.Cluster({
                    distance: clusteringDistance, 
                    threshold: clusteringThreshold, 
                    shouldCluster: function(cluster, feature) {
                        updateFeatureStyle(feature);
                        if (feature.geometry.CLASS_NAME == "OpenLayers.Geometry.Point" && boundArea >= maxBoundAreaForClustering) {
                            return OpenLayers.Strategy.Cluster.prototype.shouldCluster.apply(this, arguments);
                        } else {
                            return false;
                        }
                    }
                })],
                styleMap: clusterStyle                              
            });
            blankLayer = true;   
            layerData.setVisibility(false);                                     

function updateFeatureStyle(feature) {
    feature.style.label = "\n\n " + feature.attributes.name;            
    feature.style.labelAlign = 'ct';
    feature.style.fontColor = 'red';
    feature.style.fontFamily = 'Arial';
    feature.style.fontSize = '10px';
    feature.style.fontOpacity = 1;
    feature.style.graphicTitle = feature.attributes.name;                           
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接