(Android) improve the DOM tree inspection
MODIFY
plugin.xml
plugin.xml
<?xml version='1.0' encoding='utf-8'?>
-<plugin id="cordova-plugin-googlemaps" version="2.1.2-beta-20171117-2005" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
+<plugin id="cordova-plugin-googlemaps" version="2.1.2-beta-20171120-0000" 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/CordovaGoogleMaps.java
src/android/plugin/google/maps/CordovaGoogleMaps.java
@@ -464,13 +464,6 @@ public class CordovaGoogleMaps extends CordovaPlugin implements ViewTreeObserver
PluginEntry pluginEntry = new PluginEntry(mapId, pluginMap);
pluginManager.addService(pluginEntry);
- if (mPluginLayout.isSuspended) {
- mPluginLayout.isSuspended = false;
- synchronized (mPluginLayout.timerLock) {
- mPluginLayout.timerLock.notify();
- }
- }
-
pluginMap.getMap(args, callbackContext);
}

MODIFY
src/android/plugin/google/maps/MyPluginLayout.java
src/android/plugin/google/maps/MyPluginLayout.java
@@ -130,6 +130,7 @@ public class MyPluginLayout extends FrameLayout implements ViewTreeObserver.OnSc
if (lParams instanceof FrameLayout.LayoutParams) {
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) lParams;
+ //Log.d("MyPluginLayout", "-->FrameLayout x = " + x + ", y = " + y + ", w = " + params.width + ", h = " + params.height);
if (params.leftMargin == x && params.topMargin == y &&
params.width == width && params.height == height) {
return;
@@ -138,7 +139,6 @@ public class MyPluginLayout extends FrameLayout implements ViewTreeObserver.OnSc
params.height = height;
params.leftMargin = x;
params.topMargin = y;
- //Log.d("MyPluginLayout", "-->FrameLayout x = " + x + ", y = " + y + ", w = " + params.width + ", h = " + params.height);
pluginMap.mapView.setLayoutParams(params);
} else if (lParams instanceof AbsoluteLayout.LayoutParams) {
@@ -192,6 +192,7 @@ public class MyPluginLayout extends FrameLayout implements ViewTreeObserver.OnSc
//}
zoomScale = Resources.getSystem().getDisplayMetrics().density;
+ Log.e(TAG, "--> zoomScale = " + zoomScale);
frontLayer = new FrontLayerLayout(this.context);
scrollView = new ScrollView(this.context);
@@ -439,6 +440,7 @@ public class MyPluginLayout extends FrameLayout implements ViewTreeObserver.OnSc
}
if (!HTMLNodes.containsKey(pluginMap.mapDivId)) {
+ Log.e(TAG, "----> 100x100");
Bundle dummyInfo = new Bundle();
dummyInfo.putDouble("offsetX", 0);
dummyInfo.putDouble("offsetY", 3000);

MODIFY
src/android/plugin/google/maps/PluginGroundOverlay.java
src/android/plugin/google/maps/PluginGroundOverlay.java
@@ -36,6 +36,7 @@ public class PluginGroundOverlay extends MyPlugin implements MyPluginInterface
private HashMap<Integer, AsyncTask> imageLoadingTasks = new HashMap<Integer, AsyncTask>();
private final Object semaphore = new Object();
private HashMap<String, Bitmap> overlayImage = new HashMap<String, Bitmap>();
+ private boolean _clearDone = false;
@Override
public void initialize(final CordovaInterface cordova, final CordovaWebView webView) {
@@ -142,6 +143,7 @@ public class PluginGroundOverlay extends MyPlugin implements MyPluginInterface
@Override
protected void clear() {
+ _clearDone = false;
synchronized (semaphore) {
//--------------------------------------
@@ -178,6 +180,7 @@ public class PluginGroundOverlay extends MyPlugin implements MyPluginInterface
}
synchronized (semaphore) {
+ _clearDone = true;
semaphore.notify();
}
@@ -185,9 +188,12 @@ public class PluginGroundOverlay extends MyPlugin implements MyPluginInterface
});
try {
- semaphore.wait();
+ if (!_clearDone) {
+ semaphore.wait(1000);
+ }
} catch (InterruptedException e) {
- e.printStackTrace();
+ // ignore
+ //e.printStackTrace();
}
}
}

MODIFY
src/android/plugin/google/maps/PluginMap.java
src/android/plugin/google/maps/PluginMap.java
@@ -5,6 +5,7 @@ import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Point;
+import android.graphics.RectF;
import android.graphics.Typeface;
import android.location.Location;
import android.os.AsyncTask;
@@ -16,6 +17,7 @@ import android.util.Base64;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
+import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
@@ -405,24 +407,29 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
} catch (Exception e) {
e.printStackTrace();
}
- map.moveCamera(CameraUpdateFactory.newLatLngBounds(initCameraBounds, (int) (CAMERA_PADDING / density)));
+ map.moveCamera(CameraUpdateFactory.newLatLngBounds(initCameraBounds, (int) (CAMERA_PADDING * density)));
CameraPosition.Builder builder = CameraPosition.builder(map.getCameraPosition());
try {
if (mParams.has("camera")) {
+ Boolean additionalParams = false;
JSONObject camera = mParams.getJSONObject("camera");
if (camera.has("bearing")) {
builder.bearing((float) camera.getDouble("bearing"));
+ additionalParams = true;
}
if (camera.has("tilt")) {
builder.tilt((float) camera.getDouble("tilt"));
+ additionalParams = true;
+ }
+ if (additionalParams) {
+ map.moveCamera(CameraUpdateFactory.newCameraPosition(builder.build()));
}
}
} catch (Exception e) {
e.printStackTrace();
}
- map.moveCamera(CameraUpdateFactory.newCameraPosition(builder.build()));
mapView.setVisibility(View.VISIBLE);
mCallback.success();
@@ -476,6 +483,7 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
Builder builder = CameraPosition.builder();
builder.tilt(map.getCameraPosition().tilt);
builder.bearing(map.getCameraPosition().bearing);
+ Log.d(TAG, mapView.getWidth() + "x" + mapView.getHeight());
// Fit the camera to the cameraBounds with 20px padding.
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(cameraBounds, padding / (int)density);
@@ -525,7 +533,7 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
}
- public void resizeMap(JSONArray args, CallbackContext callbackContext) throws JSONException {
+ public void resizeMap(JSONArray args, final CallbackContext callbackContext) throws JSONException {
if (mapCtrl.mPluginLayout == null || mapDivId == null) {
//Log.d("PluginMap", "---> resizeMap / mPluginLayout = null");
callbackContext.success();
@@ -557,11 +565,33 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
mapCtrl.mPluginLayout.HTMLNodes.put(mapDivId, dummyInfo);
}
- //mapCtrl.mPluginLayout.updateViewPosition(mapId);
- //mapCtrl.mPluginLayout.inValidate();
+
+ activity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+
+ RectF drawRect = mapCtrl.mPluginLayout.HTMLNodeRectFs.get(mapDivId);
+
+ final int scrollY = webView.getView().getScrollY();
+
+ int width = (int)drawRect.width();
+ int height = (int)drawRect.height();
+ int x = (int) drawRect.left;
+ int y = (int) drawRect.top + scrollY;
+ ViewGroup.LayoutParams lParams = mapView.getLayoutParams();
+ FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) lParams;
+
+ params.width = width;
+ params.height = height;
+ params.leftMargin = x;
+ params.topMargin = y;
+ mapView.setLayoutParams(params);
+
callbackContext.success();
}
+ });
+ }
public void setDiv(JSONArray args, CallbackContext callbackContext) throws JSONException {
if (args.length() == 0) {

MODIFY
src/android/plugin/google/maps/PluginMarker.java
src/android/plugin/google/maps/PluginMarker.java
@@ -47,6 +47,7 @@ public class PluginMarker extends MyPlugin implements MyPluginInterface {
protected final HashMap<String, Integer> iconCacheKeys = new HashMap<String, Integer>();
private static final Paint paint = new Paint();
private final HashMap<String, Integer> semaphoreAsync = new HashMap<String, Integer>();
+ private boolean _clearDone = false;
protected interface ICreateMarkerCallback {
void onSuccess(Marker marker);
@@ -93,6 +94,7 @@ public class PluginMarker extends MyPlugin implements MyPluginInterface {
@Override
protected void clear() {
synchronized (semaphoreAsync) {
+ _clearDone = false;
cordova.getThreadPool().submit(new Runnable() {
@Override
@@ -165,6 +167,7 @@ public class PluginMarker extends MyPlugin implements MyPluginInterface {
}
synchronized (semaphoreAsync) {
+ _clearDone = true;
semaphoreAsync.notify();
}
@@ -172,9 +175,12 @@ public class PluginMarker extends MyPlugin implements MyPluginInterface {
});
try {
- semaphoreAsync.wait(5);
+ if (!_clearDone) {
+ semaphoreAsync.wait(1000);
+ }
} catch (InterruptedException e) {
- e.printStackTrace();
+ // ignore
+ //e.printStackTrace();
}
}

MODIFY
www/Map.js
www/Map.js
@@ -160,7 +160,6 @@ Map.prototype.getMap = function(mapId, div, options) {
exec.call({
_isReady: true
}, function() {
- self._onTouchEvents();
//------------------------------------------------------------------------
// Clear background colors of map div parents after the map is created
@@ -177,7 +176,7 @@ Map.prototype.getMap = function(mapId, div, options) {
div.addEventListener('touchcancel', self._onTouchEvents.bind(self));
div.addEventListener('touchleave', self._onTouchEvents.bind(self));
}
- div.style.backgroundColor = 'rgba(0,0,0,0)';
+ div.style.backgroundColor = 'rgba(0,0,0,0) !important';
// prevent multiple readding the class
if (div.classList && !div.classList.contains('_gmaps_cdv_')) {
@@ -189,11 +188,12 @@ Map.prototype.getMap = function(mapId, div, options) {
div = div.parentNode;
}
}
+ //cordova.fireDocumentEvent("plugin_touch", {force: true});
+
//------------------------------------------------------------------------
// In order to work map.getVisibleRegion() correctly, wait a little.
//------------------------------------------------------------------------
setTimeout(function() {
- self._onTouchEvents();
Object.defineProperty(self, "_isReady", {
value: true,
writable: false
@@ -202,6 +202,8 @@ Map.prototype.getMap = function(mapId, div, options) {
self.trigger(event.MAP_READY, self);
}, 250);
}, self.errorHandler, 'CordovaGoogleMaps', 'getMap', args, {sync: true});
+
+
};
Map.prototype.setOptions = function(options) {

MODIFY
www/googlemaps-cdv-plugin.js
www/googlemaps-cdv-plugin.js
@@ -396,6 +396,7 @@ if (!cordova) {
// If the map div is not displayed (such as display='none'),
// ignore the map temporally.
var minMapDepth = 9999999;
+ var stopFlag = false;
mapIDs.forEach(function(mapId) {
var div = MAPS[mapId].getDiv();
if (div) {
@@ -411,23 +412,25 @@ if (!cordova) {
// If no div element, remove the map.
if (mapId in MAPS) {
MAPS[mapId].remove();
+ return;
}
}
}
-
- domPositions[elemId] = {
- size: {
- top: 10000,
- left: 0,
- width: 100,
- height: 100
- },
- depth: 0
- };
+ stopFlag = true;
}
}
}
});
+ if (stopFlag) {
+ // There is no map size information (maybe timining?)
+ // Try again.
+ isChecking = false;
+ isThereAnyChange = true;
+ common.nextTick(function() {
+ setTimeout(putHtmlElements, 50);
+ });
+ return;
+ }
//-----------------------------------------------------------------
// Ignore the elements that their z-index is smaller than map div
@@ -460,21 +463,19 @@ if (!cordova) {
cordova_exec(null, null, 'CordovaGoogleMaps', 'resume', []);
isSuspended = false;
}
+
cordova_exec(function() {
prevDomPositions = domPositions;
- mapIDs.forEach(function(mapId) {
- if (mapId in MAPS) {
- MAPS[mapId].refreshLayout();
- }
- });
+ isChecking = false;
if (!isMutationObserver) {
isThereAnyChange = true;
- common.nextTick(putHtmlElements, 50);
+ common.nextTick(function() {
+ setTimeout(putHtmlElements, 50);
+ });
} else {
isThereAnyChange = false;
cordova_exec(null, null, 'CordovaGoogleMaps', 'pause', []);
}
- isChecking = false;
}, null, 'CordovaGoogleMaps', 'putHtmlElements', [finalDomPositions]);
child = null;
parentNode = null;
@@ -563,7 +564,6 @@ if (!cordova) {
cacheDepth[elemId] = depth;
}
}
- removeDomTree(element);
}
} else {
doNotTrace = true;
@@ -592,10 +592,12 @@ if (!cordova) {
if (!isMutationObserver || opts.force) {
idlingCnt = -1;
longIdlingCnt = -1;
+ isSuspended = false;
if (!isMutationObserver) {
cacheDepth = {};
cacheZIndex = {};
}
+ cordova_exec(null, null, 'CordovaGoogleMaps', 'resume', []);
isThereAnyChange = true;
}
common.nextTick(function() {
@@ -611,8 +613,16 @@ if (!cordova) {
});
document.addEventListener("plugin_touch", resetTimer);
window.addEventListener("orientationchange", function() {
- cordova_exec(null, null, 'CordovaGoogleMaps', 'resume', []);
+ var cnt = 10;
resetTimer({force: true});
+ var timer = setInterval(function() {
+ cnt--;
+ if (cnt > 0 && !isSuspended) {
+ followMapDivPositionOnly();
+ } else {
+ clearInterval(timer);
+ }
+ }, 50);
});
//----------------------------------------------------
@@ -692,7 +702,7 @@ if (!cordova) {
mapId = div.getAttribute("__pluginMapId");
if (!mapOptions || mapOptions.visible !== false) {
// Add gray color until the map is displayed.
- div.style.backgroundColor = "rgba(255, 30, 30, 0.5);";
+ div.style.backgroundColor = "rgba(200, 200, 200, 0.5)";
}
}
if (mapId && MAPS[mapId].getDiv() !== div) {
@@ -712,6 +722,19 @@ if (!cordova) {
}
if (common.isDom(div)) {
div.setAttribute("__pluginMapId", mapId);
+
+ var elemId = div.getAttribute("__pluginDomId");
+ if (!elemId) {
+ elemId = "pgm" + Math.floor(Math.random() * Date.now());
+ div.setAttribute("__pluginDomId", elemId);
+ }
+
+ var dummyInfo = {};
+ dummyInfo[elemId] = {
+ size: div.getBoundingClientRect(),
+ depth: 0.01
+ };
+ cordova_exec(null, null, 'CordovaGoogleMaps', 'updateMapPositionOnly', [dummyInfo]);
}
var map = new Map(mapId, execCmd);
@@ -756,7 +779,6 @@ if (!cordova) {
MAP_CNT++;
MAPS[mapId] = map;
isThereAnyChange = true;
- //cordova.fireDocumentEvent('plugin_touch', {});
var args = [mapId];
for (var i = 0; i < arguments.length; i++) {
@@ -781,9 +803,9 @@ if (!cordova) {
}
};
-
}());
+
cordova.addConstructor(function() {
if (!window.Cordova) {
window.Cordova = cordova;
@@ -818,7 +840,6 @@ if (!cordova) {
*****************************************************************************/
function onMapResize(event) {
- //console.log("---> onMapResize");
var mapIDs = Object.keys(MAPS);
mapIDs.forEach(function(mapId) {
MAPS[mapId].refreshLayout();

(Android) improve the DOM tree inspection