Skip to content

Commit ef62c60

Browse files
author
trancee
committed
Added maxWidth option.
1 parent e431749 commit ef62c60

1 file changed

Lines changed: 29 additions & 2 deletions

File tree

src/ios/GoogleMaps/GoogleMapsViewController.m

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,15 +384,38 @@ -(UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker*)marker
384384
width = (int)((double)mapView.frame.size.width * (widthDouble / 100));
385385
} else if ([widthString isNumeric:widthString]) {
386386
double widthDouble = [widthString doubleValue];
387-
387+
388388
if (widthDouble <= 1.0) {
389389
width = (int)((double)mapView.frame.size.width * (widthDouble));
390390
} else {
391391
width = (int)widthDouble;
392392
}
393393
}
394394
}
395-
395+
396+
int maxWidth = 0;
397+
398+
if (styles && [styles objectForKey:@"maxWidth"]) {
399+
NSString *widthString = [styles valueForKey:@"maxWidth"];
400+
401+
if ([widthString hasSuffix:@"%"]) {
402+
double widthDouble = [[widthString stringByReplacingOccurrencesOfString:@"%" withString:@""] doubleValue];
403+
404+
maxWidth = (int)((double)mapView.frame.size.width * (widthDouble / 100));
405+
406+
// make sure to take padding into account.
407+
maxWidth -= sizeEdgeWidth;
408+
} else if ([widthString isNumeric:widthString]) {
409+
double widthDouble = [widthString doubleValue];
410+
411+
if (widthDouble <= 1.0) {
412+
maxWidth = (int)((double)mapView.frame.size.width * (widthDouble));
413+
} else {
414+
maxWidth = (int)widthDouble;
415+
}
416+
}
417+
}
418+
396419
//-------------------------------------
397420
// Calculate the size for the contents
398421
//-------------------------------------
@@ -471,6 +494,10 @@ -(UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker*)marker
471494
if (width > 0) {
472495
rectSize.width = width;
473496
}
497+
if (maxWidth > 0 &&
498+
maxWidth < rectSize.width) {
499+
rectSize.width = maxWidth;
500+
}
474501

475502
//-------------------------------------
476503
// Draw the the info window

0 commit comments

Comments
 (0)