再会。
我为谷歌地图使用 Gmap3 jQuery 插件,我试图让标记与标签一起工作,但是每次我添加标记时,标签(从示例标签中过滤)都不起作用。这是我正在处理的网站上的代码(使用 Wordpress):
$(function(){
var data = [],
tmp = {},
r, k,
pubtypes = [],
$dpts = $("#pubtype"),
icons = {"Certifikované provozovny":'provozovna',"Tankovny":'tankovna'};
$.each(villes, function(i, ville){
data.push({
lat: ville.lat,
lng: ville.lng,
tag: ville.pubtype,
data: ville,
options: { icon: new google.maps.MarkerImage('<?php bloginfo( 'template_directory' ); ?>/gfx/pin-'+icons[ville.pubtype]+'.png')
}
});
tmp[ ville.pubtype ] = true;
});
for(r in tmp){
pubtypes.push(r);
}
pubtypes = pubtypes.sort();
for(k in pubtypes){
$dpts.append('<input id="chk'+k+'" type="checkbox" checked><label for="chk'+k+'">'+pubtypes[k]+'</label><br />');
}
$('input', $dpts).change(function(){
var pubtype = $('label[for='+$(this).attr('id')+']', $dpts).html(),
checked = $(this).is(':checked'),
map = $('#test1').gmap3('get'),
markers;
markers = $('#test1').gmap3({
action:'get',
name:'marker',
all: true,
tag:pubtype
});
$.each(markers, function(i, marker){
marker.setMap( checked ? map : null);
});
});
$('#test1').gmap3(
{ action:'init',
options:{
center:[49.743341,15.336227],
zoom: 7,
streetViewControl: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
},{
action:'addMarkers',
radius:100,
markers: data,
maxZoom:13,
radius:40,
clusters:{
// This style will be used for clusters with more than 0 markers
0: {
content: '<div class="cluster cluster-1">CLUSTER_COUNT</div>',
width: 53,
height: 52
},
// This style will be used for clusters with more than 20 markers
20: {
content: '<div class="cluster cluster-2">CLUSTER_COUNT</div>',
width: 56,
height: 55
},
// This style will be used for clusters with more than 50 markers
50: {
content: '<div class="cluster cluster-3">CLUSTER_COUNT</div>',
width: 66,
height: 65
}
},
marker: {
options: {
//icon: new google.maps.MarkerImage('<?php bloginfo( 'template_directory' ); ?>/gfx/beer.png')
//icon: new google.maps.MarkerImage('<?php bloginfo( 'template_directory' ); ?>/gfx/'+marker+'.png')
},
events:{
click: function(marker, event, data) { infoWindowOpen($this, marker, data) }
}
}
});
});
感谢您的每一个小帮助和建议。