本文介绍了使用< BaloonStyle>和< LableStyle>一起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是KML的新手,似乎转圈了.希望有人能帮忙.

I am new to KML and seem to be going round in circles. Hope someone can help.

我想显示一个HTML气球并摆脱丑陋的行车路线.我正在使用"BalloonStyle"来做到这一点.

I want to show a HTML balloon and get rid of the ugly driving directions. I am using 'BalloonStyle' to do this.

也希望能够隐藏地标标签,因此我要使用"LabelStyle"来实现.

Also want to be able to hide the placemark label, so am using 'LabelStyle' to do this.

我可以将它们分开工作,但是似乎无法使它们一起工作以达到预期的结果.

I can get these to work separately, but don't seem to be able to get them to work together to achieve the desired result.

下面是复制该问题的示例代码.难道我做错了什么?还是这两个项目不能同时使用?如果是这样,还有另一种方法来获得期望的结果(HTML气球和隐藏标签)吗?

Below is sample code which replicates the issue. Am I doing something wrong? Or do these two items just not work together? If so, is there another way to get the desired result (a HTML Balloon and a hidden label)?

谢谢

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
  <Style id="randomLabelColor">
      <LabelStyle>
         <color>ff0000cc</color>
         <colorMode>random</colorMode>
        <scale>1.5</scale>
      </LabelStyle>
  </Style>

  <Style id="FEXBalloonStyle">
  <BalloonStyle>
     <bgColor>ffffff</bgColor>
     <text><![CDATA[<b><font color="#CC0000" size="+2">$[name]</font></b>
     <br><br/><font face="Courier">$[description]</font><br/><br/><br/><br/>]]></text>
     </BalloonStyle>
  </Style>

  <Placemark>
    <name>LabelStyle.kml</name>

  <styleUrl>#randomLabelColor</styleUrl>
  <styleUrl>#FEXBalloonStyle</styleUrl>

  <Point>
     <coordinates>-122.367375,37.829192,0</coordinates>
  </Point>
</Placemark>

</Document>
</kml>

推荐答案

您只能为地标设置一个 styleUrl.如果要同时在<LabelStyle><BalloonStyle>上应用单个地标,则必须将它们设置为相同的样式:

You can only have one styleUrl for a Placemark. If you want to have both the <LabelStyle> and <BalloonStyle> applied a single place mark, you have to put them in the same style:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
  <Style id="randomLabelColor">
  </Style>

  <Style id="FEXBalloonStyle">
    <LabelStyle>
      <color>ff0000cc</color>
      <colorMode>random</colorMode>
      <scale>1.5</scale>
    </LabelStyle>
    <BalloonStyle>
      <bgColor>ffffff</bgColor>
      <text><![CDATA[<b><font color="#CC0000" size="+2">$[name]</font></b>
      <br><br/><font face="Courier">$[description]</font><br/><br/><br/><br/>]]></text>
    </BalloonStyle>
  </Style>

  <Placemark>
    <name>LabelStyle.kml</name>
    <styleUrl>#FEXBalloonStyle</styleUrl>
    <Point>
      <coordinates>-122.367375,37.829192,0</coordinates>
    </Point>
  </Placemark>

</Document>
</kml>

这篇关于使用&lt; BaloonStyle&gt;和&lt; LableStyle&gt;一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 20:00