Question

The Setup: On the same page (inside the same map canvas), I have 2 info windows. The CSS for both of them is the same. The content is very similar. Initially, the Street View pano loads with an info window open. A button inside the info window is used to toggle between the regular map and Street View. The map has a second info window displayed with a button to go back to Street View.

The Problem: One info window is resizing to fit the content and the other one is not, so it's displaying scroll bars. The only difference I can see is that one is on a regular old road map and the other is on a Street View panorama.

What I've Tried: I have maxWidth for both info windows set to 500 (ridiculously wide) and a set width and height for the inner div of the info window in CSS.

The Code: Here's the CSS:

#map-canvas{
  height: 600px;
  width: 1000px;
}
#map-canvas .info-window {
  width: 250px;
  height: 230px;
}

The full JS is long and on jsfiddle.

The Demo: http://jsfiddle.net/rkXuk/1/

full screen demo

A Call for Help: What is going on here? Why are they rendering differently and how can I fix this?

Was it helpful?

Solution

Use inline css.

Instead of

.info-window {
    width: 250px;
    height: 230px;
}

Use:

// map info window
var contentString = '<div style="width:250px; height:230px;" class="info-window">' +
    '<h3>Hi, we\'re Cuberis</h3>' +
    '<table border="0" cellpadding="0" cellspacing="0" class="contact">' +
    '<tr>' +
    '<th scope="row">Email:</th>' +
    '<td>info@cuberis.com</td>' +
    '</tr>' +
    '<tr>' +
    '<th scope="row">Phone:</th>' +
    '<td>919.443.2254</td>' +
    '</tr>' +
    '<tr>' +
    '<th scope="row">Office:</th>' +
    '<td>Golden Belt - Building 2<br />' +
    '807 E. Main Street<br />' +
    'Suite 2-210<br />' +
    'Durham, NC 27701</td>' +
    '</tr>' +
    '</table>' +
    '<div class="contact">' +
    '<input type="button" class="button" value="See inside our office" onclick="toggleStreetView();"></input>' +
    '</div>';

And:

// street view info window
var contentString2 = '<div style="width:250px; height:230px;" class="info-window">' +
    '<h3>Hi, we\'re Cuberis</h3>' +
    '<table border="0" cellpadding="0" cellspacing="0" class="contact">' +
    '<tr>' +
    '<th scope="row">Email:</th>' +
    '<td>info@cuberis.com</td>' +
    '</tr>' +
    '<tr>' +
    '<th scope="row">Phone:</th>' +
    '<td>919.443.2254</td>' +
    '</tr>' +
    '<tr>' +
    '<th scope="row">Office:</th>' +
    '<td>Golden Belt - Building 2<br />' +
    '807 E. Main Street<br />' +
    'Suite 2-210<br />' +
    'Durham, NC 27701</td>' +
    '</tr>' +
    '</table>' +
    '<div class="contact">' +
    '<input type="button" class="button" value="Check us out on the map" onclick="toggleStreetView();"></input>' +
    '</div>';
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top