【问题标题】:Set fill color in placemark from KML file in Android在 Android 的 KML 文件中设置地标的填充颜色
【发布时间】:2015-09-12 22:08:17
【问题描述】:

我想在 GoogleMap 中为地标设置填充颜色,但它不起作用。我使用来自fill polygons in google map/earth 的 KML 我的结果是: http://i.imgur.com/ed27B0I.jpg?1

我的代码是:

KmlLayer kmlLayer = new KmlLayer(googleMap,R.raw.test,getActivity().getApplication());
kmlLayer.addLayerToMap();

KML 文件是:

<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
 <Document>
    <Style id="s1">
      <LineStyle>
        <color>7f0000ff</color>
        <width>4</width>
      </LineStyle>
      <PolyStyle>
        <color>7f0000ff</color>
        <colorMode>normal</colorMode>
        <fill>1</fill>
        <outline>1</outline>
      </PolyStyle>
    </Style>
    <name>All isolation countries</name>
    <description>All isolation countries</description>
    <Placemark>
      <styleUrl>#s1</styleUrl>
      <name>Indonesia</name>
      <Polygon>
      <tessellate>1</tessellate>
        <extrude>1</extrude>
        <altitudeMode>clampedToGround</altitudeMode>
        <outerBoundaryIs>
          <LinearRing>
            <coordinates>102.4918975830078,1.259721994400024,0 102.3088989257813,1.420554995536804,0 102.1374969482422,1.448055028915405,0 102.0785980224609,1.485000014305115,0 101.9944000244141,1.600000023841858,0 102.0065994262695,1.619166970252991,0 102.4349975585938,1.527500033378601,0 102.4779968261719,1.502221941947937,0 102.4954986572266,1.436308026313782,0 102.504997253418,1.273888945579529,0 102.4918975830078,1.259721994400024,0</coordinates>
          </LinearRing>
        </outerBoundaryIs>
      </Polygon>
    </Placemark>
    <Placemark>
      <styleUrl>#s1</styleUrl>
      <name>Ecuador</name>
      <Polygon>
      <tessellate>1</tessellate>
        <extrude>1</extrude>
        <altitudeMode>clampedToGround</altitudeMode>
        <outerBoundaryIs>
          <LinearRing>
            <coordinates>-90.61167907714844,-0.3755556046962738,0 -90.77166748046875,-0.344166785478592,0 -90.87222290039063,-0.2652778923511506,0 -90.79332733154297,-0.149444505572319,0 -90.77362060546876,-0.1550000011920929,0 -90.58556365966797,-0.2455555945634842,0 -90.55029296875,-0.3091666996479035,0 -90.61167907714844,-0.3755556046962738,0</coordinates>
          </LinearRing>
        </outerBoundaryIs>
      </Polygon>
    </Placemark>
    </Document>
    </kml>

【问题讨论】:

    标签: android google-maps kml


    【解决方案1】:

    您是否浏览过此受支持元素列表? https://developers.google.com/kml/documentation/kmlelementsinmaps

    我看到您使用了一些不受支持的元素(例如高度模式)。从理论上讲,如果您这样做,它应该会静默失败,但似乎它可能会影响整体结果(请参阅此issue 的答案)。

    我也认为这就是@JeremyA1 的答案可能不起作用的原因,因为 StyleMap 也不支持。

    无论如何,请告诉我们您是如何解决的,因为这将非常有帮助。

    【讨论】:

      【解决方案2】:

      首先,您需要缺少的标签。试试这个更新的代码

      <?xml version="1.0" encoding="utf-8"?>
      <kml xmlns="http://www.opengis.net/kml/2.2">
       <Document>
          <StyleMap id="s1">
              <Pair>
                  <key>normal</key>
                  <styleUrl>#s1-temp</styleUrl>
              </Pair>
              <Pair>
                  <key>highlight</key>
                  <styleUrl>#s1-temp</styleUrl>
              </Pair>
          </StyleMap>
          <Style id="s1-temp">
              <IconStyle>
                  <scale>1.0</scale>
                  <Icon>
                      <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
                  </Icon>
              </IconStyle>
              <PolyStyle>
                  <color>7f0000ff</color>
                  <outline>0</outline>
              </PolyStyle>
          </Style>
          <name>All isolation countries</name>
          <description>All isolation countries</description>
          <Placemark>
            <styleUrl>#s1-temp</styleUrl>
            <name>Indonesia</name>
            <Polygon>
            <tessellate>1</tessellate>
              <extrude>1</extrude>
              <altitudeMode>clampedToGround</altitudeMode>
              <outerBoundaryIs>
                <LinearRing>
                  <coordinates>102.4918975830078,1.259721994400024,0 102.3088989257813,1.420554995536804,0 102.1374969482422,1.448055028915405,0 102.0785980224609,1.485000014305115,0 101.9944000244141,1.600000023841858,0 102.0065994262695,1.619166970252991,0 102.4349975585938,1.527500033378601,0 102.4779968261719,1.502221941947937,0 102.4954986572266,1.436308026313782,0 102.504997253418,1.273888945579529,0 102.4918975830078,1.259721994400024,0</coordinates>
                </LinearRing>
              </outerBoundaryIs>
            </Polygon>
          </Placemark>
          <Placemark>
            <styleUrl>#s1-temp</styleUrl>
            <name>Ecuador</name>
            <Polygon>
            <tessellate>1</tessellate>
              <extrude>1</extrude>
              <altitudeMode>clampedToGround</altitudeMode>
              <outerBoundaryIs>
                <LinearRing>
                  <coordinates>-90.61167907714844,-0.3755556046962738,0 -90.77166748046875,-0.344166785478592,0 -90.87222290039063,-0.2652778923511506,0 -90.79332733154297,-0.149444505572319,0 -90.77362060546876,-0.1550000011920929,0 -90.58556365966797,-0.2455555945634842,0 -90.55029296875,-0.3091666996479035,0 -90.61167907714844,-0.3755556046962738,0</coordinates>
                </LinearRing>
              </outerBoundaryIs>
            </Polygon>
          </Placemark>
         </Document>
       </kml>` 
      

      【讨论】:

        【解决方案3】:

        从此代码中删除颜色模式、填充和轮廓:

        <PolyStyle>
            <color>7f0000ff</color>
            <colorMode>normal</colorMode>
            <fill>1</fill>
            <outline>1</outline>
          </PolyStyle>
        

        应该是这样的:

        <PolyStyle>
            <color>7f0000ff</color>
          </PolyStyle>
        

        结果如下:

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2013-07-01
          • 2019-01-16
          • 2012-04-24
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多