@@ -1786,10 +1786,12 @@ public View getInfoContents(Marker marker) {
17861786 LayoutParams layoutParams = new LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .WRAP_CONTENT );
17871787 layoutParams .gravity = Gravity .BOTTOM | Gravity .CENTER ;
17881788
1789+ int maxWidth = 0 ;
1790+
17891791 if (styles != null ) {
17901792 try {
1793+ int width = 0 ;
17911794 String widthString = styles .getString ("width" );
1792- Integer width = 0 ;
17931795
17941796 if (widthString .endsWith ("%" )) {
17951797 double widthDouble = Double .parseDouble (widthString .replace ("%" , "" ));
@@ -1809,6 +1811,27 @@ public View getInfoContents(Marker marker) {
18091811 layoutParams .width = width ;
18101812 }
18111813 } catch (Exception e ) {}
1814+
1815+ try {
1816+ String widthString = styles .getString ("maxWidth" );
1817+
1818+ if (widthString .endsWith ("%" )) {
1819+ double widthDouble = Double .parseDouble (widthString .replace ("%" , "" ));
1820+
1821+ maxWidth = (int )((double )mapView .getWidth () * (widthDouble / 100 ));
1822+
1823+ // make sure to take padding into account.
1824+ maxWidth -= (windowLayer .getPaddingLeft () + windowLayer .getPaddingRight ());
1825+ } else if (isNumeric (widthString )) {
1826+ double widthDouble = Double .parseDouble (widthString );
1827+
1828+ if (widthDouble <= 1.0 ) { // for percentage values (e.g. 0.5 = 50%).
1829+ maxWidth = (int )((double )mapView .getWidth () * (widthDouble ));
1830+ } else {
1831+ maxWidth = (int )widthDouble ;
1832+ }
1833+ }
1834+ } catch (Exception e ) {}
18121835 }
18131836
18141837 windowLayer .setLayoutParams (layoutParams );
@@ -1848,6 +1871,11 @@ public View getInfoContents(Marker marker) {
18481871 image = PluginUtil .scaleBitmapForDevice (image );
18491872 ImageView imageView = new ImageView (this .cordova .getActivity ());
18501873 imageView .setImageBitmap (image );
1874+
1875+ if (maxWidth > 0 ) {
1876+ imageView .setMaxWidth (maxWidth );
1877+ }
1878+
18511879 windowLayer .addView (imageView );
18521880 } else {
18531881 TextView textView = new TextView (this .cordova .getActivity ());
@@ -1884,7 +1912,11 @@ public View getInfoContents(Marker marker) {
18841912 } catch (JSONException e ) {}
18851913 }
18861914 textView .setTypeface (Typeface .DEFAULT , fontStyle );
1887-
1915+
1916+ if (maxWidth > 0 ) {
1917+ textView .setMaxWidth (maxWidth );
1918+ }
1919+
18881920 windowLayer .addView (textView );
18891921 }
18901922 }
@@ -1899,8 +1931,13 @@ public View getInfoContents(Marker marker) {
18991931 textView2 .setTextAlignment (textAlignment );
19001932 }
19011933
1934+ if (maxWidth > 0 ) {
1935+ textView2 .setMaxWidth (maxWidth );
1936+ }
1937+
19021938 windowLayer .addView (textView2 );
19031939 }
1940+
19041941 return windowLayer ;
19051942 }
19061943
0 commit comments