2011-08-09 59 views

回答

1

你可以使用自定义图标呈现伪名(您所需要的文本的图像),并以同样的方式另一卷在伪名。

这就是所谓的“风格为高亮显示的图标”,使用它,你需要创建并上传两个JPG图像

nameImageOver.jpg 

nameImageNormal.jpg 

的KML看起来就像这样:

<?xml version="1.0" encoding="UTF-8"?> 
<kml xmlns="http://www.opengis.net/kml/2.2"> 
    <Document> 
    <name>Highlighted Icon</name> 
    <description>Mouse over to see the swap</description> 
    <Style id="highlightPlacemark"> 
     <IconStyle> 
     <Icon> 
     <href>http://www.yourserver.com/nameImageOver.jpg</href> 
     </Icon> 
     </IconStyle> 
    </Style> 
    <Style id="normalPlacemark"> 
     <IconStyle> 
     <Icon> 
      <href>http://www.yourserver.com/nameImageNormal.jpg</href> 
     </Icon> 
     </IconStyle> 
    </Style> 
    <StyleMap id="exampleStyleMap"> 
     <Pair> 
     <key>normal</key> 
     <styleUrl>#normalPlacemark</styleUrl> 
     </Pair> 
     <Pair> 
     <key>highlight</key> 
     <styleUrl>#highlightPlacemark</styleUrl> 
     </Pair> 
    </StyleMap> 
    <Placemark> 
     <styleUrl>#exampleStyleMap</styleUrl> 
     <Point> 
     <coordinates>-122.0856545755255,37.42243077405461,0</coordinates> 
     </Point> 
    </Placemark> 
    </Document> 
</kml> 
+0

在我的情况下,文本是动态的不同的地标。您的解决方案适用于静态标题,或者您想为每个可能的组合创建一个图像。我会将其标记为正确,因为在某些情况下它是可行的。 –

+0

你可以使用像gdlib这样的东西在服务器上动态生成图像。谷歌甚至有免费的服务来做到这一点。只需提供您需要的文本作为查询。请参阅http://groups.google.com/group/google-chart-api/web/chart-type-for-text-with-outline?pli=1 – Fraser

0

我已经使用Google Earth API实现了这一点。不知道这是怎么使用KML ...

// On mouse over - show name 
google.earth.addEventListener(placemark, 'mouseover', function(event) { 
    placemark.setName('My Placemark Label'); 
}); 
// On mouse out - hide (remove) name 
google.earth.addEventListener(placemark, 'mouseout', function(event) { 
    placemark.setName(''); 
});