谷歌地图标记点击事件使用角度

时间:2017-06-23 06:12:23

标签: google-maps google-maps-api-3

我想使用angular js google map api创建点击事件。

单击标记我想调用函数而不打开信息窗口。

我该怎么做?

$scope.map = new google.maps.Map(document.getElementById('map'), {
                        zoom: 12,
                        center: { lat: parseFloat(Center_lat) , lng: parseFloat(center_lang) }
                    });

                    $scope.infowindow = new google.maps.InfoWindow({
                        // content: ''
                    });

                    angular.forEach($scope.panoramas, function(value, index) {
                        var latLang = $scope.panoramas[index].project_latLng ;
                        // console.log(latLang)
                        var LatLngArr = latLang.split(",");
                        var lat  = LatLngArr[0];
                        var lang = LatLngArr[1];
                        console.log("lat " ,lat);

                        var marker = new google.maps.Marker({
                            position: new google.maps.LatLng(parseFloat(lat), parseFloat(lang)),
                            map: $scope.map,
                            icon:"images/map-circle.png",
                            draggable:true,
                            label: {
                                color: 'black',
                                fontWeight: 'bold',
                                text: $scope.panoramas[index].panoId,
                            },

                            title: $scope.panoramas[index].panoId
                        });

                        var content = '<a ng-click="ShowCenterPano(' + index + ')" class="btn btn-default">View details</a>';

                        var compiledContent = $compile(content)($scope)

                        google.maps.event.addListener(marker, 'click', (function(marker, content, scope) {
                            return function() {
                                scope.infowindow.setContent(content);
                                scope.infowindow.open(scope.map, marker);
                            };
                        })(marker, compiledContent[0], $scope));


                        $scope.ShowCenterPano = function(index) {
                          // alert(JSON.stringify($scope.panoramas[index]));
                        }

此信息窗口正在打开。如何删除信息窗口并直接调用ShowCenterPano()函数。

1 个答案:

答案 0 :(得分:0)

单击标记时想要发生的一切都在侦听器内部。 我认为你使你的代码变得不必要复杂。只需在标记scope.infowindow.open(scope.map, marker);上放置一个监听器,然后在此功能中运行ShowCenterPano()

infowindow正在打开的原因是因为你要求用这行代码打开queried_entities = table_service.query_entities('myTable', filter="RowKey gt '2017-06-20T15:33:00' and PartitionKey eq 'myKey'"