0
我當時過濾使用jQuery UI的地圖。所以舊版本正在完美。下面的代碼,我使用舊版本:過濾使用jQuery UI映射
$('#map_canvas').gmap({ 'center':new google.maps.LatLng(43.730531,-79.416927), 'callback': function() {
$.getJSON('path to json', 'category=activity', function(data) {
$.each(data.markers, function(i, m) {
$('#map_canvas').gmap('addMarker', { 'tag': m.area, 'position': new google.maps.LatLng(m.latitude, m.longitude), 'center': new google.maps.LatLng(m.latitude, m.longitude), 'bounds': true })
.click(function() { $('#map_canvas').gmap('openInfoWindow', { 'content': m.content }, this); });
});
});
$("#some").change(function() {
var bounds = new google.maps.LatLngBounds();
var tag = $(this).val();
if (tag == '*') {
$('#map_canvas').gmap('findMarker', 'tag', tag, function(found, marker) {
marker.setVisible(true);
bounds.extend(marker.position);
marker.map.fitBounds(bounds);
});
} else {
$('#map_canvas').gmap('findMarker', 'tag', tag, function(found, marker) {
if (found) {
marker.setVisible(true);
bounds.extend(marker.position);
marker.map.fitBounds(bounds);
} else {
marker.setVisible(false);
}
});
}
$('#map_canvas').gmap('option', 'center', bounds.getCenter());
});
}
但是當我切換到新版本時,我無法進行過濾。我正在使用下面的代碼來過濾新版本:
$('#map_canvas').gmap({ 'center':new google.maps.LatLng(43.730531,-79.416927), 'callback': function() {
$.getJSON('path to json', 'category=activity', function(data) {
$.each(data.markers, function(i, m) {
$('#map_canvas').gmap('addMarker', { 'tag': m.area, 'position': new google.maps.LatLng(m.latitude, m.longitude), 'center': new google.maps.LatLng(m.latitude, m.longitude), 'bounds': true })
.click(function() { $('#map_canvas').gmap('openInfoWindow', { 'content': m.content }, this); });
});
});
$("#some").change(function() {
var bounds = new google.maps.LatLngBounds();
var tag = $(this).val();
if (tag == '*') {
$('#map_canvas').gmap('find', 'markers', { 'property': 'tag', 'value': tag }, function(marker, isFound) {
marker.setVisible(true);
bounds.extend(marker.position);
marker.map.fitBounds(bounds);
});
} else {
$('#map_canvas').gmap('find', 'markers', { 'property': 'tag', 'value': tag }, function(marker, isFound) {
if (isFound) {
marker.setVisible(true);
bounds.extend(marker.position);
marker.map.fitBounds(bounds);
} else {
marker.setVisible(false);
}
});
}
$('#map_canvas').gmap('option', 'center', bounds.getCenter());
});
}
});
上面的代碼工作所有標誌物(其標記值爲*
),但對其他財產,它不是working.When我試圖調試它,我發現它不是在if(isFound)
part.But去那裏是標籤。所以它應該去。
你可以找到它的文件here。
檢查控制檯錯誤??? – 2014-11-24 08:31:37
沒有控制檯錯誤.. – Twix 2014-11-24 09:11:03