Skip to content

Commit 60f833e

Browse files
author
lempere
committed
For android sdk 30, update agp, fix from: mapsplugin#2872
1 parent 3b965e3 commit 60f833e

File tree

2 files changed

+52
-37
lines changed

2 files changed

+52
-37
lines changed

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -448,15 +448,13 @@ public void getMap(final JSONArray args, final CallbackContext callbackContext)
448448
//------------------------------------------
449449
JSONObject meta = args.getJSONObject(0);
450450
String mapId = meta.getString("__pgmId");
451-
PluginMap pluginMap = new PluginMap();
452-
pluginMap.privateInitialize(mapId, cordova, webView, null);
453-
pluginMap.initialize(cordova, webView);
454-
pluginMap.mapCtrl = CordovaGoogleMaps.this;
455-
pluginMap.self = pluginMap;
456451

452+
PluginMap pluginMap = new PluginMap();
457453
PluginEntry pluginEntry = new PluginEntry(mapId, pluginMap);
458454
pluginManager.addService(pluginEntry);
459455

456+
pluginMap.mapCtrl = CordovaGoogleMaps.this;
457+
pluginMap.self = pluginMap;
460458
pluginMap.getMap(args, callbackContext);
461459
}
462460

@@ -470,14 +468,12 @@ public void getPanorama(final JSONArray args, final CallbackContext callbackCont
470468
String mapId = meta.getString("__pgmId");
471469
Log.d(TAG, "---> mapId = " + mapId);
472470
PluginStreetViewPanorama pluginStreetView = new PluginStreetViewPanorama();
473-
pluginStreetView.privateInitialize(mapId, cordova, webView, null);
474-
pluginStreetView.initialize(cordova, webView);
475-
pluginStreetView.mapCtrl = CordovaGoogleMaps.this;
476-
pluginStreetView.self = pluginStreetView;
477-
478471
PluginEntry pluginEntry = new PluginEntry(mapId, pluginStreetView);
479472
pluginManager.addService(pluginEntry);
480473

474+
pluginStreetView.mapCtrl = CordovaGoogleMaps.this;
475+
pluginStreetView.self = pluginStreetView;
476+
481477
pluginStreetView.getPanorama(args, callbackContext);
482478
}
483479

@@ -524,12 +520,12 @@ public void onPause(boolean multitasking) {
524520
@Override
525521
public void onResume(boolean multitasking) {
526522
Collection<PluginEntry>pluginEntries = pluginManager.getPluginEntries();
527-
for (PluginEntry pluginEntry: pluginEntries) {
523+
for (Iterator<PluginEntry> iterator = pluginEntries.iterator(); iterator.hasNext();) {
524+
PluginEntry pluginEntry = iterator.next();
528525
if (pluginEntry.service.startsWith("map_")) {
529526
pluginEntry.plugin.onResume(multitasking);
530527
}
531528
}
532-
533529
}
534530

535531
@Override

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

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -613,9 +613,6 @@ public synchronized void loadPlugin(final JSONArray args, final CallbackContext
613613
plugins.put(pluginName, pluginEntry);
614614
mapCtrl.pluginManager.addService(pluginEntry);
615615

616-
plugin.privateInitialize(pluginName, cordova, webView, null);
617-
618-
plugin.initialize(cordova, webView);
619616
((MyPluginInterface)plugin).setPluginMap(PluginMap.this);
620617
MyPlugin myPlugin = (MyPlugin) plugin;
621618
myPlugin.self = (MyPlugin)plugin;
@@ -666,8 +663,6 @@ public void create(final JSONArray args, final CallbackContext callbackContext)
666663
pluginMap = PluginMap.this;
667664
pluginMap.mapCtrl.pluginManager.addService(pluginEntry);
668665

669-
plugin.privateInitialize(className, cordova, webView, null);
670-
plugin.initialize(cordova, webView);
671666
((MyPluginInterface)plugin).setPluginMap(PluginMap.this);
672667
pluginEntry.plugin.execute("create", args, callbackContext);
673668

@@ -724,28 +719,32 @@ public void run() {
724719
activity.runOnUiThread(new Runnable() {
725720
@Override
726721
public void run() {
727-
if (mapDivId != null) {
728-
RectF drawRect = mapCtrl.mPluginLayout.HTMLNodeRectFs.get(mapDivId);
729-
730-
//Log.d(TAG, "--->mapDivId = " + mapDivId + ", drawRect = " + drawRect);
731-
if (drawRect != null) {
732-
final int scrollY = webView.getView().getScrollY();
733-
734-
int width = (int) drawRect.width();
735-
int height = (int) drawRect.height();
736-
int x = (int) drawRect.left;
737-
int y = (int) drawRect.top + scrollY;
738-
ViewGroup.LayoutParams lParams = mapView.getLayoutParams();
739-
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) lParams;
740-
741-
params.width = width;
742-
params.height = height;
743-
params.leftMargin = x;
744-
params.topMargin = y;
745-
mapView.setLayoutParams(params);
746722

723+
if(mapCtrl.mPluginLayout == null || mapDivId == null) {
747724
callbackContext.success();
748-
}
725+
return;
726+
}
727+
728+
RectF drawRect = mapCtrl.mPluginLayout.HTMLNodeRectFs.get(mapDivId);
729+
730+
//Log.d(TAG, "--->mapDivId = " + mapDivId + ", drawRect = " + drawRect);
731+
if (drawRect != null) {
732+
final int scrollY = webView.getView().getScrollY();
733+
734+
int width = (int) drawRect.width();
735+
int height = (int) drawRect.height();
736+
int x = (int) drawRect.left;
737+
int y = (int) drawRect.top + scrollY;
738+
ViewGroup.LayoutParams lParams = mapView.getLayoutParams();
739+
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) lParams;
740+
741+
params.width = width;
742+
params.height = height;
743+
params.leftMargin = x;
744+
params.topMargin = y;
745+
mapView.setLayoutParams(params);
746+
747+
callbackContext.success();
749748
}
750749
}
751750
});
@@ -1748,6 +1747,26 @@ public void run() {
17481747
});
17491748
}
17501749

1750+
1751+
/**
1752+
* Stop camera animation
1753+
* @param args
1754+
* @param callbackContext
1755+
* @throws JSONException
1756+
*/
1757+
public void stopAnimation(JSONArray args, final CallbackContext callbackContext) throws JSONException {
1758+
1759+
this.activity.runOnUiThread(new Runnable() {
1760+
@Override
1761+
public void run() {
1762+
if(map != null) {
1763+
map.stopAnimation();
1764+
}
1765+
callbackContext.success();
1766+
}
1767+
});
1768+
}
1769+
17511770
/**
17521771
* Pan by the specified pixel
17531772
* @param args

0 commit comments

Comments
 (0)