简体   繁体   English

将HTML链接添加到Google Maps Circle元素

[英]Add HTML Link to Google Maps Circle Element

I am sure there is a simple way to do this, but I can't seem to find it within the Google Maps online documentation. 我敢肯定有一个简单的方法可以做到这一点,但是我似乎在Google Maps在线文档中找不到它。 I have a map with several circles and the idea is that clicking on the circle will open up a new HTML page. 我有一个带有多个圆圈的地图,其想法是单击圆圈将打开一个新的HTML页面。

For each circle..... 对于每个圈子.....

Lat Long is defined: Lat Long的定义是:

var NZNorth=new google.maps.LatLng( -38.929764,176.009002);

Circle Variables: 圆变量:

var Circle1 = new google.maps.Circle({
center:NZNorth,
 radius:250000,
 strokeColor:"#FA0014",
 strokeOpacity:1,
 strokeWeight:1,
 fillColor:"#FA0014",
 fillOpacity:0.2
 });

Call the Circle: 致电圈子:

Circle1.setMap(map); 

So to add a hyperlink onclick of the circle what do I need to do? 因此,要添加圆圈的onclick超链接,我需要做什么? I am not sure if I have to declare the link for each circle and then include an onclick function in each circle variable? 我不确定是否必须为每个圆声明链接,然后在每个圆变量中包含onclick函数?

As always thanks for your help! 一如既往的感谢您的帮助!

Incase anyone has the same problem, add the URL to your variable 如果有人遇到相同的问题,请将URL添加到您的变量中

var Circle1 = new google.maps.Circle({
center:NZNorth,
radius:250000,
strokeColor:"#FA0014",
strokeOpacity:1,
strokeWeight:1,
fillColor:"#FA0014",
fillOpacity:0.2,
URL:'http://www.bbc.co.uk'
});

Then add the listener! 然后添加监听器!

google.maps.event.addListener(Circle1, 'click', function() {

 window.location = Circle1.URL; 

});

Circle throws an "click" event. Circle引发“点击”事件。 So you must add a listener to it. 因此,您必须为其添加一个侦听器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM