2016-08-26 7 views
0

上のマーカーからpanToのTOP_LEFT(X、Y)にどのように私は、マーカの右からの情報ウィンドウのポップアップを持っている私のコードGoogleマップAPIのV.3 - こちらをクリックしてください

function init_map() { 

    var bounds = new google.maps.LatLngBounds(); 
    var myOptions = { 
     zoom: 10, 
     center: new google.maps.LatLng(31.75664276376096, 35.56389920898436), 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 

    map = new google.maps.Map(document.getElementById('gmap_canvas'), myOptions); 

    var locations = [ 
     ['Name1', 0, 0], 
     ['Name2', 1, 1] 
    ]; 

    var infoWindowContent = ['some content here'] 

    var infoWindow = new google.maps.InfoWindow(), 
     marker, i; 

    for (i = 0; i < locations.length; i++) { 

     var position = new google.maps.LatLng(locations[i][1], locations[i][2]); 

     bounds.extend(position); 
     marker = new google.maps.Marker({ 
      position: position, 
      map: map, 
      icon: './images/content/mapPin.png', 
      title: locations[i][0] 
     }); 

     google.maps.event.addListener(marker, 'click', (function(marker, i) { 
      return function() { 

       map.panTo(marker.getPosition()); 
       infoWindow.setContent(infoWindowContent[i][0]); 
       infoWindow.open(map, marker); 

       var iwOuter = jQuery('.gm-style-iw'); 

       var iwBackground = iwOuter.prev(); 

       iwBackground.children(':nth-child(2)').css({ 
        'display': 'none' 
       }); 

       iwBackground.children(':nth-child(4)').css({ 
        'display': 'none' 
       }); 

       var ceva = jQuery(window).width(); 

       if(ceva <= 400){ 
        iwOuter.parent().parent().css({ 
         'left': '0', 
         'top': '0' 
        }); 
        iwOuter.children(':nth-child(1)').addClass('gm-style-child').css({ 
         'width': '100%' 
        }); 
       } else if (ceva <= 768) { 
        iwOuter.parent().parent().css({ 
         'left': '15px', 
         'top': '0' 
        }); 
        map.panTo(marker.getPosition()); 

       } else { 
        iwOuter.parent().parent().css({ 
         'left': '220px', 
         'top': '180px' 
        }); 
       } 

       iwOuter.parent().css({ 
        'width': '260px' 
       }); 

       iwOuter.children().css({ 
        'max-height': 'none', 
        'overflow': 'visible' 
       }); 

       iwOuter.children().children().css({ 
        'overflow': 'visible' 
       }); 

       iwBackground.children(':nth-child(1)').css({ 
        'display': 'none' 
       }); 

       iwBackground.children(':nth-child(3)').find('div').children().css({ 
        'display': 'none' 
       }); 

       var iwCloseBtn = iwOuter.next(); 

       iwCloseBtn.addClass('close-icon').css({ 
         'display': 'none' 
       }); 
      } 
     })(marker, i)); 

     map.fitBounds(bounds); 
    } 

    var boundsListener = google.maps.event.addListener((map), 'bounds_changed', function(event) { 
     this.setZoom(8); 
     google.maps.event.removeListener(boundsListener); 
    }); 
} 
google.maps.event.addDomListener(window, 'load', init_map); 

です。私がmapPinをクリックするたびに、ピンの地図が中央に表示されます。

map.panTo(marker.getPosition());

だから私が望むのは、マーカーをクリックすると地図が少し左に移動し、上に移動します。マーカは上部に表示され、-100 xオフセットが表示されるので、マーカーをクリックするとポップアップが表示され、マップをドラッグしてポップアップ内のすべての情報を表示する必要はありません。

わかりやすい画像を追加します。

今のところ、このような感じです。

enter image description here

そして私はそれが完璧に動作し、モバイル用として、デスクトップバージョンのため、このような何かをしたいです。

enter image description here

誰もがこれを達成するためにどのように任意のアイデアを持っています。ありがとうございました!

+0

これを試してみて、私がしなければならなかったのは、情報ウィンドウにdisableAutoPanを追加することでしたhttp://stackoverflow.com/questions/8146676/google-maps-api-v3-offset-panto-by-x-pixels – Pianist

答えて

0

答えが見つかりました。

var infoWindow = new google.maps.InfoWindow({ 
    disableAutoPan: true 
}), 
関連する問題