主要HTML:
<div ng-controller="MapCtrl as vm">
<ui-gmap-google-map center="vm.map.center" zoom="vm.map.zoom">
<ui-gmap-map-control template="mapControl.tpl.html" controller="MapControlCtrl"></ui-gmap-map-control>
<ui-gmap-marker idKey="vm.marker1.id" coords="vm.marker1.coords"></ui-gmap-marker>
</ui-gmap-google-map>
</div>
MapCtrl:
angularApp.controller('MapCtrl', function() {
var vm = this;
vm.map = {
zoom: 11,
center: {
latitude: ...,
longitude: ...
}
};
vm.marker1 = {
id: 1,
coords: {
latitude: ...,
longitude: ...
}
};
});
mapControl.tpl.html:
<button ng-click="addMarker()">Add</button>
<button ng-click="updateMarker1()">Update Marker 1</button>
MapControlCtrl:
angularApp.controller('MapControlCtrl', function($scope) {
$scope.addMarker = function() {
// how to add a marker to the map from within this method?
};
$scope.updateMarker1 = function() {
// how to update marker1 from within this method?
};
)};
答案 0 :(得分:1)
您可能希望使用<ui-gmap-markers>
来获取<ui-gmap-marker>
然后你可以将新的标记对象推送到数据数组以显示在地图上
答案 1 :(得分:-1)
因为你正在使用&#34; var vm = this&#34;在控制器中的语法,您必须使用&#34;控制器指定您的控制器为&#34;语法。
ui-gmap-map-control template =&#34; mapControl.tpl.html&#34; controller =&#34; MapControlCtrl as vm&#34;
请尝试以上更改。
谢谢你, 索马。