在使用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上