クリーンな GoogleMap.js スクリプトを作成しようとしています。gMarker と gInfoWindow を含む js クラスを作成しました。そのプロトタイプ (共有) に「openedInfoWindow」プロパティを設定したいので、ユーザーが特定の gMarker をクリックするたびに、それをグローバルとして指定せずに閉じて変更できます。
function gMarkerWInfo(gMarker,gInfoWindow){
if(!gMarker || !gInfoWindow)
return null;
this.Marker = gMarker;
this.InfoWindow = gInfoWindow;
}
gMarkerWInfo.prototype.openedInfoWindow = null;
gMarkerWInfo.prototype.openInfoWindow = function(){
if(this.openedInfoWindow){
alert(this.openedInfoWindow.getContent());
//openedInfoWindow.close();
}
this.InfoWindow.open(this.Marker.getMap(),this.Marker);
this.openedInfoWindow = this.InfoWindow;
}
「アラート」はデバッグ用であり、クリックするたびに、クリックした gMarker に「リンク」された InfoWindow の内容が表示されます。したがって、「openedInfoWindow」は期待どおりに機能しません。誰でも私を助けることができますか?
PS。「GoogleMap」クラス内で gMarkerWInfo を作成するために使用する関数は次のとおりです。
this.createMarkerWInfo = function(LatLng,Name,HTML_Infos){
var gMarker = new google.maps.Marker({ position: LatLng,
animation: this.MarkerAnimation,
map: priv_Map,
title: Name
});
var gInfoWindow = new google.maps.InfoWindow({content:HTML_Infos});
var gMarkerWInfoWindow = new gMarkerWInfo(gMarker,gInfoWindow);
google.maps.event.addListener(gMarker,'click', function() {gMarkerWInfoWindow.openInfoWindow();});
return gMarkerWInfoWindow;
}