Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap marker setIcon execute in try/catch to avoid crash in host app #529

Merged
merged 1 commit into from
Aug 30, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 35 additions & 26 deletions src/android/plugin/google/maps/PluginMarker.java
Original file line number Diff line number Diff line change
Expand Up @@ -759,34 +759,43 @@ protected void onPostExecute(Bitmap image) {
callback.onPostExecute(marker);
return;
}
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(image);
marker.setIcon(bitmapDescriptor);

// Save the information for the anchor property
Bundle imageSize = new Bundle();
imageSize.putInt("width", image.getWidth());
imageSize.putInt("height", image.getHeight());
PluginMarker.this.objects.put("imageSize", imageSize);


// The `anchor` of the `icon` property
if (iconProperty.containsKey("anchor") == true) {
double[] anchor = iconProperty.getDoubleArray("anchor");
if (anchor.length == 2) {
_setIconAnchor(marker, anchor[0], anchor[1], imageSize.getInt("width"), imageSize.getInt("height"));
}
}

try {
//TODO: check image is valid?
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(image);
marker.setIcon(bitmapDescriptor);

// Save the information for the anchor property
Bundle imageSize = new Bundle();
imageSize.putInt("width", image.getWidth());
imageSize.putInt("height", image.getHeight());
PluginMarker.this.objects.put("imageSize", imageSize);


// The `anchor` of the `icon` property
if (iconProperty.containsKey("anchor") == true) {
double[] anchor = iconProperty.getDoubleArray("anchor");
if (anchor.length == 2) {
_setIconAnchor(marker, anchor[0], anchor[1], imageSize.getInt("width"), imageSize.getInt("height"));
}
}


// The `anchor` property for the infoWindow
if (iconProperty.containsKey("infoWindowAnchor") == true) {
double[] anchor = iconProperty.getDoubleArray("infoWindowAnchor");
if (anchor.length == 2) {
_setInfoWindowAnchor(marker, anchor[0], anchor[1], imageSize.getInt("width"), imageSize.getInt("height"));
}
}

callback.onPostExecute(marker);

} catch (java.lang.IllegalArgumentException e) {
Log.e("GoogleMapsPlugin","PluginMarker: Warning - marker method called when marker has been disposed, wait for addMarker callback before calling more methods on the marker (setIcon etc).");
//e.printStackTrace();

// The `anchor` property for the infoWindow
if (iconProperty.containsKey("infoWindowAnchor") == true) {
double[] anchor = iconProperty.getDoubleArray("infoWindowAnchor");
if (anchor.length == 2) {
_setInfoWindowAnchor(marker, anchor[0], anchor[1], imageSize.getInt("width"), imageSize.getInt("height"));
}
}

callback.onPostExecute(marker);
}
}
};
task.execute();
Expand Down