NG-地图:我怎样才能获得标记对象,当我点击它? [英] ng-map: How can I get the Marker object when I click it?

查看:236
本文介绍了NG-地图:我怎样才能获得标记对象,当我点击它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是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
      };
  });

由于提前,

推荐答案

您需要创建标记数组!这是(在我看来)的唯一途径。请参见 href=\"http://stackoverflow.com/a/28754507/2954267\">

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) {...}

这篇关于NG-地图:我怎样才能获得标记对象,当我点击它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆