【问题标题】:Google Earth: Retrieving icon URL from KML using JAKGoogle 地球:使用 JAK 从 KML 检索图标 URL
【发布时间】:2012-07-03 05:59:23
【问题描述】:

我目前正在使用 JAK(KML 的 Java API)与 Google 地球和自定义 KML 文件进行交互。我可以使用 Placemark p.getName() 或 point.getCoordinates() 之类的东西获取/设置地标的名称、描述、坐标;进入列表等。但我遇到的问题是获取用于图标的图像的 url。例如,如果我的 kml 文件中有这个地标(包含在 Document 中,然后是整个 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 说,放入一个单独的 String 对象?我在 Style 中看到了 .getIconStyle,在 IconStyle 中看到了 .getIcon,在 Icon 中看到了 .getHttpQuery,但是除了 .getStyleSelector 和 .getStyleUrl 之外,没有任何东西可以链接到从 Placemark/Feature 中查看 Style。您可以使用其中一个或样式图来做到这一点吗?我不确定我是否完全掌握其中每一个的作用。另外反过来,可以做些什么来设置这个 URL?感谢您的帮助!

【问题讨论】:

    标签: api url kml google-earth jak


    【解决方案1】:

    Feature.getStyleSelector() 返回一个List&lt;StyleSelector&gt;StyleStyleSelector 的子类,因此您的样式应该在此列表中(以及为该功能定义的任何其他样式和样式映射)。

    设置样式(和图标 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();
        }
    }
    

    【讨论】:

    • 谢谢!我做了一些事情来适应我的需要,但是 ((Style)styleSelector).otherstuff 是让我绊倒的东西。再次感谢:)
    • 谢谢,这帮助了我。我还找到了一个链接到所有标准图标的页面,以防有人需要标准图标的 URL。 kml4earth.appspot.com/icons.html
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多