首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用角的Google地图标记单击事件

使用角的Google地图标记单击事件
EN

Stack Overflow用户
提问于 2017-06-23 06:12:23
回答 1查看 1.9K关注 0票数 0

我想要创建一个点击事件使用角度js谷歌地图api。

在点击标记时,我想要调用一个函数,而不打开信息窗口。

我该怎么做?

代码语言:javascript
复制
$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]));
                        }

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-06-23 06:36:05

单击标记时想要发生的一切都在侦听器内部。我认为您正在使您的代码不必要地复杂。只需在标记marker.addListener('click', function() {});上放置一个侦听器,然后在这个函数中运行ShowCenterPano()

is打开的原因是您要求它用这行代码scope.infowindow.open(scope.map, marker);打开。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44714249

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档