Skip to content

Commit

Permalink
Implementing virtual synchronizing mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
wf9a5m75 committed Mar 31, 2018
1 parent 6b8e5f6 commit 3a3e207
Show file tree
Hide file tree
Showing 6 changed files with 371 additions and 260 deletions.
3 changes: 3 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@
<js-module name="StreetViewPanorama" src="www/StreetViewPanorama.js">
<runs />
</js-module>
<js-module name="Overlay" src="www/Overlay.js">
<runs />
</js-module>

<description>Google Maps native SDK for Android and iOS.
This plugin allows your application to use the native Google Maps views instead of the Google Maps JavaScript API v3.
Expand Down
7 changes: 6 additions & 1 deletion src/android/plugin/google/maps/PluginMarker.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public void create(final JSONArray args, final CallbackContext callbackContext)
// Create an instance of Marker class

JSONObject opts = args.getJSONObject(1);
final String markerId = "marker_" + callbackContext.hashCode();
final String markerId = args.getString(2);
final JSONObject result = new JSONObject();
result.put("id", markerId);

Expand Down Expand Up @@ -593,6 +593,11 @@ public void setAnimation(final JSONArray args, final CallbackContext callbackCon
String markerId = args.getString(0);
String animation = args.getString(1);
final Marker marker = this.getMarker(markerId);
Log.d(TAG, "--->setAnimation: markerId = " + markerId + ", animation = " + animation);
if (marker == null) {
callbackContext.error("marker is null");
return;
}

this.setMarkerAnimation_(marker, animation, new PluginAsyncInterface() {

Expand Down
4 changes: 4 additions & 0 deletions www/CordovaGoogleMaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,10 @@ CordovaGoogleMaps.prototype.getPanorama = function(div, streetViewOptions) {
// Create a panorama instance.
var panorama = new StreetViewPanorama(mapId, self.execCmd);

// Catch all events for this map instance, then pass to the instance.
// (Don't execute this native callback from your code)
plugin.google.maps[mapId] = nativeCallback.bind(panorama);

self.MAP_CNT++;
self.MAPS[mapId] = panorama;
self.isThereAnyChange = true;
Expand Down
49 changes: 29 additions & 20 deletions www/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -1151,14 +1151,31 @@ Map.prototype.addCircle = function(circleOptions, callback) {
Map.prototype.addMarker = function(markerOptions, callback) {
var self = this;
markerOptions = common.markerOptionsFilter(markerOptions);

//------------------------------------
// Generate a makrer instance at once.
//------------------------------------
markerOptions.icon = markerOptions.icon || {};
if (typeof markerOptions.icon === 'string' || Array.isArray(markerOptions.icon)) {
markerOptions.icon = {
url: markerOptions.icon,
size: {}
};
}

var markerId = "marker_" + (Math.floor(Date.now() * Math.random()));
var marker = new Marker(self, markerId, markerOptions, "Marker", exec);
self.MARKERS[markerId] = marker;
self.OVERLAYS[markerId] = marker;
marker.one(markerId + "_remove", function() {
delete self.MARKERS[markerId];
delete self.OVERLAYS[markerId];
marker.destroy();
marker = undefined;
});

exec.call(this, function(result) {
markerOptions.icon = markerOptions.icon || {};
if (typeof markerOptions.icon === 'string' || Array.isArray(markerOptions.icon)) {
markerOptions.icon = {
url: markerOptions.icon,
size: {}
};
}

markerOptions.icon.size = markerOptions.icon.size || {};
markerOptions.icon.size.width = markerOptions.icon.size.width || result.width;
markerOptions.icon.size.height = markerOptions.icon.size.height || result.height;
Expand All @@ -1167,23 +1184,15 @@ Map.prototype.addMarker = function(markerOptions, callback) {
if (!markerOptions.infoWindowAnchor) {
markerOptions.infoWindowAnchor = [markerOptions.icon.size.width / 2, 0];
}

var marker = new Marker(self, result.id, markerOptions, "Marker", exec);

self.MARKERS[result.id] = marker;
self.OVERLAYS[result.id] = marker;

marker.one(result.id + "_remove", function() {
marker.off();
delete self.MARKERS[result.id];
delete self.OVERLAYS[result.id];
marker = undefined;
});
marker._privateInitialize(markerOptions);
delete marker._privateInitialize;

if (typeof callback === "function") {
callback.call(self, marker);
}
}, self.errorHandler, self.id, 'loadPlugin', ['Marker', markerOptions]);
}, self.errorHandler, self.id, 'loadPlugin', ['Marker', markerOptions, markerId]);

return marker;
};


Expand Down
Loading

0 comments on commit 3a3e207

Please sign in to comment.