1

情報ウィンドウのサイズを解決するために大きな問題に直面しています。情報ウィンドウに画像ブロックといくつかのテキスト情報を表示したいのですが、コンテンツ情報ウィンドウのサイズが大きくなった後、いくつかのスレッドを読みましたが、コードに運がありません。誰でもそれを整理するのを手伝ってもらえますか。

// Creating an object literal containing the properties 
// we want to pass to the map  
var options = {  
  zoom: 5,  
  center: new google.maps.LatLng(44.913990, 15.205078),  
  mapTypeId: google.maps.MapTypeId.ROADMAP ,
  };
// Creating the map  
var map = new google.maps.Map(document.getElementById("map"), options);
// Creating a LatLngBounds object
var bounds = new google.maps.LatLngBounds();
// Creating an array that will contain the coordinates 
// for New York, San Francisco, and Seattle
  var content = [];
  var places = [];content.push('Some html');
  places.push(new google.maps.LatLng(44.913990, 15.205078));
// Creating a variable that will hold 
// the InfoWindow object
var infowindow;

// Looping through the places array
for (var i = 0; i < places.length; i++)
{
  // Adding the markers
  var marker = new google.maps.Marker({
    position: places[i], 
    map: map,
    icon: "/themes/garland/images/beach_icon_gmap.png"
  //  title: "Place number " + i
  });

  // Wrapping the event listener inside an anonymous function 
  // that we immediately invoke and passes the variable i to.
  (function(i, marker) {
    // Creating the event listener. It now has access to the values of
    // i and marker as they were during its creation
    google.maps.event.addListener(marker, "click", function() {

      // Check to see if we already have an InfoWindow  
      if (!infowindow) {
        infowindow = new google.maps.InfoWindow({
            maxWidth: 20,
            maxheight: 20
        });
      }

      // Setting the content of the InfoWindow
      infowindow.setContent(content[i]);

      // Tying the InfoWindow to the marker 
      infowindow.open(map, marker);

    });

  })(i, marker);

  // Extending the bounds object with each LatLng
  bounds.extend(places[i]);
}
// Adjusting the map to new bounding box
// map.fitBounds(bounds)

どんな助けでも大歓迎です。前もって感謝します。

4

1 に答える 1

0

コードで最初に気付くのは、コンストラクターに渡されるapi-docmaxWidthオブジェクトの有効なプロパティですが、そうではありません。幅は制限されますが、厳密なコンテナーまたは固定コンテナーとして扱うことはできません。Anは常に、提供されたコンテンツを含むようにサイズ設定されます。API ドキュメントから:InfoWindowOptionsInfoWindowmaxheightInfoWindowmaxWidthInfoWindow

InfoWindow は、コンテンツに応じてサイズ変更されます。コンテンツに明示的なサイズを設定するには、コンテンツをそのサイズの HTML 要素に設定します。

InfoWindowつまり、CSS クラスを定義し、スタイル ルールをウィンドウのコンテンツに適用することで、 のサイズ、表示、色などを制御できます。コンテンツに CSS アプローチを採用すると、コンテンツInfoWindowのコンテナーとして機能するだけなので、コンテンツのサイズを完全に制御できます。CSS ルールによって正しいサイズのコンテンツが得られる場合、あなたInfoWindowは正しいサイズになります。

于 2012-07-03T13:15:31.597 に答える