在地图上使用KML显示名称

11

我能够使用KML显示多边形、圆等等,现在我想仅使用KML显示一些名称。这是可能的吗?


2
你是指在Google Earth、Google Maps还是其他平台上展示? - CodeMonkey
1个回答

10
如果您想在Google Earth地图上抑制通过KML显示标注的标签,则可以将LabelStyle添加到您的标注中,使用0比例(请参见下面示例中的sn_hide样式)。如果您想要在用户悬停或鼠标指向图标时才显示标签名称,则StyleMaps是最佳选择。
下面的示例中,第一个标注在地点面板中显示其名称,但使用LabelStyle从地图中隐藏了它。第二个标注#2使用StyleMap来隐藏标签,直到用户突出显示或悬停在图标上,该图标会触发显示标签的突出显示样式。第三个标注#3使用始终显示标签的默认样式。
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
    <Document>
        <name>Hide and show labels</name>
        <Style id="sn_hide">
            <LabelStyle>
                <scale>0</scale>
            </LabelStyle>
        </Style>
        <Style id="sh_style">
            <LabelStyle>
                <scale>1.1</scale>
            </LabelStyle>
        </Style>
        <StyleMap id="msn_hide">
            <Pair>
                <key>normal</key>
                <styleUrl>#sn_hide</styleUrl>
            </Pair>
            <Pair>
                <key>highlight</key>
                <styleUrl>#sh_style</styleUrl>
            </Pair>
        </StyleMap>

        <Placemark>
            <name>Placemark 1</name>
            <description>Label name always hidden</description>
            <styleUrl>#sn_hide</styleUrl>
            <Point>
                <coordinates>-119.232195,36.016021</coordinates>
            </Point>
        </Placemark>

        <Placemark>
            <name>Placemark 2</name>
            <description>Hover over place to show label</description>
            <styleUrl>#msn_hide</styleUrl>
            <Point>
                <coordinates>-119.2324,36.0155</coordinates>
            </Point>
        </Placemark>

        <Placemark>
            <name>Placemark 3</name>
            <description>Always showing</description>
            <Point>
                <coordinates>-119.232672,36.014837</coordinates>
            </Point>
        </Placemark>
    </Document>
</kml>

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