Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Dron007/33205981b11ab4cadb31 to your computer and use it in GitHub Desktop.
Save Dron007/33205981b11ab4cadb31 to your computer and use it in GitHub Desktop.
IITC plugin: Ingress KML Exporter
// ==UserScript==
// @id iitc-plugin-CSV@pad
// @name IITC plugin: Ingress KML Exporter
// @category Keys
// @version 1.0.20160105.02
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
// @updateURL https://gist.github.com/Dron007/33205981b11ab4cadb31/raw/f425c125f236256998f143f385249006c0442223/iitc-plugin-ingressKML-exporter.user.js
// @downloadURL https://gist.github.com/Dron007/33205981b11ab4cadb31/raw/f425c125f236256998f143f385249006c0442223/iitc-plugin-ingressKML-exporter.user.js
// @description Exports portals currently in view for use with Google Map ( KML Format ).
// @include https://www.ingress.com/intel*
// @include http://www.ingress.com/intel*
// @match https://www.ingress.com/intel*
// @match http://www.ingress.com/intel*
// @grant none
// ==/UserScript==
function wrapper() {
// in case IITC is not available yet, define the base plugin object
if (typeof window.plugin !== "function") {
window.plugin = function() {};
}
// base context for plugin
window.plugin.ingressKMLexporter = function() {};
var self = window.plugin.ingressKMLexporter;
// custom dialog wrapper with more flexibility
self.TEAM_STYLES = ["none", "res", "enl"];
self.TEAM_COLORS = ["B00066FF", "B0D09205", "B002BF02"];
self.portalInScreen = function portalInScreen( p ) {
return map.getBounds().contains(p.getLatLng())
}
self.genStyle = function genStyle(team, o) {
var teamStyleName = self.TEAM_STYLES[team];
var teamStyleColor = self.TEAM_COLORS[team];
o.push('<Style id="' + teamStyleName + '-inactive">');
o.push(' <IconStyle>');
o.push(' <Icon><href>http://www.gstatic.com/mapspro/images/stock/959-wht-circle-blank.png</href></Icon>');
o.push(' <color>' + teamStyleColor + '</color>');
o.push(' </IconStyle>');
o.push(' <LabelStyle><scale>0</scale></LabelStyle>');
o.push(' <BalloonStyle><text><![CDATA[$[description]]]></text></BalloonStyle>');
o.push('</Style>');
o.push('<Style id="' + teamStyleName + '-active">');
o.push(' <IconStyle>');
o.push(' <Icon><href>http://www.gstatic.com/mapspro/images/stock/959-wht-circle-blank.png</href></Icon>');
o.push(' <color>' + teamStyleColor + '</color>');
o.push(' </IconStyle>');
o.push(' <LabelStyle><scale>1</scale></LabelStyle>');
o.push(' <BalloonStyle><text><![CDATA[$[description]]]></text></BalloonStyle>');
o.push('</Style>');
o.push('<StyleMap id="' + teamStyleName + '">');
o.push(' <Pair><key>normal</key><styleUrl>#' + teamStyleName + '-inactive</styleUrl></Pair>');
o.push(' <Pair><key>highlight</key><styleUrl>#' + teamStyleName + '-active</styleUrl></Pair>');
o.push('</StyleMap>');
}
self.gen = function gen() {
var o = [];
var inBounds = function( portal ) {
return self.portalInScreen( portal );
}
// var string = "Portal selection based on screen boundaries.";
o.push('<?xml version="1.0" encoding="UTF-8"?>');
o.push('<kml xmlns="http://www.opengis.net/kml/2.2">');
o.push(' <Document>');
o.push(' <name>Import from IITC</name>');
for (var x in window.portals) {
var p = window.portals[x];
if (inBounds(p)) {
console.log(p);
var title = p.options.data.title;
var level = p.options.data.level;
var resCount = p.options.data.resCount;
var health = p.options.data.health + '%';
title = title.replace(/["«»]/g, '&quot;');//'""');
title = title.replace(/'/g, '&apos;');
title = title.replace(/</g, '&lt;');
title = title.replace(/>/g, '&gt;');
title = title.replace(/&/g, '&amp;');
var teamStyle = self.TEAM_STYLES[p.options.team];
o.push(' <Placemark>');
o.push(' <description><![CDATA[<p><ul><li>Level: ' + level + '</li><li>Resonators: ' + resCount + '</li><li>Health: ' + health + '</li></ul></p>]]></description>');
o.push(' <styleUrl>#' + teamStyle + '</styleUrl>');
o.push(' <name>' + title + '</name>');
o.push(' <Point>');
o.push(' <coordinates>' + p._latlng.lng + "," + p._latlng.lat + ',0.0</coordinates>');
o.push(' </Point>');
o.push(' </Placemark>');
}
}
self.genStyle(0, o);
self.genStyle(1, o);
self.genStyle(2, o);
o.push(' </Document>');
o.push('</kml>');
var dialog = window.dialog({
title: "Ingress KML Exporter",
// body must be wrapped in an outer tag (e.g. <div>content</div>)
html: '<span>Save the data below to a KML file and import it on <code> https://www.google.com/maps/d </code>.</span><textarea id="idKMLexporter" rows="30" style="width: 100%;"></textarea>'
}).parent();
$(".ui-dialog-buttonpane", dialog).remove();
dialog.css("width", "600px")
.css("top", ($(window).height() - dialog.height()) / 2)
.css("left", ($(window).width() - dialog.width()) / 2);
$("#idKMLexporter").val(o.join("\n"));
return dialog;
};
// setup function called by IITC
self.setup = function init() {
// add controls to toolbox
var link = $("<a onclick=\"window.plugin.ingressKMLexporter.gen();\" title=\"Generate KML list of portals and locations.\">KML Export</a>");
$("#toolbox").append(link);
// delete setup to ensure init can't be run again
delete self.setup;
};
// IITC plugin setup
if (window.iitcLoaded && typeof self.setup === "function") {
self.setup();
} else if (window.bootPlugins) {
window.bootPlugins.push(self.setup);
} else {
window.bootPlugins = [self.setup];
}
}
// inject plugin into page
var script = document.createElement("script");
script.appendChild(document.createTextNode("(" + wrapper + ")();"));
(document.body || document.head || document.documentElement).appendChild(script);
@trefmanic
Copy link

Small patch to export portal photo URLs to the KML file.

After line 80:
var imgLink = p.options.data.image;
And then line 90:
o.push(' <description><![CDATA[<p align=center><img src="' + imgLink +'" width="150"></p><p><ul><li>Level: ' + level + '</li><li>Resonators: ' + resCount + '</li><li>Health: ' + health + '</li></ul></p>]]></description>');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment