Bug fix: Problem adding a marker without clustering
MODIFY
plugin.xml
plugin.xml
<?xml version='1.0' encoding='utf-8'?>
-<plugin id="cordova-plugin-googlemaps" version="cluster-20170731-1050" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
+<plugin id="cordova-plugin-googlemaps" version="cluster-20170801-1825" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<name>cordova-plugin-googlemaps</name>
<js-module name="BaseClass" src="www/BaseClass.js">
<runs />

MODIFY
src/android/plugin/google/maps/AsyncLoadImage.java
src/android/plugin/google/maps/AsyncLoadImage.java
@@ -65,11 +65,13 @@ public class AsyncLoadImage extends AsyncTask<Void, Void, AsyncLoadImage.AsyncLo
}
public static String getCacheKey(String url, int width, int height) {
+ if (url == null) {
+ return null;
+ }
try {
return getCacheKey(new URL(url), width, height);
} catch (MalformedURLException e) {
- e.printStackTrace();
- return null;
+ return url.hashCode() + "/" + width + "x" + height;
}
}
public static String getCacheKey(URL url, int width, int height) {

MODIFY
src/android/plugin/google/maps/MyPlugin.java
src/android/plugin/google/maps/MyPlugin.java
@@ -29,7 +29,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class MyPlugin extends CordovaPlugin implements MyPluginInterface {
- protected final ConcurrentHashMap<String, Object> objects = new ConcurrentHashMap<String, Object>();
+ protected static final ConcurrentHashMap<String, Object> objects = new ConcurrentHashMap<String, Object>();
public MyPlugin self = null;
public final ConcurrentHashMap<String, Method> methods = new ConcurrentHashMap<String, Method>();
protected static ExecutorService executorService = null;
@@ -38,7 +38,7 @@ public class MyPlugin extends CordovaPlugin implements MyPluginInterface {
public GoogleMap map = null;
public PluginMap pluginMap = null;
protected boolean isRemoved = false;
- protected float density = Resources.getSystem().getDisplayMetrics().density;
+ protected static float density = Resources.getSystem().getDisplayMetrics().density;
public String CURRENT_PAGE_URL;
public void setPluginMap(PluginMap pluginMap) {

MODIFY
src/android/plugin/google/maps/PluginMap.java
src/android/plugin/google/maps/PluginMap.java
@@ -357,9 +357,9 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
} else {
mapView.setVisibility(View.VISIBLE);
callbackContext.success();
- if (map.getMapType() == GoogleMap.MAP_TYPE_NONE) {
+ //if (map.getMapType() == GoogleMap.MAP_TYPE_NONE) {
PluginMap.this.onMapLoaded();
- }
+ //}
}
}
});
@@ -378,9 +378,9 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
} else {
mapView.setVisibility(View.VISIBLE);
callbackContext.success();
- if (map.getMapType() == GoogleMap.MAP_TYPE_NONE) {
+ //if (map.getMapType() == GoogleMap.MAP_TYPE_NONE) {
PluginMap.this.onMapLoaded();
- }
+ //}
}
}
} catch (Exception e) {

MODIFY
src/android/plugin/google/maps/PluginMarker.java
src/android/plugin/google/maps/PluginMarker.java
@@ -267,9 +267,11 @@ public class PluginMarker extends MyPlugin implements MyPluginInterface {
try {
// Store the marker
- self.objects.put(markerId, marker);
+ synchronized (objects) {
+ objects.put(markerId, marker);
- self.objects.put("marker_property_" + markerId, properties);
+ objects.put("marker_property_" + markerId, properties);
+ }
// Prepare the result
final JSONObject result = new JSONObject();
@@ -675,7 +677,7 @@ public class PluginMarker extends MyPlugin implements MyPluginInterface {
this.sendNoResult(callbackContext);
return;
}
- String propertyId = "marker_property_" + marker.getTag();
+ String propertyId = "marker_property_" + id;
JSONObject properties = null;
if (self.objects.containsKey(propertyId)) {
properties = (JSONObject)self.objects.get(propertyId);
@@ -700,7 +702,7 @@ public class PluginMarker extends MyPlugin implements MyPluginInterface {
this.sendNoResult(callbackContext);
return;
}
- String propertyId = "marker_property_" + marker.getTag();
+ String propertyId = "marker_property_" + id;
JSONObject properties = null;
if (self.objects.containsKey(propertyId)) {
properties = (JSONObject)self.objects.get(propertyId);
@@ -776,7 +778,7 @@ public class PluginMarker extends MyPlugin implements MyPluginInterface {
}
*/
- String propertyId = "marker_property_" + marker.getTag();
+ String propertyId = "marker_property_" + id;
objects.remove(propertyId);
cordova.getActivity().runOnUiThread(new Runnable() {

MODIFY
src/ios/GoogleMaps/GoogleMapsViewController.m
src/ios/GoogleMaps/GoogleMapsViewController.m
- (void) syncInfoWndPosition {
if (self.activeMarker == nil) {
- NSLog(@"-->no active marker");
+ //NSLog(@"-->no active marker");
return;
}
CLLocationCoordinate2D position = self.activeMarker.position;

MODIFY
src/ios/GoogleMaps/PluginMarker.m
src/ios/GoogleMaps/PluginMarker.m
{
NSDictionary *json = [command.arguments objectAtIndex:1];
- NSMutableDictionary *result = [[NSMutableDictionary alloc] init];
+ __block NSMutableDictionary *createResult = [[NSMutableDictionary alloc] init];
NSString *markerId = [NSString stringWithFormat:@"marker_%lu", command.hash];
- [result setObject:markerId forKey:@"id"];
-
+ [createResult setObject:markerId forKey:@"id"];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
CDVCommandDelegateImpl *cmdDelegate = (CDVCommandDelegateImpl *)self.commandDelegate;
if (successed == NO) {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:result];
} else {
- pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:result];
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:createResult ];
}
[cmdDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
return;
}
-
NSMutableDictionary *iconProperty = nil;
NSString *animation = nil;
NSDictionary *latLng = [json objectForKey:@"position"];
// Custom properties
NSMutableDictionary *properties = [[NSMutableDictionary alloc] init];
- NSString *propertyId = [NSString stringWithFormat:@"marker_property_%lu", (unsigned long)marker.hash];
+ NSString *propertyId = [NSString stringWithFormat:@"marker_property_%@", markerId];
if ([json valueForKey:@"styles"]) {
NSDictionary *styles = [json valueForKey:@"styles"];

MODIFY
www/HtmlInfoWindow.js
www/HtmlInfoWindow.js
@@ -94,7 +94,7 @@ var HTMLInfoWindow = function() {
}
// Adjust the HTMLInfoWindow size
- var contentsWidth = contentBox.offsetWidth;
+ var contentsWidth = contentBox.offsetWidth + 10; // padding 5px x 2
self.set("contentsWidth", contentsWidth);
var contentsHeight = contentBox.offsetHeight;
self.set("contentsHeight", contentsHeight );

Bug fix: Problem adding a marker without clustering #10