谷歌地图事件 - 获取点击元素的父级

时间:2015-02-12 12:31:38

标签: javascript jquery html google-maps google-maps-api-3

我有能力制作新对象' claster'。在每个claster中都是google maps API的标记。我想点击这个标记并访问claster.icons []。我在我的函数声明中绑定了click事件。怎么做?

代码

function newClaster(_center){
        this.centerIco = _center;
        this.center = this.centerIco.getPosition();
        this.icons = [];
        this.icons.push(this.centerIco);
        this.addIcon = function(_icon){this.icons.push(_icon)};
        this.marker = new google.maps.Marker({
            position : this.center,
            icon : {
                url : 'map/circle.png',
                scaledSize : new google.maps.Size(40,40),
                size : new google.maps.Size(40,40),
            },
            map:map,
        });
        this.setCenter = function(ctr){
            this.centerIco = ctr;
            this.center = ctr.getPosition();
        }
        this.findCenter = function(){
            this.centerIco = this.icons[parseInt((this.icons.length)%2)];
            this.center = this.centerIco.getPosition();
        }

        google.maps.event.addListener(this.marker, 'click', function(){
            this.icons 
        });
    }

我绑定点击标记。

1 个答案:

答案 0 :(得分:0)

添加一个功能并在点击时将标记发送给它,然后您可以通过访问标记对象来获取图标:

 google.maps.event.addListener(this.marker, 'click', getIcons(this));

function getIcons(marker){
  console.log(marker.icons);
}