Add: visibleRegion.js
MODIFY
plugin.xml
plugin.xml
<?xml version='1.0' encoding='utf-8'?>
-<plugin id="cordova-plugin-googlemaps" version="2.0.0-beta3-20170818-2345" 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.0.0-beta3-20170820-2025" 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 />
<js-module name="LatLngBounds" src="www/LatLngBounds.js">
<runs />
</js-module>
+ <js-module name="VisibleRegion" src="www/VisibleRegion.js">
+ <runs />
+ </js-module>
<js-module name="Location" src="www/Location.js">
<runs />
</js-module>

MODIFY
www/Map.js
www/Map.js
@@ -7,7 +7,8 @@ var argscheck = require('cordova/argscheck'),
LatLng = require('./LatLng'),
LatLngBounds = require('./LatLngBounds'),
MapTypeId = require('./MapTypeId'),
- event = require('./event');
+ event = require('./event'),
+ VisibleRegion = require('./VisibleRegion');
var Marker = require('./Marker');
var Circle = require('./Circle');
@@ -618,18 +619,19 @@ Map.prototype.getVisibleRegion = function(callback) {
return null;
}
- var latLngBounds = new LatLngBounds(cameraPosition.northeast, cameraPosition.southwest);
+ var latLngBounds = new VisibleRegion(
+ cameraPosition.southwest,
+ cameraPosition.northeast,
+ cameraPosition.farLeft,
+ cameraPosition.farRight,
+ cameraPosition.nearLeft,
+ cameraPosition.nearRight
+ );
if (typeof callback === "function") {
console.log("[deprecated] getVisibleRegion() is changed. Please check out the https://goo.gl/yHstHQ");
callback.call(self, latLngBounds);
}
-
- latLngBounds.nearLeft = new LatLng(cameraPosition.nearLeft.lat, cameraPosition.nearLeft.lng);
- latLngBounds.nearRight = new LatLng(cameraPosition.nearRight.lat, cameraPosition.nearRight.lng);
- latLngBounds.farLeft = new LatLng(cameraPosition.farLeft.lat, cameraPosition.farLeft.lng);
- latLngBounds.farRight = new LatLng(cameraPosition.farRight.lat, cameraPosition.farRight.lng);
-
return latLngBounds;
};

ADD
www/VisibleRegion.js
+var utils = require('cordova/utils'),
+ LatLngBounds = require('./LatLngBounds'),
+ LatLng = require('./LatLng');
+
+/*****************************************************************************
+ * VisibleRegion Class
+ *****************************************************************************/
+var VisibleRegion = function(southwest, northeast, farLeft, farRight, nearLeft, nearRight) {
+ Object.defineProperty(this, "type", {
+ value: "VisibleRegion",
+ writable: false
+ });
+ this.southwest = southwest;
+ this.northeast = northeast;
+ this.farLeft = farLeft;
+ this.farRight = farRight;
+ this.nearLeft = nearLeft;
+ this.nearRight = nearRight;
+};
+
+utils.extend(VisibleRegion, LatLngBounds);
+
+delete VisibleRegion.prototype.extend;
+delete VisibleRegion.prototype.getCenter;
+
+VisibleRegion.prototype.contains = function(latLng) {
+ if (!latLng || !("lat" in latLng) || !("lng" in latLng)) {
+ return false;
+ }
+ var y = latLng.lat,
+ x = latLng.lng;
+
+ var y90 = y + 90;
+ var south = this.southwest.lat,
+ north = this.northeast.lat,
+ west = this.southwest.lng,
+ east = this.northeast.lng;
+ var south90 = south + 90,
+ north90 = north + 90;
+
+ var containX = false,
+ containY = false;
+
+ if (east >= 0 && west >= east) {
+ if (x <= 0 && x >= -180) {
+ containX = true;
+ } else {
+ containX = (west <= x && x <= east);
+ }
+ } else if (west <= 0 && east <= west) {
+ containX = (west <= x && x <= east);
+ if (x >= 0 && x <= 180) {
+ containX = true;
+ } else {
+ containX = (x <= 0 && x <= west || x <= east && x>= -180);
+ }
+ } else {
+ return LatLngBounds.prototype.contains.call(this, latLng);
+ }
+
+ containY = (south90 <= y90 && y90 <= north90) || //#a
+ (south >= 0 && north <= 0 && ((south <= y && y <= 90) || (y >= -90 && y<= north))); // #d
+
+ return containX && containY;
+};
+
+module.exports = VisibleRegion;

Add: visibleRegion.js