google-maps - 如何为谷歌地图图层中的所有标记设置标签颜色?
问题描述
我看过一些相关的问题,但没有一个完全回答我的问题。
这提到了 Javascript: How to override KML colors in Google Map?
这提到了 KML 颜色代码助手,但没有给出应用它的解决方案:Google Maps KML: 8-Digit Hex Code
KML 参考建议使用 a<Style>
但没有用:https ://developers.google.com/kml/documentation/kmlreference#balloonstyle
有没有办法为给定图层的所有标记设置颜色(或样式),以便将其与其他图层区分开来?
解决方案
这并不完美——我宁愿在 UI 中有一种简单的点击式方法来执行此操作——但是就这样吧。
让我们以美国国家公园的一层标记为例;取自维基百科:https ://tools.wmflabs.org/kmlexport?article=List_of_national_parks_of_the_United_States
我已使用导入工具将这些添加到新地图中
我认为最简单的方法是将所有所需的样式应用于 UI 中的单个标记,例如第一个标记。为简单起见,我将其设为橙色:
现在,将图层导出到 KML 并打开 KML 文件。这是该文件的压缩版本:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>National parks</name>
<Style id="icon-1899-0288D1-normal">
<IconStyle>
<color>ffd18802</color>
<!-- more attributes -->
</IconStyle>
<LabelStyle>
<scale>0</scale>
</LabelStyle>
</Style>
<Style id="icon-1899-0288D1-highlight">
<!-- similar markup -->
</Style>
<StyleMap id="icon-1899-0288D1">
<Pair>
<key>normal</key>
<styleUrl>#icon-1899-0288D1-normal</styleUrl>
</Pair>
<Pair>
<key>highlight</key>
<styleUrl>#icon-1899-0288D1-highlight</styleUrl>
</Pair>
</StyleMap>
<!-- Two more <Style> tags for -normal and -highlight -->
<Style id="icon-1899-F57C00-normal"></Style>
<Style id="icon-1899-F57C00-highlight"></Style>
<!-- Another <StyleMap> -->
<StyleMap id="icon-1899-F57C00"></StyleMap>
<Placemark>
<name>Acadia</name>
<description>...</description>
<styleUrl>#icon-1899-F57C00</styleUrl>
<Point>...</Point>
</Placemark>
<Placemark>
<name>National Park of American Samoa</name>
<description>...</description>
<styleUrl>#icon-1899-0288D1</styleUrl>
<Point></Point>
</Placemark>
<!-- More <Placemark>s for the other parks -->
</Document>
</kml>
从这里开始,我们只需将<styleUrl>
所有标签中的参考样式替换为 Acadia 使用的样式即可。这是一个简单的查找和替换。我们也可以删除过时<Style>
的 s,<StyleMap>
但这并不是绝对必要的。之后,保存更新的 KML 并将其重新导入 Google 地图,我们就完成了:
推荐阅读
- aws-lambda - Serilog CloudWatchSink 不适用于 Lambda 函数
- javascript - regex to mask phone number such that except first 2 and last 2 characters in a number are replaced with * in javascript
- jmeter - Opco 的 Jmeter 脚本
- apache-spark - 根据另一个表spark sql计算每一行
- ejs - 如何阻止 csslint 和 jshint 在 Atom 中对我的 EJS 进行 linting?
- openstack - Openstack HEAT:通过 HEAT 模板手动将新实例添加到现有堆栈
- python - python - 列出熊猫数据框
- android - 如何使底部导航栏可见?
- php - PHP中变量周围的括号有什么作用?
- python - Discord Python - 如何让 BOT 说出频道的所有消息?