Implementing fusion table
MODIFY
plugin.xml
plugin.xml
<?xml version='1.0' encoding='utf-8'?>
-<plugin id="cordova-plugin-googlemaps" version="2.5.0-beta-20181020-0912" 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.5.0-beta-20181020-1803" 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="Promise" src="www/Promise.js" />
<asset src="www/promise-7.0.4.min.js.map" target="promise-7.0.4.min.js.map" />

MODIFY
www/FusionTableOverlay.js
www/FusionTableOverlay.js
+
+
var utils = require('cordova/utils'),
common = require('./Common'),
- Overlay = require('./Overlay');
+ Overlay = require('./Overlay'),
+ BaseClass = require('./BaseClass'),
+ event = require('./event'),
+ BaseArrayClass = require('./BaseArrayClass');
/*****************************************************************************
* FusionTableOverlay Class
@@ -17,10 +22,70 @@ var FusionTableOverlay = function (map, FusionTableOverlayOptions, _exec) {
var visible = self.get('visible');
self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'setVisible', [self.getId(), visible]);
});
+
+ delete self._privateInitialize;
+
+ var onOverlayClick = function() {
+ var overlay = this;
+ self.trigger('fusion_click', overlay);
+ };
+
+ var _privateInitialize = function(kmlData) {
+ if (!kmlData) {
+ //-----------------------------------------------
+ // (browser)Trigger internal command queue
+ //-----------------------------------------------
+ Object.defineProperty(self, '_isReady', {
+ value: true,
+ writable: false
+ });
+ self.exec('nop');
+ return;
+ }
+
+ //--------------------------
+ // Listen XXX_CLICK events
+ //--------------------------
+ var eventNames = {
+ 'Marker': event.MARKER_CLICK,
+ 'Polyline': event.POLYLINE_CLICK,
+ 'Polygon': event.POLYGON_CLICK,
+ 'GroundOverlay': event.GROUND_OVERLAY_CLICK
+ };
+ var seekOverlays = function (overlay) {
+ if (overlay instanceof BaseArrayClass) {
+ overlay.forEach(seekOverlays);
+ } else if (Array.isArray(overlay)) {
+ (new BaseArrayClass(overlay)).forEach(seekOverlays);
+ } else if (overlay instanceof BaseClass && overlay.type in eventNames) {
+ overlay.on(eventNames[overlay.type], onOverlayClick);
+ }
+ };
+
+ kmlData.forEach(seekOverlays);
+
+
+
+ //-----------------------------------------------
+ // Trigger internal command queue
+ //-----------------------------------------------
+ Object.defineProperty(self, '_isReady', {
+ value: true,
+ writable: false
+ });
+ self.exec('nop');
+ };
+ Object.defineProperty(FusionTableOverlay.prototype, '_privateInitialize', {
+ enumerable: false,
+ value: _privateInitialize,
+ writable: false
+ });
+
};
utils.extend(FusionTableOverlay, Overlay);
+
FusionTableOverlay.prototype.getPluginName = function () {
return this.map.getId() + '-fusiontableoverlay';
};
@@ -43,6 +108,21 @@ FusionTableOverlay.prototype.getVisible = function () {
return this.get('visible');
};
+FusionTableOverlay.prototype.setOptions = function (options) {
+ var currentOptions = this.get('options');
+ this.set('options', {
+ clickable: 'clickable' in options ? common.defaultTrueOption(options.clickable) : currentOptions.clickable,
+ suppressInfoWindows: 'suppressInfoWindows' in options ? options.suppressInfoWindows === true : currentOptions.suppressInfoWindows,
+ query: {
+ from: options.query && 'from' in options.query ? options.query.from : currentOptions.query.from,
+ limit: options.query && 'from' in options.query ? options.query.limit : currentOptions.query.limit,
+ offset: options.query && 'from' in options.query ? options.query.offset : currentOptions.query.offset,
+ orderBy: options.query && 'from' in options.query ? options.query.orderBy : currentOptions.query.orderBy,
+ select: options.query && 'from' in options.query ? options.query.select : currentOptions.query.select,
+ where: options.query && 'from' in options.where ? options.query.where : currentOptions.query.where
+ }
+ });
+};
FusionTableOverlay.prototype.remove = function (callback) {
var self = this;
if (self._isRemoved) {

MODIFY
www/Map.js
www/Map.js
@@ -1041,67 +1041,121 @@ Map.prototype.addFusionTableOverlay = function(fusionTableOptions, callback) {
if (!fusionTableOptions) {
throw new Error('Please specify fusionTableOptions');
}
- if (!fusionTableOptions.select) {
- throw new Error('Please specify fusionTableOptions.select');
+ if (!fusionTableOptions.query) {
+ throw new Error('Please specify fusionTableOptions.query');
}
- if (!fusionTableOptions.from) {
- throw new Error('Please specify fusionTableOptions.from');
+ if (!fusionTableOptions.query.select) {
+ throw new Error('Please specify fusionTableOptions.query.select');
}
+ if (!fusionTableOptions.query.from) {
+ throw new Error('Please specify fusionTableOptions.query.from');
+ }
+ var limitedOptions = {
+ clickable: common.defaultTrueOption(fusionTableOptions.clickable),
+ suppressInfoWindows: fusionTableOptions.suppressInfoWindows === true,
+ query: {
+ from: fusionTableOptions.query.from,
+ limit: fusionTableOptions.query.limit,
+ offset: fusionTableOptions.query.offset,
+ orderBy: fusionTableOptions.query.orderBy,
+ select: fusionTableOptions.query.select,
+ where: fusionTableOptions.query.where
+ }
+ };
- var fusionTableOverlay = new FusionTableOverlay(self, fusionTableOptions, exec);
+ var fusionTableOverlay = new FusionTableOverlay(self, limitedOptions, exec);
if (cordova.platformId === 'browser') {
//----------------------------------
// Browser: use FusionTable layer
//----------------------------------
+ return (new Promise(function(resolve, reject) {
self.exec.call(self, function() {
fusionTableOverlay._privateInitialize();
- delete fusionTableOverlay._privateInitialize;
+ resolve(fusionTableOverlay);
+ }, reject,
+ self.__pgmId,
+ 'loadPlugin', ['FusionTableOverlay', limitedOptions, fusionTableOverlay.hashCode]);
+ }))
+ .then(function(overlay) {
if (typeof callback === 'function') {
- callback.call(self, fusionTableOverlay);
- }
- }, self.errorHandler, self.__pgmId, 'loadPlugin', ['FusionTableOverlay', fusionTableOptions, fusionTableOverlay.hashCode]);
-
- if (typeof callback === 'function') {
- callback(fusionTableOverlay);
- return;
+ callback.call(self, overlay);
} else {
- return Promise.resolve(fusionTableOverlay);
+ return Promise.resolve(overlay);
}
+ });
}
var query = ['select+',
- fusionTableOptions.select,
+ limitedOptions.query.select,
'+from+',
- fusionTableOptions.from];
- if (fusionTableOptions.where) {
- query.push('+where+' + fusionTableOptions.where);
+ limitedOptions.query.from];
+ if (limitedOptions.query.where) {
+ query.push('+where+' + limitedOptions.query.where);
}
- if (fusionTableOptions.orderBy) {
- query.push('+orderBy+' + fusionTableOptions.orderBy);
+ if (limitedOptions.query.orderBy) {
+ query.push('+orderBy+' + limitedOptions.query.orderBy);
}
- if (fusionTableOptions.offset) {
- query.push('+offset+' + fusionTableOptions.offset);
+ if (limitedOptions.query.offset) {
+ query.push('+offset+' + limitedOptions.query.offset);
}
- if (fusionTableOptions.limit) {
- query.push('+limit+' + fusionTableOptions.limit);
+ if (limitedOptions.query.limit) {
+ query.push('+limit+' + limitedOptions.query.limit);
} else {
query.push('+limit+1000');
}
- fusionTableOptions.url =
+ var kmlOptions = {
+ clickable: limitedOptions.clickable,
+ suppressInfoWindows: limitedOptions.suppressInfoWindows
+ };
+ kmlOptions.url =
'https://fusiontables.google.com/exporttable?query=' +
query.join('') +
- '&o=kml&g=' + fusionTableOptions.select +
+ '&o=kml&g=' + limitedOptions.query.select +
'&styleId=2&templateId=2'; // including '&styleId=2&templateId=2', FusionTable exports the latest KML file
- fusionTableOptions.clickable = common.defaultTrueOption(fusionTableOptions.clickable);
- fusionTableOptions.suppressInfoWindows = fusionTableOptions.suppressInfoWindows === true;
- return self.addKmlOverlay(fusionTableOptions, callback);
+ var link = document.createElement('a');
+ link.href = kmlOptions.url;
+ kmlOptions.url = link.protocol+'//'+link.host+link.pathname + link.search;
+
+ var invisible_dot = self.get('invisible_dot');
+ if (!invisible_dot || invisible_dot._isRemoved) {
+ // Create an invisible marker for kmlOverlay
+ self.set('invisible_dot', self.addMarker({
+ position: {
+ lat: 0,
+ lng: 0
+ },
+ icon: 'skyblue',
+ visible: false
+ }));
+ }
+
+ return (new Promise(function(resolve, reject) {
+
+ var loader = new KmlLoader(self, self.exec, kmlOptions);
+ loader.parseKmlFile(function(camera, kmlData) {
+ if (kmlData instanceof BaseClass) {
+ kmlData = new BaseArrayClass([kmlData]);
+ }
+ fusionTableOverlay._privateInitialize(kmlData);
+
+ resolve.call(self, fusionTableOverlay);
+ }, reject);
+
+ }))
+ .then(function(overlay) {
+ if (typeof callback === 'function') {
+ callback.call(self, overlay);
+ } else {
+ return Promise.resolve(overlay);
+ }
+ });
};

Implementing fusion table