sencha map infowindow 的问题

17 篇文章 0 订阅

在使用map的过程中,发现多个地标的infowindow是无法关闭的

因为在sencha中不如在js中可以设定多个全局变量来控制,所以google搜来的教程大多不可用

写下我的解决方案

showinfomessage:function (map, markers, index) {
        google.maps.event.addListener(markers[index], 'click', function (event) {
            if (markers) {
                for (i in markers) {
                    if(markers[i].infowindow) markers[i].infowindow.close();
                }
            }
            markers[index].infowindow.open(map, markers[index]);
        });
    },
    onMapMaprender:function (mapview, gmap, options) {
         var markers = [];
        var i =0;       
        store.load(function (records, operation, success) {
            store.each(function (record) {
                i=i+1;
                markers[i]= new google.maps.Marker({
                    position:new google.maps.LatLng([record.get('latitude')], [record.get('longitude')]),
                    map:gmap,
                    draggable:true,
                    title:record.get('name'),
                    animation:google.maps.Animation.DROP
                });
                markers[i].infowindow = new google.maps.InfoWindow({
                    content: contentString
                });
                mapview.showinfomessage(gmap,  markers,i);
            })
        });
    }

讲数组作为参数传递

有人会问为什么不在一个函数里写完,发现

google.maps.event.addListener
如果不在另外一个函数里会只增加到一个marker上

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值