通过 KML 的 GMap:更改地标图钉的颜色
我们使用 GMap 和 KML feed 在地图上显示位置。这是一个示例:
http://jugendinfo.de/themen.php/873/geo.html
此地图上的图钉应为红色,因此我在 KML 生成器中使用以下 PHP4 代码来设置颜色:
$snode = $dom->create_element('Style');
$styleNode = $docNode->append_child($snode);
$styleNode->set_attribute('id', 'normalPlacemark');
$lnode = $dom->create_element('LabelStyle');
$labelNode = $styleNode->append_child($lnode);
$cnode = $dom->create_element('color');
$colorNode = $labelNode->append_child($cnode);
$colorText = $dom->create_text_node('ffcc0000');
$colorNode->append_child($colorText);
这会生成以下 KML 代码:
<Style id="normalPlacemark">
<LabelStyle>
<color>ffcc0000</color>
</LabelStyle>
</Style>
可以从此位置加载完整的 KML 源:
http://jugendinfo.de/feeds/geo.php/873.kml
但是,色彩风格似乎没有得到尊重。 KML 文档中没有任何样式元素,甚至不会显示图钉。如何更改颜色? API 文档似乎对这个问题非常有限,示例 PHP 代码片段甚至有很多错误,我无法得到任何如何让它工作的提示。大多数示例似乎适用于 Google 地球而不是 Google 地图。
We are using GMaps with a KML feed to display locations on a map. Here's an example:
http://jugendinfo.de/themen.php/873/geo.html
The pins on this map should be red, so I used the following PHP4 code in the KML generator to set the color:
$snode = $dom->create_element('Style');
$styleNode = $docNode->append_child($snode);
$styleNode->set_attribute('id', 'normalPlacemark');
$lnode = $dom->create_element('LabelStyle');
$labelNode = $styleNode->append_child($lnode);
$cnode = $dom->create_element('color');
$colorNode = $labelNode->append_child($cnode);
$colorText = $dom->create_text_node('ffcc0000');
$colorNode->append_child($colorText);
This results in the following KML code:
<Style id="normalPlacemark">
<LabelStyle>
<color>ffcc0000</color>
</LabelStyle>
</Style>
The full KML source can be loaded from this location:
http://jugendinfo.de/feeds/geo.php/873.kml
However, the color style seems not to be respected. Without any style element in the KML document, the pins are even not displayed. How do I change the color? The API docs seem to be very limited about this issue and example PHP code snippets are even pretty buggy, I couldn't get any hints how to get it working. Most examples seem to apply to Google Earth instead of Google Maps.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想更改图像,请使用 IconStyle。我认为颜色规范不适用于谷歌地图,但您可以为地标指定自定义图标图像网址。
参考:http://code.google.com/apis/kml/documentation /kmlreference.html#iconstyle
If you would like to change the image use IconStyle. I don't think that the color spec works in google maps but you can specify a custom icon image url for your placemark.
Reference : http://code.google.com/apis/kml/documentation/kmlreference.html#iconstyle