Angularjs 打开一个信息窗口,在谷歌地图上点击事件
我有一个应用程序,我需要它在谷歌地图上打开一个信息窗口,当我点击侧栏的面板时,只需显示一秒钟。在这之后,它不需要再工作了 我在侧边栏中有一个标记和信息列表,当用户点击其中一些标记时,我需要打开信息窗口Angularjs 打开一个信息窗口,在谷歌地图上点击事件,angularjs,google-maps,google-maps-api-3,infowindow,Angularjs,Google Maps,Google Maps Api 3,Infowindow,我有一个应用程序,我需要它在谷歌地图上打开一个信息窗口,当我点击侧栏的面板时,只需显示一秒钟。在这之后,它不需要再工作了 我在侧边栏中有一个标记和信息列表,当用户点击其中一些标记时,我需要打开信息窗口 (function(){ angular.module('mapCtrl', ['presentacionService']) .controller('MapController', function($scope, Presentacion) {
(function(){
angular.module('mapCtrl', ['presentacionService'])
.controller('MapController', function($scope, Presentacion) {
var self = this;
function initialize() {
var options = {
googleApiKey: '',
locationColumn: 'geometry',
map_center: [-16.494898, -68.133553],
locationScope: 'La Paz'
};
options = options || {};
self.googleApiKey = options.googleApiKey || "";
self.locationColumn = options.locationColumn || "geometry";
self.locationScope = options.locationScope || "";
self.defaultZoom = options.defaultZoom || 10;
self.map_centroid = new google.maps.LatLng(options.map_center[0], options.map_center[1]);
self.myOptions = {
zoom: self.defaultZoom,
center: self.map_centroid,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
self.map = new google.maps.Map($("#map")[0], self.myOptions);
var infoWindow = new google.maps.InfoWindow();
google.maps.event.addListener(map, 'click', function() {
infowindow.close();
});
$scope.markers = [];
var createMarker = function (info){
var marker = new google.maps.Marker({
map: self.map,
position: new google.maps.LatLng(info.latitud, info.long),
title: info.nombre,
date: info.date,
imagen: info.imagen,
nombre_categoria: info.nombre_categoria
});
marker.content = '<div class="infoWindowContent">' + info.descripcion + '</div>';
google.maps.event.addListener(marker, 'click', function(){
infoWindow.setContent('<h2>' + marker.title + '</h2>' + marker.content);
infoWindow.open(self.map, marker);
});
$scope.markers.push(marker);
};
Presentacion.getAll().success(function (datos) {
for (var i = 0; i < datos.length; i++){
createMarker(datos[i]);
}
});
$scope.openInfoWindow = function(e, selectedMarker){
console.log('show something');
e.preventDefault();
new google.maps.event.trigger(selectedMarker, 'click' );
};
}
google.maps.event.addDomListener(window, 'load', initialize);
});
})();
(函数(){
angular.module('mapCtrl',['presentacionService']))
.controller('MapController',函数($scope,Presentacion){
var self=这个;
函数初始化(){
变量选项={
Googleapkey:“,
locationColumn:“几何体”,
地图中心:[-16.494898,-68.133553],
位置范围:“拉巴斯”
};
选项=选项| |{};
self.googleApiKey=options.googleApiKey | | |“”;
self.locationColumn=options.locationColumn | | |“几何体”;
self.locationScope=options.locationScope | |“”;
self.defaultZoom=options.defaultZoom | | 10;
self.map_centroid=new google.maps.LatLng(options.map_center[0],options.map_center[1]);
self.myOptions={
缩放:self.defaultZoom,
中心:self.map\u形心,
mapTypeId:google.maps.mapTypeId.ROADMAP
};
self.map=new google.maps.map($(“#map”)[0],self.myOptions);
var infoWindow=new google.maps.infoWindow();
google.maps.event.addListener(映射,'click',函数(){
infowindow.close();
});
$scope.markers=[];
var createMarker=函数(信息){
var marker=new google.maps.marker({
map:self.map,
位置:新的google.maps.LatLng(info.latitud,info.long),
标题:info.nombre,
日期:info.date,
imagen:info.imagen,
nombre_categoria:info.nombre_categoria
});
marker.content=''+info.description+'';
google.maps.event.addListener(标记'click',函数(){
infoWindow.setContent(“”+marker.title+“”+marker.content);
打开(self.map,marker);
});
$scope.markers.push(marker);
};
Presentacion.getAll().success(函数(datos){
对于(变量i=0;i
一种观点认为:
<div class="row list_special" ng-repeat="marker in markers | orderBy : 'date'">
<div class="panel-google-plus" ng-click="openInfoWindow($event, marker)">
</div>
</div>
我准备了一个Plunker来模拟项目所需的功能。 以下是网址: 我已将您的服务表示替换为在MainCtrl中初始化的简单数组
places
(而且markers
是MainCtrl作用域的一个属性,但由MapController继承):
您的代码中没有其他编辑,并且它正在按要求工作:您可以单击某个项目,它将随时打开信息窗口。不要在openInfoWindow函数中新建google.maps.event.trigger。您不是在构造触发器对象,而是在google.maps.event类上调用触发器函数。只需执行
google.maps.event.trigger
我尝试使用google.maps.event.trigger,我有相同的错误,但您执行了相同的XD,这与我的操作不同,因为打开一个信息窗口,但仅此之后的一秒钟不要打开更多信息窗口抱歉,但我不明白…我的代码中有什么错误?如果是关于填充标记的代码,这只是一个示例,因为您没有共享“Presentacion”服务。。。
$scope.markers = [];
$scope.places = [];
$scope.places.push({lat: 44.99758207, lng: 7.140598296999997, ...);