我有一個選擇與一些地區(voivodship) - 如果用戶選擇任何 - 地圖應該改變中心和縮放以最適合該地區。這是理論。現在代碼:選擇onchange應改變地圖範圍
controller.js:
KPNControllers.controller('branchesCtrl', ['$scope',
function branchesCtrl($scope) {
$scope.voivodships = [
{"name" : 'dolnośląskie', "bounds" : {
"northeast" : {
"lat" : 51.8047592,
"lng" : 17.7989169
},
"southwest" : {
"lat" : 50.09634,
"lng" : 14.816831
}
}},
{"name" : 'kujawsko-pomorskie', "bounds" : {
"northeast" : {
"lat" : 53.7809988,
"lng" : 19.7618465
},
"southwest" : {
"lat" : 52.33079009999999,
"lng" : 17.2472673
}
}}];
$scope.$watch('voivodship', function() {
if ($scope.voivodship !== undefined) {
console.log($scope.voivodship.bounds);
$scope.bounds = new google.maps.LatLngBounds(new google.maps.LatLng($scope.voivodship.bounds.northeast),new google.maps.LatLng($scope.voivodship.bounds.southwest));
console.log($scope.bounds);
$scope.map.panToBounds($scope.bounds);
$scope.map.fitBounds($scope.bounds);
}
})
分/ branches.html:
<select ng-model="voivodship" ng-options="voivodship.name for voivodship in voivodships" class="full-width"><option value="">-- wybierz województwo --</option></select>
遺憾的是地圖沒有變化,控制檯顯示:
RangeError: Maximum call stack size exceeded
任何想法?
有時,最好去睡覺或散步,並用新鮮的頭腦可以追溯到; d –