javascript 如何覆盖 Google 地图中的 KML 颜色?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10610697/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to override KML colors in Google Map?
提问by TruMan1
I am loading a KML file via Google Map's V3 API. The colors in the KML file are being used but I would like to override it with my own color. I actually want to use a solid color for the whole trace. Is there a way to do this?
我正在通过 Google Map 的 V3 API 加载 KML 文件。正在使用 KML 文件中的颜色,但我想用我自己的颜色覆盖它。我实际上想为整个跟踪使用纯色。有没有办法做到这一点?
回答by Sean Mickey
KML colors are based on Style
api-doctags 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 颜色基于Style
api-doc标签,这些标签直接在 KML 中定义或使用对外部 KML 样式文件(类似于 CSS)的引用。我们使用外部样式文件,以便样式可以应用于多个 KML 文件。
This means that within our KML datafiles, you will find entries such as this:
这意味着在我们的 KML数据文件中,您会发现如下条目:
<?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
tag above essentially says: go look in the file: kml-styles.kml
and find the style named: red
.
styleUrl
上面的标签本质上说:去看看文件:kml-styles.kml
并找到名为:的样式red
。
And within the our KML stylefile, you will find entries such as this:
在我们的 KML样式文件中,您会找到如下条目:
<?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-docdefinitions include eighthex 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).
请务必注意,KML 颜色api-doc定义在其定义中包含八个十六进制数字;比其他颜色定义的常用数字多两位,因为前两个十六进制数字定义了颜色不透明度 (alpha)。
The example at the KML Style
api-doc(same as the link at the top), also shows how styles may be defined directly within the KML file that contains the data.
KML Style
api-doc 中的示例(与顶部的链接相同)还显示了如何直接在包含数据的 KML 文件中定义样式。
回答by CG_DEV
KML colors work like so,
KML 颜色的工作原理是这样的,
<color>AABBGGRR</color>
AA = alpha opacity
BB = blue
GG = gren
RR = red
The range is from 00 -> ff
RGB for white = 255, 255, 255, hex -> #ffffff
RGB for yellow is 255,255,0, hex -> #ffff00
Hex can also been seen as
十六进制也可以看作
#RRGGBB
You can easily move the colors around to work for KML
您可以轻松地移动颜色以适用于 KML
so yellow in KML would be
所以 KML 中的黄色会是
<color>ff00FFFF</color>
<color>AABBGGRR</color>
This has been working for me.
这对我有用。
Also, for borders use below.
另外,对于下面的边框使用。
<outline>1</outline>
https://developers.google.com/kml/documentation/kmlreference
https://developers.google.com/kml/documentation/kmlreference
回答by shovemedia
KML is XML, so you'd use XSL (yeah, me neither) or PHP or (depending on the specifics) JavaScript to parse / transform / re-serialize back to KML.
KML 是 XML,因此您将使用 XSL(是的,我都没有)或 PHP 或(取决于具体情况)JavaScript 来解析/转换/重新序列化回 KML。