(JS) Bug fix: can not detect another page that places over the map page
MODIFY
plugin.xml
plugin.xml
<?xml version='1.0' encoding='utf-8'?>
-<plugin id="cordova-plugin-googlemaps" version="2.1.2-beta-20171206-1705" 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-20171208-1415" 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
www/Common.js
www/Common.js
@@ -319,9 +319,9 @@ function getZIndex(dom, solt) {
} else {
z = parseInt(z);
}
- dom.setAttribute("__parentZIndex", parentZIndex);
- dom.setAttribute("__solt", solt);
- dom.setAttribute("__ZIndex", z);
+ //dom.setAttribute("__parentZIndex", parentZIndex);
+ //dom.setAttribute("__solt", solt);
+ //dom.setAttribute("__ZIndex", z);
internalCache[elemId] = z + parentZIndex;
return z;
}
@@ -329,7 +329,9 @@ function getDomDepth(dom, idx, zIndex) {
if (dom.nodeType !== Node.ELEMENT_NODE) {
return 0;
}
- var result = (zIndex) + (idx / (1 << Math.pow(idx, idx)) / 10);
+
+ dom.setAttribute("_idx", idx); // for debugging
+ var result = (zIndex) + (idx / (1 << Math.pow(idx, idx)) / 10) + 0.01;
/* for debug */
var currentDepth = parseFloat(dom.getAttribute("_depth")) || 0;
@@ -784,35 +786,45 @@ function getClickableRect(element, parentRect) {
return rect;
}
-function quickfilter(domPositions, minMapDepth) {
- var list = Object.keys(domPositions);
- var finalDomPositions = {};
- var i = 0, j = list.length - 1;
- var leftRight = true;
- while(i < j) {
- if (leftRight) {
- if (domPositions[list[j]].depth < minMapDepth) {
- list[i] = list[j];
- i++;
- leftRight = false;
- } else {
- j--;
- }
- } else {
- if (domPositions[list[i]].depth >= minMapDepth) {
- list[j] = list[i];
- j--;
- leftRight = true;
- } else {
- i++;
- }
+function quickfilter(domPositions, minMapDepth, mapElemIDs) {
+ //console.log("before", JSON.parse(JSON.stringify(domPositions)));
+ var keys = Object.keys(domPositions);
+
+ var tree = {};
+ mapElemIDs.forEach(function(mapElemId) {
+ var size = domPositions[mapElemId].size;
+ var mapRect = {
+ left: size.left,
+ top: size.top,
+ right: size.left + size.width,
+ bottom: size.top + size.height
+ };
+
+ tree[mapElemId] = domPositions[mapElemId];
+
+ keys.forEach(function(elemId) {
+ if (domPositions[elemId].ignore) {
+ return;
}
+ var domSize = {
+ left: domPositions[elemId].size.left,
+ top: domPositions[elemId].size.top,
+ right: domPositions[elemId].size.left + domPositions[elemId].size.width,
+ bottom: domPositions[elemId].size.bottom + domPositions[elemId].size.height
+ };
+ if (
+ ((domSize.left >= mapRect.left && domSize.left <= mapRect.right) ||
+ (domSize.right >= mapRect.left && domSize.right <= mapRect.right)) &&
+ ((domSize.top >= mapRect.top && domSize.top <= mapRect.bottom) ||
+ (domSize.bottom >= mapRect.top && domSize.bottom <= mapRect.bottom))
+ ) {
+ tree[elemId] = domPositions[elemId];
}
- list.splice(0, j);
- list.forEach(function(domId) {
- finalDomPositions[domId] = domPositions[domId];
});
- return finalDomPositions;
+ });
+
+ //console.log("after", JSON.parse(JSON.stringify(tree)));
+ return tree;
}
module.exports = {

MODIFY
www/googlemaps-cdv-plugin.js
www/googlemaps-cdv-plugin.js
@@ -394,6 +394,7 @@ if (!cordova) {
bodyRect.bottom = bodyRect.top + bodyRect.heihgt;
common._clearInternalCache();
+ foundMap = false;
traceDomTree(document.body, 0, bodyRect, 0, 0, 0);
// If some elements has been removed, should update the positions
@@ -433,14 +434,30 @@ if (!cordova) {
var minMapDepth = 9999999;
var maxMapDepth = -1;
var stopFlag = false;
+ var mapElemIDs = [];
mapIDs.forEach(function(mapId) {
var div = MAPS[mapId].getDiv();
if (div) {
var elemId = div.getAttribute("__pluginDomId");
if (elemId) {
if (elemId in domPositions) {
+ mapElemIDs.push(elemId);
minMapDepth = Math.min(minMapDepth, domPositions[elemId].depth);
maxMapDepth = Math.max(maxMapDepth, domPositions[elemId].depth);
+
+ div = div.parentNode;
+ while(div) {
+ children = div.children;
+ for (var i = 0; i < children.length; i++) {
+ elemId = children[i].getAttribute("__pluginDomId");
+ if (elemId in domPositions) {
+ domPositions[elemId].parent = true;
+ }
+ }
+ div = div.parentNode;
+ }
+
+
} else {
// Is the map div removed?
if (window.document.querySelector) {
@@ -478,7 +495,7 @@ if (!cordova) {
if (touchableMapList.length === 0) {
finalDomPositions = domPositions;
} else {
- finalDomPositions = common.quickfilter(domPositions, minMapDepth);
+ finalDomPositions = common.quickfilter(domPositions, minMapDepth, mapElemIDs);
}
var prevKeys = Object.keys(prevFinal);
var currentKeys = Object.keys(finalDomPositions);
@@ -544,6 +561,7 @@ if (!cordova) {
children = null;
}
+ var foundMap = false;
function traceDomTree(element, domIdx, parentRect, parentZIndex, parentDepth, zIndexSolt) {
var zIndex = parentZIndex;
doNotTrace = false;
@@ -558,6 +576,9 @@ if (!cordova) {
elemId = "pgm" + Math.floor(Math.random() * Date.now());
element.setAttribute("__pluginDomId", elemId);
}
+ if (!foundMap) {
+ foundMap = element.hasAttribute("__pluginMapId");
+ }
// get dom depth
zIndex = common.getZIndex(element, zIndexSolt);
@@ -590,7 +611,8 @@ if (!cordova) {
domPositions[elemId] = {
size: rect,
depth: depth,
- zIndex: zIndex
+ zIndex: zIndex,
+ ignore: foundMap === false
};
parentRect = rect;
parentRect.elemId = elemId;

(JS) Bug fix: can not detect another page that places over the map page