之前我有一个类似的问题,但由于id导致死路一条,我已经形成了一种新的理解,我现在处于不同的观点。我现在的问题是如何使用媒体查询和panBy来处理这个问题,并使用每次调整大小新计算的偏移量
我使用此代码(已更新):
var map;
function initialize() {
var Name = {lat: XX, lng: XX};
var marker = new google.maps.Marker({
position: Name,
map: map,
title: 'Name!'
});
var mapOptions = {
center: new google.maps.LatLng(XX, XX),
zoom: 13,
zoomControl: false,
disableDoubleClickZoom: false,
mapTypeControl: false,
scaleControl: false,
scrollwheel: false,
panControl: false,
streetViewControl: false,
draggable: false,
overviewMapControl: false,
overviewMapControlOptions: {
opened: false,
},
mapTypeId: google.maps.MapTypeId.ROADMAP,
styles: styleArray
};
map = new google.maps.Map(document.getElementById("map"),
mapOptions);
marker = new google.maps.Marker({
icon: markericon,
position: new google.maps.LatLng(locations[i][5], locations[i][6]),
map: map,
title: locations[i][0],
desc: description,
tel: telephone,
email: email,
web: web
});
}
var mql = window.matchMedia(("(max-height: 750px)"));
mql.addListener(new function(){
if(window.matchMedia("(max-height: 750px)").matches){
map.panBy(0, 150);
}else {
map.panBy(0, 250);
}});
}
google.maps.event.addDomListener(window, 'load', initialize);
google.maps.event.addDomListener(window, "resize", function() {
var center = map.getCenter();
google.maps.event.trigger(map, "resize");
map.setCenter(center);
});
感谢阅读! 此致