こんにちは。いつもお世話になってます。
Google Maps APIでカスタム情報ウインドウを表示させるだけのシンプルなサイトを作っていて、カスタム情報ウインドウを表示させることはできたのですが、他の場所を押すとその場所のデフォルトの情報ウインドウが開かれてしまいます。カスタム情報ウインドウと重なったり、予期せず押してしまって邪魔なので消したいのですが、どうやって消せるのかわからず質問させていただきました。
予想ではこの下のコードをどうにかする必要があると思ったので、いろいろやってみたのですが、うまくいかず。。しかしListenerはこれ一つしかないです。(1番下に全てのコードを載せてあります。)
JavaScript
1marker.addListener("click", function () { 2 ib.open(theMap, this); 3});
詳しい方どうか教えてくださいませんでしょうか?宜しくお願いします。
JavaScript
1 function initialize() { 2 var secheltLoc = new google.maps.LatLng(00.000000,000.000000); 3 4 var myMapOptions = { 5 zoom: 15 6 ,center: secheltLoc 7 ,mapTypeId: google.maps.MapTypeId.ROADMAP 8 }; 9 var theMap = new google.maps.Map(document.getElementById("map_canvas"), myMapOptions); 10 11 12 var icon = "images/icon.png" 13 14 var marker = new google.maps.Marker({ 15 map: theMap, 16 position: new google.maps.LatLng(00.000000,000.000000), 17 visible: true, 18 icon: icon 19 }); 20 21 var viewport = { 22 width : $(window).width(), 23 height : $(window).height() 24 }; 25 26 var infoWindowHtml = 27 "<div id='content_wrapper'>" 28 +"<div id='infoWin'>" 29 +"<div>" 30 +"<h1 style=''>Example Inc.</h1>" 31 +"<blockquote>We are the best.</blockquote>" 32 +"</div>" 33 +"<ul id='sns'>" 34 +"<li><a href='#'></a></li>" 35 +"<li><a href='#'></a></li>" 36 +"<li><a href='#'></a></li>" 37 +"<li><a href='#'></a></li>" 38 +"<li><a href='#'></a></li>" 39 +"<li><a href='#'></a></li>" 40 +"</ul>" 41 +"<button class='more_open'>More info</button>" 42 +"</div>" 43 44 +"</div> <!-- Close content_wrapper -->" 45 46 47 var pxOffX; 48 var pxOffY; 49 50 var mobileWidth = 768; 51 var infoWinWidth, infoWinHeight; 52 53 if(viewport.width < mobileWidth){ 54 pxOffX = -(viewport.width/2); //it moves infowindow when you move the map 55 pxOffY = -(viewport.height/1.6); 56 infoWinWidth = viewport.width 57 infoWinHeight = viewport.height/2.4; 58 // document.getElementById("infoWin").style.fontSize = "200%"; 59 }else if(viewport.width >= mobileWidth){ 60 pxOffX = -310; 61 pxOffY = -160; 62 infoWinWidth = 280 63 infoWinHeight = infoWinWidth *0.8; //It is calculating height 64 } 65 66 67 // console.log(toString(infoWinWidth) + "px"); 68 // console.log(infoWinWidth.toString() + "px"); 69 70 var myOptions = { 71 content: infoWindowHtml 72 ,pixelOffset: new google.maps.Size(pxOffX, pxOffY) //You can fix postion of info window 73 ,boxStyle: { 74 width: infoWinWidth.toString() + "px" 75 ,height: infoWinHeight.toString() + "px" //This is the width of the window. 76 } 77 }; 78 79 var ib = new InfoBox(myOptions); 80 81 //Add icon click function 82 marker.addListener("click", function () { 83 ib.open(theMap, this); 84 }); 85 86 ib.open(theMap, marker); 87 88 theMap.panBy(pxOffX/2,pxOffY/2); 89 } 90
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/09/07 23:48