Update: map.getVisibleRegion() returns the values as synchronize
Add:
map.animateZoomIn(), map.animateZoomOut(), map.moveCameraZoomIn(), and map.moveCameraZoomOut()
Add:
BaseArrayClass.forEach(fn, callback) and BaseArrayClass.map(fn, callback)
MODIFY
package.json
package.json
{
"name": "cordova-plugin-googlemaps",
- "version": "2.0.0-beta",
+ "version": "2.0.0-beta-20170509-1251",
"description": "Google Maps native SDK for Android and iOS",
"cordova": {
"id": "cordova-plugin-googlemaps",
},
"repository": {
"type": "git",
- "url": "https://github.com/mapsplugin/cordova-plugin-googlemaps.git"
+ "url": "https://github.com/mapsplugin/cordova-plugin-googlemaps.git#multiple_maps"
},
"keywords": [
"google",

MODIFY
plugin.xml
plugin.xml
<?xml version='1.0' encoding='utf-8'?>
-<plugin id="cordova-plugin-googlemaps" version="2.0.0-beta" 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-beta-20170509-1251" 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/PluginMap.java
src/android/plugin/google/maps/PluginMap.java
@@ -1883,44 +1883,6 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
});
}
- /**
- * Return the visible region of the map
- */
- public void getVisibleRegion(final JSONArray args, final CallbackContext callbackContext) throws JSONException {
- this.activity.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- final VisibleRegion visibleRegion = projection.getVisibleRegion();
- cordova.getThreadPool().submit(new Runnable() {
- @Override
- public void run() {
- try {
- LatLngBounds latLngBounds = visibleRegion.latLngBounds;
- JSONObject result = new JSONObject();
- JSONObject northeast = new JSONObject();
- JSONObject southwest = new JSONObject();
- northeast.put("lat", latLngBounds.northeast.latitude);
- northeast.put("lng", latLngBounds.northeast.longitude);
- southwest.put("lat", latLngBounds.southwest.latitude);
- southwest.put("lng", latLngBounds.southwest.longitude);
- result.put("northeast", northeast);
- result.put("southwest", southwest);
-
- JSONArray latLngArray = new JSONArray();
- latLngArray.put(northeast);
- latLngArray.put(southwest);
- result.put("latLngArray", latLngArray);
-
- callbackContext.success(result);
- } catch (JSONException e) {
- e.printStackTrace();
- callbackContext.error(e.getMessage() + "");
- }
- }
- });
- }
- });
- }
/**
@@ -2275,6 +2237,18 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
target.put("lat", position.target.latitude);
target.put("lng", position.target.longitude);
params.put("target", target);
+
+ LatLngBounds latLngBounds = projection.getVisibleRegion().latLngBounds;
+ JSONObject result = new JSONObject();
+ JSONObject northeast = new JSONObject();
+ JSONObject southwest = new JSONObject();
+ northeast.put("lat", latLngBounds.northeast.latitude);
+ northeast.put("lng", latLngBounds.northeast.longitude);
+ southwest.put("lat", latLngBounds.southwest.latitude);
+ southwest.put("lng", latLngBounds.southwest.longitude);
+ params.put("northeast", northeast);
+ params.put("southwest", southwest);
+
jsonStr = params.toString();
} catch (JSONException e) {
e.printStackTrace();

MODIFY
src/ios/GoogleMaps/GoogleMapsViewController.m
src/ios/GoogleMaps/GoogleMapsViewController.m
[json setObject:[NSNumber numberWithFloat:position.zoom] forKey:@"zoom"];
+ GMSVisibleRegion visibleRegion = self.map.projection.visibleRegion;
+ GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithRegion:visibleRegion];
+ NSMutableDictionary *northeast = [NSMutableDictionary dictionary];
+ [northeast setObject:[NSNumber numberWithFloat:bounds.northEast.latitude] forKey:@"lat"];
+ [northeast setObject:[NSNumber numberWithFloat:bounds.northEast.longitude] forKey:@"lng"];
+ [json setObject:northeast forKey:@"northeast"];
+ NSMutableDictionary *southwest = [NSMutableDictionary dictionary];
+ [southwest setObject:[NSNumber numberWithFloat:bounds.southWest.latitude] forKey:@"lat"];
+ [southwest setObject:[NSNumber numberWithFloat:bounds.southWest.longitude] forKey:@"lng"];
+ [json setObject:southwest forKey:@"southwest"];
+
+
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:json options:0 error:nil];
NSString* sourceArrayString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSString* jsString = [NSString

MODIFY
src/ios/GoogleMaps/PluginMap.h
src/ios/GoogleMaps/PluginMap.h
- (void)setCompassEnabled:(CDVInvokedUrlCommand*)command;
- (void)getCameraPosition:(CDVInvokedUrlCommand*)command;
- (void)toDataURL:(CDVInvokedUrlCommand*)command;
-- (void)getVisibleRegion:(CDVInvokedUrlCommand*)command;
- (void)setOptions:(CDVInvokedUrlCommand*)command;
- (void)setAllGesturesEnabled:(CDVInvokedUrlCommand*)command;
- (void)setPadding:(CDVInvokedUrlCommand*)command;

MODIFY
src/ios/GoogleMaps/PluginMap.m
src/ios/GoogleMaps/PluginMap.m
}];
}
-/**
- * Return the visible region of the map
- * Thanks @fschmidt
- */
-- (void)getVisibleRegion:(CDVInvokedUrlCommand*)command {
-
- [[NSOperationQueue mainQueue] addOperationWithBlock:^{
- GMSVisibleRegion visibleRegion = self.mapCtrl.map.projection.visibleRegion;
- GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithRegion:visibleRegion];
-
- [self.executeQueue addOperationWithBlock:^{
-
-
- NSMutableDictionary *json = [NSMutableDictionary dictionary];
- NSMutableDictionary *northeast = [NSMutableDictionary dictionary];
- [northeast setObject:[NSNumber numberWithFloat:bounds.northEast.latitude] forKey:@"lat"];
- [northeast setObject:[NSNumber numberWithFloat:bounds.northEast.longitude] forKey:@"lng"];
- [json setObject:northeast forKey:@"northeast"];
- NSMutableDictionary *southwest = [NSMutableDictionary dictionary];
- [southwest setObject:[NSNumber numberWithFloat:bounds.southWest.latitude] forKey:@"lat"];
- [southwest setObject:[NSNumber numberWithFloat:bounds.southWest.longitude] forKey:@"lng"];
- [json setObject:southwest forKey:@"southwest"];
-
- NSMutableArray *latLngArray = [NSMutableArray array];
- [latLngArray addObject:northeast];
- [latLngArray addObject:southwest];
- [json setObject:latLngArray forKey:@"latLngArray"];
-
- CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:json];
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
- }];
- }];
-}
-
- (void)_setOptions:(NSDictionary *)initOptions command:(CDVInvokedUrlCommand *)command {
[self.executeQueue addOperationWithBlock:^{

MODIFY
www/BaseArrayClass.js
www/BaseArrayClass.js
@@ -12,11 +12,80 @@ function BaseArrayClass(array) {
}
}
- self.forEach = function(callback) {
- if (typeof callback !== "function" || _array.length === 0) {
+ self.map = function(fn, callback) {
+ if (typeof fn !== "function" || _array.length === 0) {
return;
}
- _array.forEach(callback);
+ var results = [];
+ if (typeof fn === "function" && typeof callback !== "function") {
+ //------------------------
+ // example:
+ // var values = baseArray.forEach(function(item, idx) {
+ // ...
+ // return someValue;
+ // });
+ //------------------------
+ results = _array.map(fn.bind(self));
+ return;
+ }
+ //------------------------
+ // example:
+ // baseArray.forEach(function(item, idx, callback) {
+ // ...
+ // callback(value);
+ // }, function(values) {
+ //
+ // });
+ //------------------------
+ _array.forEach(function() {
+ results.push(null);
+ });
+ var _arrayLength = _array.length;
+ var finishCnt = 0;
+ _array.forEach(function(item, idx) {
+ fn.call(self, item, function(value) {
+ results[idx] = value;
+ finishCnt++;
+ if (finishCnt === _arrayLength) {
+ callback.call(self, results);
+ }
+ });
+ });
+ };
+
+ self.forEach = function(fn, callback) {
+ if (typeof fn !== "function" || _array.length === 0) {
+ return;
+ }
+ if (typeof fn === "function" && typeof callback !== "function") {
+ //------------------------
+ // example:
+ // baseArray.forEach(function(item, idx) {
+ // ...
+ // });
+ //------------------------
+ _array.forEach(fn.bind(self));
+ return;
+ }
+ //------------------------
+ // example:
+ // baseArray.forEach(function(item, callback) {
+ // ...
+ // callback();
+ // }, function() {
+ //
+ // });
+ //------------------------
+ var finishCnt = 0;
+ var _arrayLength = _array.length;
+ _array.forEach(function(item, idx) {
+ fn.call(self, item, function() {
+ finishCnt++;
+ if (finishCnt === _arrayLength) {
+ callback.call(self);
+ }
+ });
+ });
};
self.empty = function() {

MODIFY
www/Map.js
www/Map.js
@@ -278,6 +278,58 @@ Map.prototype.setCameraBearing = function(bearing) {
return this;
};
+Map.prototype.moveCameraZoomIn = function(callback) {
+ var self = this;
+ var cameraPosition = self.get("camera");
+ cameraPosition.zoom++;
+ cameraPosition.zoom = cameraPosition.zoom < 0 ? 0 : cameraPosition.zoom;
+
+ exec(function() {
+ if (typeof callback === "function") {
+ callback.call(self);
+ }
+ }, self.errorHandler, self.id, 'animateCamera', [cameraPosition]);
+
+};
+Map.prototype.moveCameraZoomOut = function(callback) {
+ var self = this;
+ var cameraPosition = self.get("camera");
+ cameraPosition.zoom--;
+ cameraPosition.zoom = cameraPosition.zoom < 0 ? 0 : cameraPosition.zoom;
+
+ exec(function() {
+ if (typeof callback === "function") {
+ callback.call(self);
+ }
+ }, self.errorHandler, self.id, 'animateCamera', [cameraPosition]);
+
+};
+Map.prototype.animateCameraZoomIn = function(callback) {
+ var self = this;
+ var cameraPosition = self.get("camera");
+ cameraPosition.zoom++;
+ cameraPosition.zoom = cameraPosition.zoom < 0 ? 0 : cameraPosition.zoom;
+
+ exec(function() {
+ if (typeof callback === "function") {
+ callback.call(self);
+ }
+ }, self.errorHandler, self.id, 'animateCamera', [cameraPosition]);
+
+};
+Map.prototype.animateCameraZoomOut = function(callback) {
+ var self = this;
+ var cameraPosition = self.get("camera");
+ cameraPosition.zoom--;
+ cameraPosition.zoom = cameraPosition.zoom < 0 ? 0 : cameraPosition.zoom;
+
+ exec(function() {
+ if (typeof callback === "function") {
+ callback.call(self);
+ }
+ }, self.errorHandler, self.id, 'animateCamera', [cameraPosition]);
+
+};
/**
* @desc Move the map camera with animation
* @params {CameraPosition} cameraPosition New camera position
@@ -286,7 +338,7 @@ Map.prototype.setCameraBearing = function(bearing) {
Map.prototype.animateCamera = function(cameraPosition, callback) {
var self = this;
var target = cameraPosition.target;
- if (!target && position in cameraPosition) {
+ if (!target && "position" in cameraPosition) {
target = cameraPosition.position;
}
if (!target) {
@@ -313,7 +365,7 @@ Map.prototype.animateCamera = function(cameraPosition, callback) {
Map.prototype.moveCamera = function(cameraPosition, callback) {
var self = this;
var target = cameraPosition.target;
- if (!target && position in cameraPosition) {
+ if (!target && "position" in cameraPosition) {
target = cameraPosition.position;
}
if (!target) {
@@ -523,15 +575,15 @@ Map.prototype.setDiv = function(div) {
*/
Map.prototype.getVisibleRegion = function(callback) {
var self = this;
+ var northeast = self.get("camera_northeast");
+ var southwest = self.get("camera_southwest");
+ var latLngBounds = new LatLngBounds(northeast, southwest);
- exec(function(result) {
if (typeof callback === "function") {
- var latLngBounds = new LatLngBounds(result.latLngArray);
- latLngBounds.northeast = new LatLng(result.northeast.lat, result.northeast.lng);
- latLngBounds.southwest = new LatLng(result.southwest.lat, result.southwest.lng);
callback.call(self, latLngBounds);
}
- }, self.errorHandler, self.id, 'getVisibleRegion', []);
+
+ return latLngBounds;
};
/**
@@ -711,6 +763,8 @@ Map.prototype.addTileOverlay = function(tilelayerOptions, callback) {
Map.prototype.addPolygon = function(polygonOptions, callback) {
var self = this;
polygonOptions.points = polygonOptions.points || [];
+ var _orgs = polygonOptions.points;
+ polygonOptions.points = common.convertToPositionArray(polygonOptions.points);
polygonOptions.holes = polygonOptions.holes || [];
if (polygonOptions.holes.length > 0 && !Array.isArray(polygonOptions.holes[0])) {
polygonOptions.holes = [polygonOptions.holes];
@@ -735,6 +789,7 @@ Map.prototype.addPolygon = function(polygonOptions, callback) {
exec(function(result) {
polygonOptions.hashCode = result.hashCode;
+ polygonOptions.points = _orgs;
var polygon = new Polygon(self, result.id, polygonOptions);
self.OVERLAYS[result.id] = polygon;
polygon.one(result.id + "_remove", function() {
@@ -987,6 +1042,8 @@ Map.prototype._onCameraEvent = function(eventName, params) {
this.set('camera_zoom', cameraPosition.zoom);
this.set('camera_bearing', cameraPosition.bearing);
this.set('camera_tilt', cameraPosition.viewAngle || cameraPosition.tilt);
+ this.set('camera_northeast', cameraPosition.northeast);
+ this.set('camera_southwest', cameraPosition.southwest);
this.trigger(eventName, cameraPosition, this);
};
module.exports = Map;

Update: map.getVisibleRegion() returns the values as synchronize

Add:
  map.animateZoomIn(), map.animateZoomOut(), map.moveCameraZoomIn(), and map.moveCameraZoomOut()

Add:
  BaseArrayClass.forEach(fn, callback) and BaseArrayClass.map(fn, callback)