Implementing fusion table overlay
MODIFY
www/KmlLoader.js
www/KmlLoader.js
+
var argscheck = require('cordova/argscheck'),
utils = require('cordova/utils'),
common = require('./Common'),
@@ -59,7 +60,7 @@ KmlLoader.prototype.parseKmlFile = function(callback) {
self.exec.call(self.map, function(kmlData) {
var rawKmlData = JSON.parse(JSON.stringify(kmlData));
-console.log(rawKmlData);
+//console.log(rawKmlData);
Object.defineProperty(self, "kmlStyles", {
value: kmlData.styles,
writable: false
@@ -489,17 +490,20 @@ KmlLoader.prototype.parsePointTag = function(params, callback) {
var markerOptions = {};
params.styles.children.forEach(function(child) {
switch (child.tagName) {
- case "balloonstyle":
- child.children.forEach(function(style) {
- switch (style.tagName) {
- case "text":
- markerOptions.description = {
- value: style.value
- };
- break;
- }
- });
- break;
+
+ // // Don't use this code because this replace original 'description' field.
+ // case "balloonstyle":
+ // child.children.forEach(function(style) {
+ // switch (style.tagName) {
+ // case "description":
+ // markerOptions.description = {
+ // value: style.value
+ // };
+ // break;
+ // }
+ // });
+ // break;
+
case "iconstyle":
child.children.forEach(function(style) {
switch (style.tagName) {
@@ -519,6 +523,10 @@ KmlLoader.prototype.parsePointTag = function(params, callback) {
markerOptions.icon = markerOptions.icon || {};
markerOptions.icon.color = kmlColorToRGBA(style.value);
break;
+ case "icon":
+ markerOptions.icon = markerOptions.icon || {};
+ markerOptions.icon.url = style.children[0].value;
+ break;
}
});
break;

MODIFY
www/KmlOverlay.js
www/KmlOverlay.js
+
var argscheck = require('cordova/argscheck'),
utils = require('cordova/utils'),
common = require('./Common'),
@@ -52,7 +53,7 @@ var KmlOverlay = function(map, kmlId, camera, kmlData, kmlOverlayOptions) {
return html.replace(/\$[\{\[](.+?)[\}\]]/gi, function(match, name) {
var text = "";
if (marker.get(name)) {
- text = marker.get(name).value || "";
+ text = marker.get(name).value;
}
if (extendedData && text) {
text = text.replace(/\$[\{\[](.+?)[\}\]]/gi, function(match1, name1) {
@@ -125,9 +126,7 @@ var KmlOverlay = function(map, kmlId, camera, kmlData, kmlOverlayOptions) {
descriptionTxt = description.value;
}
if (description && (descriptionTxt.indexOf("<html>") > -1 || descriptionTxt.indexOf("script") > -1)) {
-console.log(descriptionTxt, overlay);
var text = templateRenderer(descriptionTxt, overlay);
-console.log(text);
// create a sandbox
// if (text.indexOf("<html") === -1) {
// text = "<html><body>" + text + "</body></html>";
@@ -172,6 +171,9 @@ console.log(text);
// once: true
//});
+ } else {
+ if (overlay.get("description")) {
+ html.push("<div style='font-weight: 300; font-size: small; font-family: Roboto,Arial,sans-serif;white-space:pre;min-width:100px;padding: auto 0.5em;'>${description}</div>");
} else {
if (overlay.get("name")) {
html.push("<div style='font-weight: 500; font-size: medium; margin-bottom: 0em'>${name}</div>");
@@ -179,8 +181,6 @@ console.log(text);
if (overlay.get("_snippet")) {
html.push("<div style='font-weight: 300; font-size: small; font-family: Roboto,Arial,sans-serif;'>${_snippet}</div>");
}
- if (overlay.get("description")) {
- html.push("<div style='font-weight: 300; font-size: small; font-family: Roboto,Arial,sans-serif;white-space:normal'>${description}</div>");
}
var prevMatchedCnt = 0;
result = html.join("");

MODIFY
www/Map.js
www/Map.js
+
var utils = require('cordova/utils'),
cordova_exec = require('cordova/exec'),
common = require('./Common'),
@@ -1045,22 +1046,6 @@ Map.prototype.addKmlOverlay = function(kmlOverlayOptions, callback) {
}
};
-/*
-Map.prototype.addFusionTableOverlay = function(fusionTableOptions, callback) {
- var self = this;
-
- if (!fusionTableOptions) {
- throw new Error('Please specify fusionTableOptions');
- }
- if (!fusionTableOptions.select) {
- throw new Error('Please specify fusionTableOptions.select');
- }
- if (!fusionTableOptions.from) {
- throw new Error('Please specify fusionTableOptions.from');
- }
-
-};
-*/
//-----------------------------------------
// Experimental: FusionTableOverlay
//-----------------------------------------
@@ -1123,12 +1108,12 @@ Map.prototype.addFusionTableOverlay = function(fusionTableOptions, callback) {
fusionTableOptions.url =
"https://fusiontables.google.com/exporttable\?query=" +
query.join('') +
- "&o=kml&g=" + fusionTableOptions.select;
+ "&o=kml&g=" + fusionTableOptions.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;
-console.log(fusionTableOptions);
return self.addKmlOverlay(fusionTableOptions, callback);
};

Implementing fusion table overlay