我目前正在使用JAK (Java API for KML)与Google Earth和自定义的KML文件进行交互。我可以使用placemark p.getName()或point.getCoordinates();在列表中获取/设置Placemark的名称、描述、坐标等,但我在获取用于图标的图像的url时遇到了麻烦。例如,如果我的kml文件中有这个placemark (包含在一个文档中,然后是整个KML标记):
<Placemark>
<name>Isla de Roatan</name>
<description>
Cruise Stop
</description>
<Style>
<IconStyle>
<Icon>
<href>http://maps.google.com/mapfiles/kml/shapes/airports.png</href>
</Icon>
</IconStyle>
</Style>
<Point>
<coordinates>-86.53,16.337461,0</coordinates>
</Point>
</Placemark>我如何抓取png url,比如放入一个单独字符串对象?我在Style中看到了.getIconStyle,在IconStyle中看到了.getIcon,在图标中看到了.getHttpQuery,但从Placemark/Feature中查看样式时,除了.getStyleSelector和.getStyleUrl之外,没有什么可链接的。你能用其中的一个或一个样式图来做吗?我不确定我是否完全掌握了它们各自的用途。另外,反过来,如何设置此URL?谢谢你的帮助!
发布于 2012-07-03 13:05:41
Feature.getStyleSelector()返回一个List<StyleSelector>。Style是StyleSelector的子类,因此您的样式应该在此列表中(以及为该要素定义的任何其他样式和StyleMaps )。
设置样式(和图标URL):
Placemark placemark = ...;
Style myStyle = new Style().withId("my_style");
myStyle.withIconStyle(new IconStyle().withIcon(new Icon().withHref("http://someurl")));
placemark.addToStyleSelector(myStyle);获取样式(和图标URL):
for (StyleSelector styleSelector : placemark.getStyleSelector())
{
if (styleSelector.getId() == "my_style")
{
String href = ((Style)styleSelector).getIconStyle().getIcon().getHref();
}
}https://stackoverflow.com/questions/11300148
复制相似问题