Implementing for browser
MODIFY
src/browser/CordovaGoogleMaps.js
src/browser/CordovaGoogleMaps.js
(function() {
var utils = require('cordova/utils');
- var PluginMap = require('cordova-plugin-googlemaps.PluginMap');
+ var PluginMap = require('cordova-plugin-googlemaps.PluginMap'),
+ event = require('cordova-plugin-googlemaps.event');
var MAP_CNT = 0;
var MAPS = {};
var maps = Object.values(MAPS);
maps.forEach(function(map) {
+ console.log(map.get("isGoogleReady"));
+ if (!map.get("isGoogleReady")) {
map.trigger("googleready");
- console.log(map);
+ }
});
}, {
once: true
var CordovaGoogleMaps = {
getMap: function(onSuccess, onError, args) {
- console.log("HelloWorld", args);
var mapId = args[0];
var pluginMap = new PluginMap(args);
MAPS[mapId] = pluginMap;
- console.log(pluginMap);
- onSuccess();
+ pluginMap.one(event.MAP_READY, onSuccess);
+
+ if (API_LOADED) {
+ pluginMap.trigger("googleready");
+ }
}
};

MODIFY
src/browser/PluginMap.js
src/browser/PluginMap.js
(function() {
- var utils = require('cordova/utils');
- var BaseClass = require('cordova-plugin-googlemaps.BaseClass');
+ var utils = require('cordova/utils'),
+ BaseClass = require('cordova-plugin-googlemaps.BaseClass'),
+ event = require('cordova-plugin-googlemaps.event');
function PluginMap(args) {
BaseClass.call(this);
var self = this;
- this.on("googleready", function() {
- console.log(args.length);
+ Object.defineProperty(this, "mapId", {
+ value: args[0],
+ writable: false
+ });
+
+ self.set("isGoogleReady", false);
+
+ this.one("googleready", function() {
+ self.set("isGoogleReady", true);
+
if (args.length === 3) {
- pluginId = args[2];
+ var mapOptions = args[1];
+ var pluginId = args[2];
var mapDiv = document.querySelector("[__plugindomid='" + pluginId + "']");
- self.set("map", new google.maps.Map(mapDiv, {
+
+ var gmap = new google.maps.Map(mapDiv, {
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: {lat: 0, lng: 0},
zoom: 0
- }));
+ });
+ self.set("gmap", gmap);
+
+ google.maps.event.addListenerOnce(gmap, "projection_changed", function() {
+ self.trigger(event.MAP_READY);
+ });
}
});

MODIFY
src/browser/googlemaps-cdv-plugin.js
src/browser/googlemaps-cdv-plugin.js
(function() {
var execCmd = require('cordova/exec');
- var common = require('cordova-plugin-googlemaps.Common');
+ var common = require('cordova-plugin-googlemaps.Common'),
+ event = require('cordova-plugin-googlemaps.event'),
+ MapTypeId = require('cordova-plugin-googlemaps.MapTypeId'),
+ LatLng = require('cordova-plugin-googlemaps.LatLng'),
+ LatLngBounds = require('cordova-plugin-googlemaps.LatLngBounds'),
+ Environment = require('cordova-plugin-googlemaps.Environment'),
+ Geocoder = require('cordova-plugin-googlemaps.Geocoder'),
+ BaseClass = require('cordova-plugin-googlemaps.BaseClass'),
+ BaseArrayClass = require('cordova-plugin-googlemaps.BaseArrayClass'),
+ encoding = require('cordova-plugin-googlemaps.encoding'),
+ spherical = require('cordova-plugin-googlemaps.spherical'),
+ HtmlInfoWindow = require('cordova-plugin-googlemaps.HtmlInfoWindow'),
+ Map = require('cordova-plugin-googlemaps.Map');
var saltHash = Math.floor(Math.random() * Date.now());
- var Map = require('cordova-plugin-googlemaps.Map');
var MAP_CNT = 0;
var MAPS = {};
module.exports = {
+ event: event,
+ MapTypeId: MapTypeId,
+ LatLng: LatLng,
+ LatLngBounds: LatLngBounds,
+ HtmlInfoWindow: HtmlInfoWindow,
+ environment: Environment,
+ Geocoder: Geocoder,
+ Animation: {
+ BOUNCE: 'BOUNCE',
+ DROP: 'DROP'
+ },
+ geometry: {
+ encoding: encoding,
+ spherical: spherical
+ },
Map: {
getMap: function(div, mapOptions) {
if (common.isDom(div)) {

Implementing for browser