我在基于maplace.js的地图实例化中使用以下函数。我想在用户滚动到地图中的某个位置后动态更改地图的中心。这就是我到目前为止所做的:
maplace = new Maplace({
map_div: '#gmap-list',
styles: styles,
scrollwheel: false,
controls_type: 'list',
controls_on_map: false,
controls_title: 'Choose a location:',
locations: LocsB,
map_options: {
scrollwheel: false,
set_center: [45.9, 10.9]
},
afterCreateMarker: function(index, location, marker) {
$(window).scroll( function() {
var scrolled_val = $(document).scrollTop().valueOf();
if (scrolled_val < 1027) {
if (marker.lat == -26.243254) {
google.maps.event.trigger(marker, 'click');
}
} else {
console.log(scrolled_val);
setCenter({lat: 42.346268, lng: -71.095764}); // does not work
}
});
}
}).Load();
感谢大家的帮助!