Changing KML Placemark icons on click in Google Maps API V3

巧了我就是萌 提交于 2019-12-04 18:46:03

I'm currently working on the exact same thing and, in my case, I could directly edit the KML file. If you have access to it and can edit it, here's what I did:

1) Right under <document> tag, paste something like this:

<Style id="desired_id">
  <IconStyle>
    <Icon>
      <href>http://www.yourwebsite.com/your_preferred_icon.png</href>
      <scale>1.0</scale>
    </Icon>    
  </IconStyle>
</Style>

The scale parameter is not supported in Google Maps at the moment. Here you can check all supported elements of KML in Google Maps:

http://code.google.com/intl/en-EN/apis/kml/documentation/kmlelementsinmaps.html

And here you've got some info about compatibility between KML and GMaps:

http://code.google.com/intl/en-EN/apis/kml/documentation/mapsSupport.html

2) Once you've defined you're style, you can refer to it on each Placemark item by adding the following to it:

<styleUrl>#desired_id</styleUrl>

Now, all your placemarks should display showing your custom icon.

Hope it helps.

EDIT: Sorry I didn't see the on click part. This isn't quite what you need then. I'll leave it in case it helps someone else. Sorry for that.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!