Skip to content

Commit 44f6f1e

Browse files
author
Philipp Grosswiler
committed
Added new option "width" to set width of the marker.
This can be percentage (%) or just a numeric value from 0.0 to 1.0 for percentile representation, or the numeric width in pixels.
1 parent bbe9a96 commit 44f6f1e

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

src/android/plugin/google/maps/GoogleMaps.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1743,7 +1743,17 @@ public void onClick(View view) {
17431743
return;
17441744
}
17451745
}
1746-
1746+
1747+
public static boolean isNumeric(String str)
1748+
{
1749+
for (char c : str.toCharArray()) {
1750+
if (!Character.isDigit(c)) {
1751+
return false;
1752+
}
1753+
}
1754+
return true;
1755+
}
1756+
17471757
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
17481758
@Override
17491759
public View getInfoContents(Marker marker) {
@@ -1775,6 +1785,30 @@ public View getInfoContents(Marker marker) {
17751785
windowLayer.setOrientation(LinearLayout.VERTICAL);
17761786
LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
17771787
layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER;
1788+
1789+
if (styles != null) {
1790+
try {
1791+
String widthString = styles.getString("width");
1792+
Integer width = 0;
1793+
1794+
if (widthString.endsWith("%")) {
1795+
double widthDouble = Double.parseDouble(widthString.replace ("%", ""));
1796+
1797+
width = (int)((double)mapView.getWidth() * (widthDouble / 100));
1798+
} else if (isNumeric(widthString)) {
1799+
width = (int)Double.parseDouble(widthString);
1800+
1801+
if (width <= 1) { // for percentage values (e.g. 0.5 = 50%).
1802+
width = mapView.getWidth() * width;
1803+
}
1804+
}
1805+
1806+
if (width > 0) {
1807+
layoutParams.width = width;
1808+
}
1809+
} catch (Exception e) {}
1810+
}
1811+
17781812
windowLayer.setLayoutParams(layoutParams);
17791813

17801814
//----------------------------------------

0 commit comments

Comments
 (0)