ng-map:单击它时如何获取标记对象?
ng-map: How can I get the Marker object when I click it?
我正在为 angular 使用非常酷的 ng-map 库,我想知道如何访问 ng-map marker[=24] 引用的底层标记对象=] 指令
所以,我有这个标记:
<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>
我还没有找到在单击事件[=26]期间访问Google地图标记对象的直接方法=] 在这种情况下;来自控制器:
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
};
});
提前致谢,
您需要创建一个标记数组!这是(在我看来)唯一的方法。参见
更新:这样的东西 plunkr 对你有用吗?
想法是在事件 on-click="pinClicked(this)"
上传递标记。然后你可以稍后在控制器上捕获它:$scope.pinClicked = function(events, marker) {...}
this
是访问市场对象的答案。它与 Google 映射 api 完全相同,没有什么不同。再次在点击功能中使用 this
。
------ 编辑 -----
testapp目录下有很多例子,当你找到ng-map的用法时,这些例子很有用。
$scope.foo = function(event, arg1, arg2) {
alert('this is at '+ this.getPosition());
alert(arg1+arg2);
}
示例:
https://rawgit.com/allenhwkim/angularjs-google-maps/master/testapp/events.html
我正在为 angular 使用非常酷的 ng-map 库,我想知道如何访问 ng-map marker[=24] 引用的底层标记对象=] 指令
所以,我有这个标记:
<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>
我还没有找到在单击事件[=26]期间访问Google地图标记对象的直接方法=] 在这种情况下;来自控制器:
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
};
});
提前致谢,
您需要创建一个标记数组!这是(在我看来)唯一的方法。参见
更新:这样的东西 plunkr 对你有用吗?
想法是在事件 on-click="pinClicked(this)"
上传递标记。然后你可以稍后在控制器上捕获它:$scope.pinClicked = function(events, marker) {...}
this
是访问市场对象的答案。它与 Google 映射 api 完全相同,没有什么不同。再次在点击功能中使用 this
。
------ 编辑 -----
testapp目录下有很多例子,当你找到ng-map的用法时,这些例子很有用。
$scope.foo = function(event, arg1, arg2) {
alert('this is at '+ this.getPosition());
alert(arg1+arg2);
}
示例:
https://rawgit.com/allenhwkim/angularjs-google-maps/master/testapp/events.html