0
我正在使用Google Maps for AngularJS將地圖添加到我在AngularJS中的項目中。一切都很好,除了在特定點我想讓地圖中心與點擊標記完全相同的位置。因此,在點擊事件中,我在AngularJS控制器中設置了地圖的中心。一切正常,但是當我拖動或縮放地圖時,標記位置成爲地圖的「新」中心。有人知道爲什麼會發生這種情況嗎?這就像標記線以雙向方式綁定......任何幫助都會被讚賞!在此先感謝AngularJS和google-maps
下面的代碼:
// angular js controller
// map init [displays markers for all railway terminals in DB]
$scope.map = {
center: {
latitude: 48.22476,
longitude: 16.41356
},
zoom: 4
};
$scope.markers = []; // later filled with data from DB
// some code in between ...
// selection in table with termnals
$scope.selectTerminal = function (terminal) {
$scope.selected.terminal = terminal;
if (terminal.placeId != $scope.currentSelectedId) {
$scope.currentSelectedId = $scope.selected.terminal.placeId;
$scope.getTerminalDetails($scope.selected.terminal.placeId);
$scope.map.center = terminal.address.coords; // THIS LINE GIVES ME TROUBLE
$scope.map.zoom = 12;
}
};
因此,地圖中心根據上選擇操作所選擇的終端的座標設置(這是地圖的新中心),和變焦水平提高。事情是當我嘗試重置地圖,或嘗試縮放或拖動地圖時,標記座標獲取新的地圖中心座標,但它不應該。這就是爲什麼我說'雙向約束',我只是無法弄清楚這件事。
你應該爲這種情況下添加示例代碼。 –