我可以创建一个地图并设置标记但是当我尝试使用鼠标缩放或移动地图时没有任何反应。
这是我的功能
function initMap() {
var locations = $scope.locList ? $scope.locList : {loc: {loc: {lat: $scope.data.loc.lat, lng: $scope.data.loc.lng}}};
var mapDiv = document.getElementById('map');
var map = new google.maps.Map(mapDiv, {
zoom: $scope.locList ? 4 : 16,
center: $scope.locList ? new google.maps.LatLng(39.833, -98.583) : new google.maps.LatLng($scope.data.loc.lat, $scope.data.loc.lng),
scrollwheel: false
});
map.addListener('click', function(e) {
map.set('scrollwheel', true);
});
map.addListener('mouseout', function(e) {
map.set('scrollwheel', false);
});
var marker;
$.each(locations, function(key, value){
marker = new google.maps.Marker({
position: new google.maps.LatLng(value.loc.lat, value.loc.lng),
icon: $scope.data.marker,
map: map
});
})
}
和我的标记
<div id="map"></div>
这一切都发生在$scope.locList
和$scope.data
填充后
答案 0 :(得分:1)
基本上,您无法缩放,因为您使用scrollwheel: false
初始化地图,并且在点击地图时尝试设置scrollwheel: true
。
相反,您应该在scrollwheel: true
上附加mouseover
,draggable: true
同样如此:
map.addListener('mouseover', function(e) {
map.set('scrollwheel', true);
map.set('draggable', true);
});
然后,在mouseout
上,您再次将它们设为false:
map.addListener('mouseout', function(e) {
map.set('scrollwheel', false);
map.set('draggable', false);
});
这是您应该如何初始化地图:
var myLatLng = new google.maps.LatLng(41.9026329,12.452200400000038);
var mapOptions = {
center: myLatLng,
zoom: 5,
scrollwheel: false,
draggable: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById(attributes.id), mapOptions);
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title:"My town"
});
marker.setMap(map);
This is a working Plunker that reproduces your target
希望我能提供帮助。