2017-05-29 34 views
1

是否有人熟悉使用Google Maps API的NgMap指令?我已经获得了一张地图,可以用数据点上的标记进行渲染,但是当我点击标记时,我想放大。这不适合我。我只是想记录标记的传入位置,而现在我什么都看不到。 我对AngularJS来说很新,所以我可能会忽略范围。谢谢!NgMap AngularJS setZoom()

这里的地图:

<div id='map'> 
<map center="{{ $ctrl.map.center.latitude }}, {{ $ctrl.map.center.longitude }}" zoom="{{ $ctrl.map.zoom }}"> 
    <div ng-repeat="location in $ctrl.locations"> 
    <marker position="[{{ location.latitude }}, {{ location.longitude }}]" ng-click="$ctrl.pinClicked(location)"></marker> 
    </div> 
</map> 
</div> 

和组件:

angular.module('myplaces') 
    .component('placespage', { 
    templateUrl: 'places.template.html', 
    controller: controller 
    }) 

    function controller(placeService, NgMap) { 
    const ctrl = this; 
    ctrl.locations = []; 
    ctrl.marker = [] 
    ctrl.map = {} 
    var map; 

    ctrl.$onInit = function() { 

     placeService.getPlaces().then(function(response) { 
     console.log(response.data.rows); 
     ctrl.locations = response.data.rows; 
     }) 

     NgMap.getMap().then(function(map) { 
     console.log(ctrl.map); 
     }) 

     ctrl.map = { 
     center: 
     { 
      latitude: 34.8394, 
      longitude: 134.6939 
     }, 
     zoom:5, 
     }; 

    } 

    ctrl.pinClicked = function(loc) { 
    console.log(loc); //This is getting nothing... 
    ctrl.map.setZoom(8); 
    } 

}

回答

0

移动ng-repeat到指令,并使用onClick与控制器的功能绑定。

<marker ng-repeat="location in $ctrl.locations" position="[{{ location.latitude }}, {{ location.longitude }}]" on-click="$ctrl.pinClicked(location)"></marker> 

看样here

相关问题