处理多个多边形对象 [英] Handling Multiple Polygon Object

查看:92
本文介绍了处理多个多边形对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Google地图上添加/删除多个多边形。在点击每个多边形时,我必须为相应的多边形显示一些信息窗口。点击多边形时,我无法保持多边形对象。



示例代码:

  for(var i = 0; i < multipleFlights.length; i ++)
{
google.maps.event.addListener(multipleFlights [i],'click',arrayfn); // $(multipleFlights [i])。click(function(){alert('x');});
}

如何获取中的当前多边形对象? arrayfn 函数。



预先感谢

解决方案

这是一个常见的问题,至少有两种解决方案:


  • 函数闭包(带有一个像createClickablePoly )将InfoWindow内容与Polygon相关联) - 示例


  • 包含由click监听器函数访问的InfoWindow内容的成员变量。



Am trying to add/remove multiple polygon on the google map. On clicking each polygon, I have to show some info window for the corresponding polygon. On clicking the polygon, I couldn't maintain the polygon object.

Sample code:

for (var i = 0; i < multipleFlights.length; i++) 
{
    google.maps.event.addListener(multipleFlights[i], 'click', arrayfn); // $(multipleFlights[i]).click(function () { alert('x'); });
}

How can I get the current polygon object in the arrayfn function .

Thanks in advance

解决方案

This is a common problem, there are at least two solutions:

  • function closure (with a function like createClickablePoly() to associate the InfoWindow contents with the Polygon) - example

  • member variable containing the InfoWindow content accessed by the click listener function.

这篇关于处理多个多边形对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆