我们有一个相机处理程序,应该尝试将相机聚焦在特定区域。如果滚动太远,它应该将相机返回到中心点,如果你缩小得太远,它应该再次放大。
我们在plugin.google.maps.event.CAMERA_CHANGE
上注册此处理程序。处理程序被正确触发并将遵循正确的代码路径。它将设置摄像机的位置(我们已经尝试了moveCamera,animateCamera和简单的setCenter / setZoom)。如果我们使用getCameraPosition
检查相机的位置,我们会看到相机报告正确的(新)位置。
所以除了视觉没有任何改变之外,一切都正常。从用户的角度来看,即使相机正确地在控制台中报告其新位置,相机也会保持不变。
var cameraHandler = function (position) {
// Create an outer LatLngBounds object that borders our map
var outerBounds = new application.services.maps.LatLngBounds([
new plugin.google.maps.LatLng(
application.configuration.location.bottomLeft.latitude,
application.configuration.location.bottomLeft.longitude
),
new plugin.google.maps.LatLng(
application.configuration.location.topRight.latitude,
application.configuration.location.topRight.longitude
)
]);
// Center of the map
var mapCenter = new application.services.maps.LatLng(
application.configuration.location.center.latitude,
application.configuration.location.center.longitude
);
var self = this;
// Current center
var center = new application.services.maps.LatLng(position.target.lat, position.target.lng);
// Zoom levels
var zoom = {
min: 11,
max: 17,
default: 15
};
// Check if map is in bounds
if (!outerBounds.contains(center)) {
this.animateCamera({
target: mapCenter,
duration: 1200
}, function() {
self.getCameraPosition(function(camera) {
console.log("AFTER MOVE CAMERA POSITION", camera);
});
});
}
if (Math.ceil(position.zoom) <= zoom.min) {
this.animateCamera({
"zoom": zoom.default,
"duration": 600
}, function() {
self.getCameraPosition(function(camera) {
console.log("AFTER ZOOM CAMERA POSITION", camera);
});
});
}
};