Google maps 谷歌地图标记点击事件使用角度
我想用AngularJSGoogleMapAPI创建一个点击事件 单击标记,我想在不打开信息窗口的情况下调用函数 我该怎么做Google maps 谷歌地图标记点击事件使用角度,google-maps,google-maps-api-3,Google Maps,Google Maps Api 3,我想用AngularJSGoogleMapAPI创建一个点击事件 单击标记,我想在不打开信息窗口的情况下调用函数 我该怎么做 $scope.map = new google.maps.Map(document.getElementById('map'), { zoom: 12, center: { lat: parseFloat(Center_lat) , lng: parseFloat(center
$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]));
}
$scope.map=new google.maps.map(document.getElementById('map'){
缩放:12,
中心:{lat:parseFloat(center_lat),lng:parseFloat(center_lang)}
});
$scope.infowindow=new google.maps.infowindow({
//内容:“”
});
角度.forEach($scope.panoramas,函数(值,索引){
var latLang=$scope.panoramas[index].project\u latLng;
//console.log(latLang)
var LatLngArr=latLang.split(“,”);
var-lat=LatLngArr[0];
var lang=Latlngar[1];
控制台日志(“lat”,lat);
var marker=new google.maps.marker({
位置:新的google.maps.LatLng(parseFloat(lat),parseFloat(lang)),
map:$scope.map,
图标:“images/map circle.png”,
真的,
标签:{
颜色:'黑色',
fontWeight:'粗体',
text:$scope.panoramas[index].panoId,
},
标题:$scope.panoramas[index].panoId
});
变量内容='查看详细信息';
var compiledContent=$compile(content)($scope)
google.maps.event.addListener(标记,'单击',(函数(标记,内容,范围){
返回函数(){
scope.infowindow.setContent(content);
scope.infowindow.open(scope.map,marker);
};
})(marker,compiledContent[0],$scope));
$scope.ShowCenterPano=函数(索引){
//警报(JSON.stringify($scope.panoramas[index]);
}
此处信息窗口正在打开。如何删除信息窗口并直接调用ShowCenterPano()函数。单击标记时希望发生的一切都在侦听器中。 我认为您正在使代码变得不必要的复杂。只需在标记
marker.addListener('click',function(){});
上放置一个侦听器,然后在此函数中运行ShowCenterPano()
信息窗口打开的原因是,您要求它使用以下代码行打开:
scope.infowindow.open(scope.map,marker);
它给了我此错误未捕获的引用错误:未定义ShowCenterPano是否调用$scope.ShowCenterPano(index)?您的索引也应该是函数可用的变量。还有一个提示,惯例是函数名以小写字母开头,因此应该是showCenterPano