2010 年 12 月
目标
本教程将介绍 Google Earth 6.0 中引入的几个新的 KML 元素,以及如何使用这些元素为 LineStyle 创建复杂的制图。您将学习的元素包括 <gx:physicalWidth>
、<gx:outerColor>
、<gx:outerWidth>
和 <gx:drawOrder>
。
简介
在 Google 地球 6.0 版发布之前,您在为 LineString 定义复杂制图样式方面的能力有限。例如,如果您想为道路创建一种样式,其中 LineString 的中心颜色与边缘颜色不同,则必须绘制两个宽度不同的单独 LineString,即使这样也无法保证它们的绘制顺序。
以下示例演示了如何创建道路。 首先,道路将采用简约风格。然后,您将添加人行道。最后,您将添加高速公路天桥。
基本道路
第一个值得关注的元素是 <gx:physicalWidth>
,它允许您以米(而非像素)为单位设置 LineString 的宽度。在道路示例中,这意味着无论最终用户从哪个海拔高度查看道路,您都可以将道路的宽度设置为与基础影像相匹配。随着海拔升高,道路的像素会减少,从而产生一种效果,即只有在近距离放大时才能看到 LineString。如果您不想从远处强调小路,或者想确保地图数据始终与卫星图像匹配,这可能会很有用。
<?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom"> <Document> <name>Road Styling</name> <Style id="street"> <LineStyle> <color>ff235523</color> <gx:physicalWidth>12</gx:physicalWidth> </LineStyle> </Style> <Placemark> <styleUrl>#street</styleUrl> <LineString> <coordinates> -122.2442883478408,37.4347536724074,0 -122.2417741446485,37.43594997501623,0 -122.2414951359056,37.43611878445952,0 </coordinates> </LineString> </Placemark> </Document> </kml>

添加人行道
现在,您可以在道路边缘添加浅绿色,以表示人行道,从而添加 <gx:outerColor>
和 <gx:outerWidth>
元素。将道路总像素数的 25% 设置为浅灰色。
<?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom"> <Document> <name>Road Styling</name> <Style id="street_sidewalk"> <LineStyle> <color>ff235523</color> <gx:physicalWidth>12</gx:physicalWidth> <gx:outerColor>ff55ff55</gx:outerColor> <gx:outerWidth>0.25</gx:outerWidth> </LineStyle> </Style> <Placemark> <styleUrl>#street_sidewalk</styleUrl> <LineString> <coordinates> -122.2442883478408,37.4347536724074,0 -122.2417741446485,37.43594997501623,0 -122.2414951359056,37.43611878445952,0 </coordinates> </LineString> </Placemark> </Document> </kml>

高速公路立交桥
现在,您已经有了一条基本道路,接下来可以尝试制作高速公路立交桥了。此箱线图将采用浅橙色,并带有深橙色中位线。这里新增的关键点是在 <LineSring>
中包含 <gx:drawOrder>
为 1(默认值为 0)的设置,以确保高速公路将渲染在道路之上。如果您要构建更复杂的公路立交桥(或任何需要两个以上重叠 LineString 的地图),只需为要渲染在顶部的 LineString 将 <gx:drawOrder>
设置为更高的值即可。
<?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom"> <Document> <name>Road Styling</name> <Style id="street_sidewalk"> <LineStyle> <color>ff235523</color> <gx:physicalWidth>10</gx:physicalWidth> <gx:outerColor>ff55ff55</gx:outerColor> <gx:outerWidth>0.25</gx:outerWidth> </LineStyle> </Style> <Style id="highway"> <LineStyle> <color>cc1447ff</color> <gx:physicalWidth>20</gx:physicalWidth> <gx:outerColor>cc1473ff</gx:outerColor> <gx:outerWidth>0.75</gx:outerWidth> </LineStyle> </Style> <Placemark> <styleUrl>#street_sidewalk</styleUrl> <LineString> <coordinates> -122.2442883478408,37.4347536724074,0 -122.2417741446485,37.43594997501623,0 -122.2414951359056,37.43611878445952,0 </coordinates> </LineString> </Placemark> <Placemark> <styleUrl>#highway</styleUrl> <LineString> <gx:drawOrder>1</gx:drawOrder> <coordinates> -122.2442692500139,37.43634904345254,0 -122.2415928723012,37.43416417520744,0 </coordinates> </LineString> </Placemark> </Document> </kml>

后续操作
能够使用多种颜色描述单个 LineString,再加上对渲染顺序的控制,让您能够创建以前无法实现的复杂线条制图。无论您是要建造高速公路天桥,还是要完成抽象艺术项目,都可以尽情使用这些样式规则!