如何覆盖 Google 地图中的 KML 颜色?

2023-11-27

我正在通过 Google 地图的 V3 API 加载 KML 文件。正在使用 KML 文件中的颜色,但我想用我自己的颜色覆盖它。我实际上想对整个轨迹使用纯色。有没有办法做到这一点?


KML colors are based on Styleapi-doc tags that are defined either directly in the KML or using a reference to an external KML style file (similar to CSS). We use an external style file, so that the styles may be applied to multiple KML files.

这意味着在我们的 KML 中data文件中,您将找到如下条目:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
    <name>Country Borders</name>
    <open>1</open>
    <Placemark>
        <name>Russian Federation</name>
        <styleUrl>kml-styles.kml#red</styleUrl>
--- etc. ---

The styleUrl上面的标签实质上是说:去查看文件:kml-styles.kml并找到名为:red.

在我们的 KML 内style文件中,您将找到如下条目:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
    <name>KML Styles</name>
    <open>1</open>
    <Style id="red">
        <LineStyle>
            <color>7da00000</color>
            <width>1</width>
        </LineStyle>
        <PolyStyle>
            <color>7f0000ff</color>
        </PolyStyle>
    </Style>
    <Style id="green">
        <LineStyle>
            <color>FFFF00</color>
            <width>1</width>
        </LineStyle>
        <PolyStyle>
            <color>7f00aa00</color>
        </PolyStyle>
    </Style>
    --- etc. ---

It's important to note that KML colorapi-doc definitions include eight hex digits within their definition; two more digits than what is customary for other color definitions, because the first two hex digits define the color opacity (alpha).

The example at the KML Styleapi-doc (same as the link at the top), also shows how styles may be defined directly within the KML file that contains the data.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何覆盖 Google 地图中的 KML 颜色? 的相关文章

随机推荐