0

我使用的是旧版本jQuery UI Map。所以当时过滤工作得很好。下面的代码我用于旧版本

$('#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());
                    });

}

});

上面的代码适用于所有标记(其标签值为*)。但对于其他属性,它不起作用。当我尝试调试它时,我发现它没有部分运行。if(isFound)但是有标签。所以它应该去。

你可以在这里找到它的文档。

4

1 回答 1

1

文档似乎不正确/不是最新的。

属性(tag在这种情况下)必须是一个数组,否则过滤总是会失败。

在标记创建中替换:

'tag': m.area

'tag': [m.area]
于 2014-11-24T21:54:21.680 回答