Using <BaloonStyle> and <LableStyle> together

狂风中的少年 提交于 2019-12-24 09:38:09

问题


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

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

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.

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)?

Thank you

<?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> 

回答1:


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> 


来源:https://stackoverflow.com/questions/17554016/using-baloonstyle-and-lablestyle-together

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!