NG-地图:我怎样才能获得标记对象,当我点击它?当我、标记、对象、地图

2023-09-14 23:07:40 作者:只有一颗心、只爱一个人

我使用的是pretty酷 NG-地图角库,我想知道如何访问由NG-地图中引用的基本标记对象的标记指令

I am using the pretty cool ng-map library for angular, and I want to know how to access the underlying Marker Object referenced by ng-map marker directive

所以,我有这样的标记:

So, I have this markup:

<div id="map-search" data-tap-disabled="true">
  <map zoom="15" disable-default-u-i="true">
    <marker ng-repeat=" pos in positions" position="{{pos.latitude}}, {{pos.longitude}}" id="{{pos.index}}" on-click="pinClicked()">
    </marker>
  </map>
</div>

我还没有找到一个的上单击事件期间访问了谷歌地图的标记对象的直接的方式的在这种情况下,从控制器:

I haven't found a straight-forward way of accessing the Google Maps Marker Object during a on-click event in this case; From the controller:

  app.controller('MapSearchController', function($scope) {

      $scope.$on('mapInitialized', function(event, map) {
        $scope.map = map;
        //Assume existence of an Array of markers
        $scope.positions = generatePinPositionsArray();
      });

      $scope.pinClicked = function(event, marker) {
        console.log('clicked pin!');
        //HOW CAN I GET THE MARKER OBJECT (The one that was clicked) HERE?
        console.log('the marker ->', marker); //prints undefined
      };
  });

由于提前,

推荐答案

您需要创建标记数组!这是(在我看来)的唯一途径。请参见

You need to create an array of markers ! That's (in my opinion) the only way. See here

更新:是否像这样 plunkr 为你工作?

UPDATE: Does something like this plunkr works for you?

我们的想法是通过对事件的标记上点击=pinClicked(本)。然后你可以在以后赶上它的控制器上: $ scope.pinClicked =功能(事件标记){...}

The idea is to pass the marker on the event on-click="pinClicked(this)". And then you can catch it later on the controller: $scope.pinClicked = function(events, marker) {...}