Mars trilogy

The Mars trilogy is a work by Kim Stanley Robinson, often considered to be Robinson's magnum opus and his most well-known work. Robinson also wrote a companion volume composed of short stories and essays often taking place in the same universe, The Martians.

Red Mars 
(1992)

Green Mars 
(1993)

Blue Mars 
(1996)

The Martians 
Companion volume (1999)

The trilogy follows the colonization of Mars and later the entire solar system, complete with the technological, moral, social and political evolution that accompanies it, spanning 200 years of future history. Made after an extensive research period and reaching 2000 pages, many of Robinson's previous novels, such as Icehenge and Pacific Edge are in many ways precursors to the trilogy in themes or setting. Each novel takes its name from the color of the planet Mars as it evolves through the process of terraforming.

Key pages

Comments

Comment: 

All the links from thsi page are dead:

http://kimstanleyrobinson.info/content/mars-trilogy

and result o a message of the form:

Page not found

The requested page "/d/node/554" could not be found.

and the "preview" button on this mesage box does nto work eithr... :-(
(function wrapper(plugin_info) {
// ensure plugin framework is there, even if iitc is not yet loaded
if (typeof window.plugin !== 'function') {
window.plugin = function () {
};
}

// PLUGIN START ////////////////////////////////////////////////////////

// use own namespace for plugin
window.plugin.portalTags = function () {
};

window.plugin.portalTags.version = '0.4.10';

window.plugin.portalTags.markers = {
"white": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAoCAQAAAA1IDASAAAAAmJLR0QA/4ePzL8AAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQffAxoWCQZ3sgjPAAAFDElEQVRIx32W228UdRTHP3PZO7u9LNCyUiMNlxJUSCBEo2KRWKmlahNNTHixiQnGB15I1AdeiPwFhgdfjCGRSBOKNAaJNMUmINICtpFLL5TSxHYr3bbjsjszO7tz8WFmL715fg8z88vvfM/3fM+ZMyOw3AQARGQkQPJ2LcDCxAbAWX586bOITLy1PbgntMvd1B/khq/08RSrBOKwqgkISASaO06MdSdnslbBcRzHKsxku5Mnxpo7iBMlgISwInCFe7j12JmpmaxmOBWmGTPZM1Otx0gQJ7w6RMm9O7nUuQzSnWw/tTaEgESg9Vh30iVeabZ3tQolCDeRCpUFwNf87sFTnyZE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Xor5nYpCjig/zwL01Cwuo4IPucAAAAAElFTkSuQmCC",
"red": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAoCAYAAACfKfiZAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3wMaFDgv8NlDfwAACIxJREFUWMOdV19sHMUZ/83s7K339u6yZ8fn/HFM/jhAZFKlLRAQESlFopKTVn0opA9A1CpVmjZCohVqhagoEg99RlTqUwQvbahQVISEWhRjHDupEppyNnFCI7B8cjDK2eeL7273bm52Zvpwt87d5uI4jPTp7nbn5vv9fvN933xDcOdBWr5TAAyA0fxtRObKls8AgGp5p++0+GrvKQAWJ6Tn147zwzile2xChlonVrWe9pXKnvD9kYJS15sgokD03QBoc37ccYYftaw/PZFMJq0nnkgZW7ZY1HUZAKgbNwI5N8f56GhptFwu/5vz37/peWcA1Jt2WxDGGpxbLyUSh59znNcfPHhwQ2zv3gQbGLBJLEahFKAUSCxGjd7emLF9u7Wjv9/Zlss9vo6QpawQs6LhQzcB6ChpYw3On3uxp+fVzLPPZtjAgE0IufkfrW+alCCGYRgbN8bc++6LPzgz8zCVklwUIisaa3YEcTsAFAB7KZE4/GJPz6vx55/vNVzX1EIAjAHk1p3T9TqIZQFSgiYSBtu1y/721av3R0AETQD6dgDClc3jjjN8wLZf23rkyCaaSDAtBLQQDaaMAUqhfvFiWc7P140NGyximtCcA6qx1dS2Kdu1y94wObk9Tkg+K8SXohGUuhmcJJQ5OiiAxCBjr3/n4MG+NufhUArENJE9c2Yhe+bMAjHNFccAEM6niQTbOjy8frNhvECBXgCxJmna6iw62HHHefwZ102bu3c7uloF6M1pxDRBTBP87NnlUc4/mRaiJq5c8cLnN2lQ6GoV5u7dzjOumz7mOI/0UJoGYDdryS0Awr03Bhl73T50qBtB0MaYENJwwhiy584VpoX47yjnb89+8MEiGGufEyoSBLAPHerebBgvcK2dOCFWiwrkFgV6KN00ZJpdRl+ftfIwCEBME1pryEKB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KAapB+bW1T+49Cvs9r+eZ/aF/s5Vu3GkYbKiS9yaOHRi3TOkp0KiO/JiO6rftzje9hX/Xg42PAPgSsgOgByACIPf6h4Tus7puqxAI9/Jye7am5xnPj20Z1/OML7dna63g3qUk72uDyu4jK7CHCncMxbJYN/+9ydNjulFU5Mr1m63V3tKHdlS7ltrxvIex37cC2ep4x7156YZ9rdp/f8O+Vq0Hty9lav7AvN91E8ajtThRbT2WwQdffHb1twAQy+CDAdLH+1mQPIr11A06B0AbN6d/CQDJP2NuKurd/bAHgP8Dtc8flm3QFHMAAAAASUVORK5CYII=",
};

window.plugin.portalTags.highlight = function (data) {
var guid = data.portal.options.ent[0];
if (window.plugin.portalTags.portalTags[guid] !== undefined) {
data.portal.setStyle({fillColor: 'yellow'});
}
};

window.plugin.portalTags.highlightRefresh = function (data) {
if (_current_highlighter === 'Tagged Portals') {
if (data.action === 'sync' || data.target === 'portal' || (data.target === 'folder' && data.action === 'remove') || (data.target === 'all' && data.action === 'import') || (data.target === 'all' && data.action === 'reset')) {
window.resetHighlightedPortals();
}
}
};

window.plugin.portalTags.saveStorage = function () {
localStorage.portalTags = JSON.stringify(window.plugin.portalTags.portalTags);
};

window.plugin.portalTags.loadStorage = function () {
window.plugin.portalTags.removeAllMarkers();
var x = localStorage.portalTags;
if (x !== undefined) {
window.plugin.portalTags.portalTags = JSON.parse(x);
}

if (window.plugin.portalTags.portalTags === undefined) {
window.plugin.portalTags.portalTags = {};
}
window.plugin.portalTags.addAllMarkers();
};

window.plugin.portalTags.removeAllMarkers = function () {
var list = window.plugin.portalTags.tagMarkers;
if (list === undefined) {
return;
}
for (var guid in list) {
var marker = list[guid];
window.plugin.portalTags.taggedLayerGroup.removeLayer(marker);
delete window.plugin.portalTags.tagMarkers[guid];
}
};

window.plugin.portalTags.addAllMarkers = function () {
var list = window.plugin.portalTags.portalTags;

for (var guid in list) {
var data = list[guid];
window.plugin.portalTags.updateMarker(guid, data.ll, data.tags, data.n);
}
};

window.plugin.portalTags.sizes = [[[15,40],[30,40]],[[8,20],[16,20]],[[30,80],[60,80]]];
window.plugin.portalTags.getMarker = function(tags,n) {
if (n === undefined) {
return {size: window.plugin.portalTags.sizes[2], img:window.plugin.portalTags.markers.yellow};
}
var markerImg = window.plugin.portalTags.markers.violet;
var size = 0;
if (tags.indexOf("#resx")!=-1) {
markerImg = window.plugin.portalTags.markers.blue;
} else if (tags.indexOf('#enlx')!=-1) {
markerImg = window.plugin.portalTags.markers.green;
} else if (tags.indexOf('#res')!=-1) {
markerImg = window.plugin.portalTags.markers.orange;
size = 1;
} else if (tags.indexOf('#enl')!=-1) {
markerImg = window.plugin.portalTags.markers.red;
size = 1;
} else if (tags.indexOf('#-')!=-1) {
markerImg = window.plugin.portalTags.markers.black;
size = 1;
} else if (tags.indexOf('#+')!=-1) {
markerImg = window.plugin.portalTags.markers.white;
size = 1;
}
return {size: window.plugin.portalTags.sizes[size], img:markerImg};
};

window.plugin.portalTags.updateMarker = function (guid, latlng, tags, title) {
var md;

if (latlng===undefined) {
return;
}
var marker = window.plugin.portalTags.tagMarkers[guid];
if (marker === undefined) {
if (tags === '') {
return;
}

md = window.plugin.portalTags.getMarker(tags, title);
marker = L.marker(
latlng,
{
title: tags,
icon: L.icon(
{
iconUrl: md.img,
iconAnchor: md.size[0], // [15, 40],
iconSize: md.size[1] // [30, 40]
}
)
}
);
window.plugin.portalTags.tagMarkers[guid] = marker;
window.registerMarkerForOMS(marker);
marker.on('spiderfiedclick', function () {
renderPortalDetails(guid);
});
marker.addTo(window.plugin.portalTags.taggedLayerGroup);
}

window.plugin.portalTags.taggedLayerGroup.removeLayer(marker);
if (tags === '') {
delete window.plugin.portalTags.tagMarkers[guid];
return;
}

{
md = window.plugin.portalTags.getMarker(tags, title);
marker.options.icon.options.iconUrl = md.img;
marker.options.icon.options.iconAnchor = md.size[0];
marker.options.icon.options.iconSize = md.size[1];
marker.options.title = tags;
marker.addTo(window.plugin.portalTags.taggedLayerGroup);
}
};

window.plugin.portalTags.setup = function () {
if (window.plugin.drawTools === undefined) {
alert("'portalTags' requires 'draw-tools'");
return;
}
if (window.plugin.crossLinks === undefined) {
alert("'portalTags' requires 'cross links'");
return;
}

window.plugin.portalTags.taggedLayerGroup = new L.LayerGroup();
window.plugin.portalTags.tagMarkers = {};

window.addPortalHighlighter('Tagged Portals', window.plugin.portalTags.highlight);
window.addLayerGroup('Tagged Portals', window.plugin.portalTags.taggedLayerGroup, true);

window.plugin.portalTags.loadStorage();

window.addHook('portalDetailsUpdated', window.plugin.portalTags.onPortalDetailLoaded);
$('head').append('.ui-dialog-tag-csv-export-throw-order { width: 96%; height: 250px; resize: vertical}');
var toolbox = $('#toolbox');
toolbox.append('portalTags version: '+window.plugin.portalTags.version+'TagOptions');
toolbox.append('TagDraw');
toolbox.append('TagBlockers');
};

window.plugin.portalTags.optReset = function () {
window.plugin.portalTags.portalTags = {};
window.plugin.portalTags.removeAllMarkers();
window.plugin.portalTags.saveStorage();
};

window.plugin.portalTags.optCopy = function () {
dialog({
html: 'Select all and press CTRL+C to copy it.' + localStorage.portalTags + '',
dialogClass: 'ui-dialog-drawtoolsSet-copy',
title: 'Portal Tags Copy'
});
};

window.plugin.portalTags.optPaste = function () {
var promptAction = prompt('Press CTRL+V to paste tags.', '');
if (promptAction !== null && promptAction !== '') {
try {
var data = JSON.parse(promptAction); // try to parse JSON first
localStorage.portalTags = promptAction;
window.plugin.portalTags.portalTags = data;
window.plugin.portalTags.removeAllMarkers();
window.plugin.portalTags.addAllMarkers();
} catch (e) {
console.warn('portalTags: failed to import data: ' + e);
window.plugin.portalTags.optAlert('Import failed ');
}
}
};

window.plugin.portalTags.lineColor = [
'#aa44cc',
'#aa4422',
'#44ccaa',
'#aacc44',
'#aa2244',
'#44aa44',
'#44aacc',
'#4422cc'
];

window.plugin.portalTags.precomputedDouble = {
"4": [[0,1,2,0,3,2]],
"4z": [[1,3]],
"5": [[0,1,2,0,3,2],[3,4,0]],
"5z": [[1,3],[2,4]]
/*
"6": [[0,1,2,0,3,2],[3,4,0,5,4]],
"6z": [[1,3,5],[2,4]],
"7": [[0,1,2,0,3,2],[3,4,0,5,4],[5,6,0]],
"7z": [[1,3,5],[2,4,6]],
"8": [[0,1,2,0,3,2],[3,4,0,5,4],[5,6,0,7,6]],
"8z": [[1,3,5,7],[2,4,6]],
"9": [[0,1,2,0,3,2],[3,4,0,5,4],[5,6,0,7,6],[7,8,0]],
"9z": [[1,3,5,7],[2,4,6,8]],
"10": [[0,1,2,0,3,2],[3,4,0,5,4],[5,6,0,7,6],[7,8,0,9,8]],
"10z": [[1,3,5,7,9],[2,4,6,8]],
"11": [[0,1,2,0,3,2],[3,4,0,5,4],[5,6,0,7,6],[7,8,0,9,8],[9,10,0]],
"11z": [[1,3,5,7,9],[2,4,6,8,10]],
"12": [[0,1,2,0,3,2],[3,4,0,5,4],[5,6,0,7,6],[7,8,0,9,8],[9,10,0,11,10]],
"12z": [[1,3,5,7,9,11],[2,4,6,8,10]],
"13": [[0,1,2,0,3,2],[3,4,0,5,4],[5,6,0,7,6],[7,8,0,9,8],[9,10,0,11,10],[11,12,0]],
"13z": [[1,3,5,7,9,11],[2,4,6,8,10,12]],
"14": [[0,1,2,0,3,2],[3,4,0,5,4],[5,6,0,7,6],[7,8,0,9,8],[9,10,0,11,10],[11,12,0,13,12]],
"14z": [[1,3,5,7,9,11,13],[2,4,6,8,10,12]],
"15": [[0,1,2,0,3,2],[3,4,0,5,4],[5,6,0,7,6],[7,8,0,9,8],[9,10,0,11,10],[11,12,0,13,12],[13,14,0]],
"15z": [[1,3,5,7,9,11,13],[2,4,6,8,10,12,14]],
"16": [[0,1,2,0,3,2],[3,4,0,5,4],[5,6,0,7,6],[7,8,0,9,8],[9,10,0,11,10],[11,12,0,13,12],[13,14,0,15,14]],
"16z": [[1,3,5,7,9,11,13,15],[2,4,6,8,10,12,14]],
"17": [[0,1,2,0,3,2],[3,4,0,5,4],[5,6,0,7,6],[7,8,0,9,8],[9,10,0,11,10],[11,12,0,13,12],[13,14,0,15,14],[15,16,0]],
"17z": [[1,3,5,7,9,11,13,15],[2,4,6,8,10,12,14,16]],
"18": [[0,1,2,0,3,2],[3,4,0,5,4],[5,6,0,7,6],[7,8,0,9,8],[9,10,0,11,10],[11,12,0,13,12],[13,14,0,15,14],[15,16,0,17,16]],
"18z": [[1,3,5,7,9,11,13,15,17],[2,4,6,8,10,12,14,16]],
"19": [[0,1,2,0,3,2],[3,4,0,5,4],[5,6,0,7,6],[7,8,0,9,8],[9,10,0,11,10],[11,12,0,13,12],[13,14,0,15,14],[15,16,0,17,16],[17,18,0]],
"19z": [[1,3,5,7,9,11,13,15,17],[2,4,6,8,10,12,14,16,18]],
"20": [[0,1,2,0,3,2],[3,4,0,5,4],[5,6,0,7,6],[7,8,0,9,8],[9,10,0,11,10],[11,12,0,13,12],[13,14,0,15,14],[15,16,0,17,16],[17,18,0,19,18]],
"20z": [[1,3,5,7,9,11,13,15,17,19],[2,4,6,8,10,12,14,16,18]],
"21": [[0,1,2,0,3,2],[3,4,0,5,4],[5,6,0,7,6],[7,8,0,9,8],[9,10,0,11,10],[11,12,0,13,12],[13,14,0,15,14],[15,16,0,17,16],[17,18,0,19,18],[19,20,0]],
"21z": [[1,3,5,7,9,11,13,15,17,19],[2,4,6,8,10,12,14,16,18,20]],
*/
};

window.plugin.portalTags.lookupDouble = function(n) {
var key = n+'';
if (window.plugin.portalTags.precomputedDouble[key] !== undefined)
{
return window.plugin.portalTags.precomputedDouble[key];
}
var x = JSON.parse(JSON.stringify(window.plugin.portalTags.lookupDouble(n-1))); // deep copy
var xl = x[x.length-1];
if (xl.length==3) {
xl.push(n-1,n-2);
} else {
x.push([n-2,n-1,0]);
}
window.plugin.portalTags.precomputedDouble[key]=x;
return x;
};

window.plugin.portalTags.lookupDoubleZip = function(n) {
var key = n+'z';
if (window.plugin.portalTags.precomputedDouble[key] !== undefined)
{
return window.plugin.portalTags.precomputedDouble[key];
}
var x = JSON.parse(JSON.stringify(window.plugin.portalTags.lookupDoubleZip(n-1))); // deep copy
if (n%2===0) {
x[0].push(n-1);
} else {
x[1].push(n-1);
}
window.plugin.portalTags.precomputedDouble[key]=x;
return x;
};

window.plugin.portalTags.precomputedTriple = {
"4": [[0,1,2,0],[2,3,1]],
"4z": [[0,3]]
/*
"5": [[0,1,2,0],[2,3,1],[3,4,2]],
"5z": [[0,3],[1,4]],
"6": [[0,1,2,0],[2,3,1],[3,4,2],[4,5,3]],
"6z": [[0,3],[1,4],[2,5]],
"7": [[0,1,2,0],[2,3,1],[3,4,2],[4,5,3],[5,6,4]],
"7z": [[0,3],[1,4],[2,5],[3,6]],
"8": [[0,1,2,0],[2,3,1],[3,4,2],[4,5,3],[5,6,4],[6,7,5]],
"8z": [[0,3],[1,4],[2,5],[3,6],[4,7]],
"9": [[0,1,2,0],[2,3,1],[3,4,2],[4,5,3],[5,6,4],[6,7,5],[7,8,6]],
"9z": [[0,3],[1,4],[2,5],[3,6],[4,7],[5,8]],
*/
};

window.plugin.portalTags.lookupTriple = function(n) {
var key = n+'';
if (window.plugin.portalTags.precomputedTriple[key] !== undefined)
{
return window.plugin.portalTags.precomputedTriple[key];
}
var x = JSON.parse(JSON.stringify(window.plugin.portalTags.lookupTriple(n-1))); // deep copy
var xl = x[x.length-1];
var nl = [xl[0]+1,xl[1]+1,xl[2]+1];
x.push(nl);
window.plugin.portalTags.precomputedTriple[key]=x;
return x;
};

window.plugin.portalTags.lookupTripleZip = function(n) {
var key = n+'z';
if (window.plugin.portalTags.precomputedTriple[key] !== undefined)
{
return window.plugin.portalTags.precomputedTriple[key];
}
var x = JSON.parse(JSON.stringify(window.plugin.portalTags.lookupTripleZip(n-1))); // deep copy
var xl = x[x.length-1];
var nl = [xl[0]+1,xl[1]+1];
x.push(nl);
window.plugin.portalTags.precomputedTriple[key]=x;
return x;
};

window.plugin.portalTags.drawLines = function(lines, set, lineOptions) {
if (lines !== undefined) {
for (var li in lines) {
var line = lines[li];
var ll = [];

for (var lli in line) {
ll[lli] = set[line[lli]].data.ll;
}

map.fire('draw:created', {
layer: L.geodesicPolyline(ll, lineOptions),
layerType: 'polyline'
});
}
}
};

window.plugin.portalTags.computeSets = function () {
var sets = {};
var setOpts = {};
// for each tagged portal
// add to set based on first character

for (var tp in window.plugin.portalTags.portalTags) {
var data = window.plugin.portalTags.portalTags[tp];
var tags = data.tags;

var asArr = tags.split(/[,\s]+/);
console.log(asArr);
console.log(tp + ": " + JSON.stringify(asArr));
for (var tagIndex in asArr) {
var tag = asArr[tagIndex];

var setChar = tag.charAt(0);
if (setChar === '#') {
continue;
}
if (setChar === '@') {
var rx = /@(.)\[([^;]*)(?:;([^;]*))*\]/g;

var grps = rx.exec(tag);
if (!grps) {
var message = "Invalid tag: " + tag + " on " + data.guid + ' ' + data.n;
console.log(message);
window.alert(message);
continue;
}
if (grps.length < 2) {
continue;
}
setChar = grps[1];
if (setOpts[setChar] === undefined) {
setOpts[setChar] = {};
}

for (var grpIndex = 2; grpIndex < grps.length; ++grpIndex) {
var opt = grps[grpIndex];
if (opt === undefined) {
continue;
}
var sOpt = opt.split(':');
if (sOpt.length == 1) {
setOpts[setChar][opt] = 1;
}
else {
setOpts[setChar][sOpt[0]] = sOpt[1];
}
}

console.log(setChar + ": " + JSON.stringify(setOpts[setChar]));
continue;
}
console.log(tag + ": " + setChar);
if (sets[setChar] === undefined) {
sets[setChar] = [];
}
sets[setChar].push({data:data,t:tag});
}
}
for(var s in sets) {
sets[s] = sets[s].sort(function(a,b) { if (a.tb.t) return 1; return 0;} );
}
console.log(sets);
return {sets: sets, setOpts: setOpts};
};

window.plugin.portalTags.tagDraw = function () {

// window.plugin.portalTags.tagClearBlockers();

var __ret = window.plugin.portalTags.computeSets();
var sets = __ret.sets;
var setOpts = __ret.setOpts;

try {
window.plugin.drawTools.optReset();
} catch (e) {
console.log(e);
}

var seti = 0;

var globalOpts = setOpts['*'];
if (globalOpts === undefined) {
globalOpts = {};
}

for (var setIndex in sets) {
var set = sets[setIndex];
if (set===undefined)
{
continue;
}
if (set.length==1)
{
continue;
}

var opts = {};
if (setOpts[setIndex] !== undefined) {
opts = setOpts[setIndex];
}
var zip = opts.zip;

if (zip === undefined) {
zip = globalOpts.zip;
}
var lineColor = opts.color;
if (lineColor === undefined) {
lineColor = globalOpts.color;
}
if (lineColor === undefined) {
var lci = seti++ % window.plugin.portalTags.lineColor.length;
lineColor = window.plugin.portalTags.lineColor[lci];
}
var lineOptions = {stroke: true, color: lineColor, weight: 4, opacity: 0.5, fill: false, clickable: true};

if (set.length==2)
{
map.fire('draw:created', {
layer: L.geodesicPolyline([set[0].data.ll,set[1].data.ll], lineOptions),
layerType:'polyline'
});
continue;
}

var pull = opts.pull;
if (pull === undefined)
{
pull = 'single';
}

if (pull === 'single') {
var latlngs = [];
var ziplatlngs = [];
latlngs.push(set[0].data.ll);
latlngs.push(set[1].data.ll);

var ai = 0;
for (var i = 2; i < set.length; ++i) {
latlngs.push(set[i].data.ll);
ziplatlngs.push(set[i].data.ll);
latlngs.push(latlngs[ai]);
ai ^= 1;
}

var layerType = 'polyline';
var layer = L.geodesicPolyline(latlngs, lineOptions);
map.fire('draw:created', {
layer: layer,
layerType: layerType
});

if (zip === 1 && ziplatlngs.length > 0) {
var ziplayer = L.geodesicPolyline(ziplatlngs, lineOptions);
map.fire('draw:created', {
layer: ziplayer,
layerType: layerType
});
}
} else if (pull === 'double') {
// first is pivot, then throws in alternating order
// use a+ for the pivot and then evens (0,2,4,6,...) for one direction and odds (1,3,5,7,...) for the other.

var lines = window.plugin.portalTags.lookupDouble(set.length);
window.plugin.portalTags.drawLines(lines, set, lineOptions);
if (zip)
{
lines = window.plugin.portalTags.lookupDoubleZip(set.length);
window.plugin.portalTags.drawLines(lines, set, lineOptions);
}
} else if (pull === 'triple') {
// use a0, a1, a2 and then by 3's in each director (0,3,6,9,...), (1,4,7,10,...), (2,5,8,11,...)
var lines = window.plugin.portalTags.lookupTriple(set.length);
window.plugin.portalTags.drawLines(lines, set, lineOptions);
if (zip)
{
lines = window.plugin.portalTags.lookupTripleZip(set.length);
window.plugin.portalTags.drawLines(lines, set, lineOptions);
}
}
}
};

window.plugin.portalTags.optAlert = function (message) {
$('.ui-dialog-drawtoolsSet .ui-dialog-buttonset').prepend('' + message + '');
$('.drawrtools-alert').delay(2500).fadeOut();
};

window.plugin.portalTags.showOptionsDialog = function () {
console.log("Portal Tags: showOptionsDialog");
var actions = '';
actions += 'Reset All Tags';
actions += 'Reset Only Blocker Tags';
actions += 'Copy Tags';
actions += 'Paste Tags';
actions += 'CSV Export';

var html = '' + actions + '';

dialog({
html: html,
dialogClass: 'ui-dialog-drawtoolsSet',
title: 'Tags Options'
});
};

window.plugin.portalTags.optExportThrow = function() {
var csv = '';
var csv_escape = function(x){
if (x===undefined) { return "undefined"; }
return x.replace(/"/g,'').replace(/[\x00-\x1f]/g,'');
};
var __ret = window.plugin.portalTags.computeSets();
var sets = __ret.sets;
var setOpts = __ret.setOpts;

var globalOpts = setOpts['*'];
if (globalOpts === undefined) {
globalOpts = {};
}

for (var setIndex in sets) {
var set = sets[setIndex];
if (set === undefined) {
continue;
}
if (set.length == 1) {
continue;
}

var opts = {};
if (setOpts[setIndex] !== undefined) {
opts = setOpts[setIndex];
}
var zip = opts.zip;
var sbla = opts.sbla;

if (zip === undefined) {
zip = globalOpts.zip;
}

var keys = {};
var addKey = function (k) {
if (keys[k] === undefined) {
keys[k] = 0;
}
++keys[k];
};

if (set.length == 2) {
csv += '"' + csv_escape(set[0].data.n) + '","' + csv_escape(set[1].data.n) + "\"\n";
addKey(set[1].data.n);
continue;
}

var pull = opts.pull;
var csvEscape0;
var csvEscape1;
var ai;
var x;
var y;
var z;
var w;

if (pull === undefined) {
pull = 'single';
}

if (pull === 'single' || set.length == 3) {
// first two are baseline
csvEscape0 = csv_escape(set[0].data.n);
csvEscape1 = csv_escape(set[1].data.n);
var csvEscapePrev;

csv += '"' + csvEscape0 + '","' + csvEscape1 + "\"\n";
addKey(set[1].data.n);

for (ai = 2; ai < set.length; ++ai) {
var csvEscape = csv_escape(set[ai].data.n);
if (!sbla) {
csv += '"' + csvEscape + '","' + csvEscape0 + "\"\n";
addKey(set[0].data.n);
csv += '"' + csvEscape + '","' + csvEscape1 + "\"\n";
addKey(set[1].data.n);
} else {
csv += '"' + csvEscape0 + '","' + csvEscape + "\"\n";
addKey(set[ai].data.n);
csv += '"' + csvEscape1 + '","' + csvEscape + "\"\n";
addKey(set[ai].data.n);
}
if (zip == 1 && csvEscapePrev !== undefined) {
csv += '"' + csvEscape + '","' + csvEscapePrev + "\"\n";
addKey(set[ai - 1].data.n);
}
csvEscapePrev = csvEscape;
}
} else if (pull === 'double') {
csvEscape0 = csv_escape(set[0].data.n);
csvEscape1 = csv_escape(set[1].data.n);
csvEscape2 = csv_escape(set[2].data.n);
csv += '"' + csvEscape1 + '","' + csvEscape0 + "\"\n";
addKey(set[0].data.n);
csv += '"' + csvEscape2 + '","' + csvEscape1 + "\"\n";
addKey(set[1].data.n);
csv += '"' + csvEscape2 + '","' + csvEscape0 + "\"\n";
addKey(set[0].data.n);

for (ai = 3; ai < set.length; ++ai) {
w = csv_escape(set[ai].data.n);
x = csv_escape(set[ai - 1].data.n);
csv += '"' + w + '","' + x + "\"\n";
addKey(set[ai - 1].data.n);
csv += '"' + w + '","' + csvEscape0 + "\"\n";
addKey(set[0].data.n);
if (zip == 1) {
z = csv_escape(set[ai - 2].data.n);
csv += '"' + w + '","' + z + "\"\n";
addKey(set[ai - 2].data.n);
}
}
} else if (pull === 'triple') {
csvEscape0 = csv_escape(set[0].data.n);
csvEscape1 = csv_escape(set[1].data.n);
csvEscape2 = csv_escape(set[2].data.n);
csv += '"' + csvEscape1 + '","' + csvEscape0 + "\"\n";
addKey(set[0].data.n);
csv += '"' + csvEscape2 + '","' + csvEscape1 + "\"\n";
addKey(set[1].data.n);
csv += '"' + csvEscape2 + '","' + csvEscape0 + "\"\n";
addKey(set[0].data.n);

for (ai = 3; ai < set.length; ++ai) {
w = csv_escape(set[ai].data.n);
x = csv_escape(set[ai - 1].data.n);
y = csv_escape(set[ai - 2].data.n);
csv += '"' + w + '","' + x + "\"\n";
addKey(set[ai - 1].data.n);
csv += '"' + w + '","' + y + "\"\n";
addKey(set[ai - 2].data.n);
if (zip == 1) {
z = csv_escape(set[ai - 3].data.n);
csv += '"' + w + '","' + z + "\"\n";
addKey(set[ai - 3].data.n);
}
}
}
}

csv += "\n\nkeys\n";
for(var k in keys) {
csv += '"'+csv_escape(k) + '",' + keys[k] + "\n";
}

csv += "\n\nblockers\n";
var ordered = Object.keys(window.plugin.portalTags.portalTags)
.filter(function(a){
var tags = window.plugin.portalTags.portalTags[a].tags;
return (tags.indexOf('#resx')>=0 || tags.indexOf('#enlx')>=0);
})
.sort(
function(a,b) {
var ad = window.plugin.portalTags.portalTags[a];
var abg = ad.tags.match(/#=([^,]+)/);
if (!abg){
abg = ad.n;
} else {
abg = abg[1] + "/" + ad.n;
}

var bd = window.plugin.portalTags.portalTags[b];
var bbg = bd.tags.match(/#=([^,]+)/);
if (!bbg){
bbg = bd.n;
} else {
bbg = bbg[1] + "/" + bd.n;
}
console.log(abg + " <=> " + bbg);
if (abgbbg) return 1;
return 0;
}
);

for(var pio in ordered) {
var pi = ordered[pio];
var pd = window.plugin.portalTags.portalTags[pi];
var tags = pd.tags;
if (tags !== undefined) {
if (tags.indexOf('#resx')!=-1) {
csv += '"RES","';
} else if (tags.indexOf('#enlx')!=-1) {
csv += '"ENL","';
} else {
continue;
}
var abg = tags.match(/#=([^,]+)/);
if (!abg){
abg = "-";
} else {
abg = abg[1];
}
csv += abg + '","';
var ll = pd.ll.lat + ',' + pd.ll.lng;
var title = pd.n;
if (title===undefined) { title = 'undefined';}
csv += csv_escape(title)+'","https://www.ingress.com/intel?ll='+ll+'&pll='+ll+'","https://www.google.com/maps?ll='+ll+'&q='+ll+'+('+encodeURIComponent(title)+")\"\n";
}
}
var html = ''+csv+'';

dialog({html:html, width: 600, title: 'CSV Export', dialogClass: 'ui-dialog-tag-csv-export-throw-order'});
};

window.plugin.portalTags.updateTags = function(guid, tags, ll, title) {
var p = window.portals[guid];

// lazy update these if we can
if (p!==undefined) {
if (!ll) {
ll = p._latlng;
}
if (p.options && p.options.data) {
if (!title) {
title = p.options.data.title;
}
}
}

if (tags === '') {
delete window.plugin.portalTags.portalTags[guid];
} else {
window.plugin.portalTags.portalTags[guid] = {ll: ll, tags: tags, n: title};
}

window.plugin.portalTags.updateMarker(guid, ll, tags, title);
window.plugin.portalTags.saveStorage();
};

window.plugin.portalTags.submitTags = function () {
var tags = $('#portalTagsTags').val();
console.log("portalTags.submitTags: " + tags);
var guid = window.selectedPortal;

window.plugin.portalTags.updateTags(guid, tags);
};

window.plugin.portalTags.tagClearBlockers = function () {
for (var pi in window.plugin.portalTags.portalTags) {
var ptd = window.plugin.portalTags.portalTags[pi];
if (ptd.tags !== undefined) {
var ot = ptd.tags;
var tags = ot.replace(/#(enlx?|resx?),?/g, '');
if (tags != ot) {
window.plugin.portalTags.updateTags(pi, tags, ptd.ll, ptd.n);
}
}
}
};
window.plugin.portalTags.tagBlockers = function () {
var blockerData = {};

for(var lgi in plugin.crossLinks.linkLayerGuids)
{
if (!window.links[lgi]) continue;
if (!window.links[lgi].options) continue;
if (!window.links[lgi].options.data) continue;

var ld = window.links[lgi].options.data;
var team = ld.team;
var lorigin = ld.oGuid;
var ldest = ld.dGuid;
var llo = {lat:ld.oLatE6/1e6, lng:ld.oLngE6/1e6};
var lld = {lat:ld.dLatE6/1e6, lng:ld.dLngE6/1e6};

if (!blockerData[lorigin]) {
blockerData[lorigin] = {
guid: lorigin,
ll : llo,
team : team,
smash : false,
remaining : 1,
linked : [ldest]
};
} else {
blockerData[lorigin].linked.push(ldest);
++blockerData[lorigin].remaining;
}

if (!blockerData[ldest]) {
blockerData[ldest] = {
guid: ldest,
ll : lld,
team : team,
smash : false,
remaining : 1,
linked : [lorigin]
};
} else {
blockerData[ldest].linked.push(lorigin);
++blockerData[ldest].remaining;
}
}

// prefer #+ portals
for (var bi in blockerData) {

var bd = blockerData[bi];
if (bd.remaining==0) {
continue;
}
var ptd = window.plugin.portalTags.portalTags[bd.guid];

if (!ptd) {
continue;
}
if (!ptd.tags) {
continue;
}
if (ptd.tags.indexOf('#+') < 0) {
continue;
}

bd.smash = true;
bd.remaining = 0;
for (var di in bd.linked) {
var destData = blockerData[bd.linked[di]];
if (destData.remaining>0) {
--destData.remaining;
}
}
}

var ordered = Object.keys(blockerData).sort(
function(a,b){
var cmp = blockerData[b].remaining-blockerData[a].remaining;
if (cmp != 0) {
return cmp;
}
if (ab) {
return 1;
}
return 0;
}
);

for (var bi in ordered) {
var bd = blockerData[ordered[bi]];
console.log(bd.guid + " " + bd.remaining + " remaining");
}

for (var bi in ordered) {
var bd = blockerData[ordered[bi]];
console.log(bd.guid + " " + bd.remaining + " remaining");
if (bd.remaining<=0) {
continue;
}
var ptd = window.plugin.portalTags.portalTags[bd.guid];

if (ptd !== undefined && ptd.tags !== undefined && ptd.tags.indexOf('#-') != -1) {
// don't smash #- portals
continue;
}

bd.smash = true;
bd.remaining = 0;
for (var di in bd.linked) {
var destData = blockerData[bd.linked[di]];
if (destData.remaining>0) {
--destData.remaining;
}
}
}

for (var bi in blockerData) {
var bd = blockerData[bi];
var ptd = window.plugin.portalTags.portalTags[bd.guid];
var pd = window.portals[bd.guid];
var title;
if (pd !== undefined && pd.options !== undefined && pd.options.data !== undefined) {
title = pd.options.data.title;
}

if (ptd === undefined) {
ptd = { ll: bd.ll, tags: '', n : title};
window.plugin.portalTags.portalTags[bd.guid] = ptd;
}
if (ptd.ll === undefined)
{
ptd.ll = bd.ll;
}
if (ptd.tags === undefined)
{
ptd.tags = '';
}
if (ptd.n === undefined) {
ptd.n = title;
}
var tags = ptd.tags;

var orignalTags=tags;

tags = tags.replace(/#(enlx?|resx?|enl|res),?/g,'');

var btag;
if (bd.team == 'E') {
btag = '#enl';
} else {
btag = '#res';
}
if (bd.smash) {
btag += 'x';
}
if (tags.length>0) {
tags = btag + ',' + tags;
} else {
tags = btag;
}

if (orignalTags != tags) {
window.plugin.portalTags.updateTags(bd.guid,tags,ptd.ll,ptd.n);
}
}
};

window.plugin.portalTags.gotoTag = function(guid, pd) {
var position = L.latLng(pd.ll.lat, pd.ll.lng);
zoomToAndShowPortal(guid, position);
};

window.plugin.portalTags.gotoNext = function(guid, dir, rx) {
var ordered = Object.keys(window.plugin.portalTags.portalTags).sort();
var i=0;
var iguid;
var pd;

if (ordered.length==0) {
return;
}

for (i=0;i=ordered.length) {
console.log("gotoNext: bailed")
return;
}
i = (i+dir) % ordered.length;
iguid = ordered[i];
pd = window.plugin.portalTags.portalTags[iguid];
if (!pd || !pd.tags) {
continue;
}
if (pd.tags.match(rx)) {
break;
}
}

window.plugin.portalTags.gotoTag(iguid, pd);
};

window.plugin.portalTags.onPortalDetailLoaded = function (data) {
console.log("portalTags: onPortalDetailLoaded");

var portalData = window.portals[data.guid].options.data;
if (portalData === undefined) {
return;
}
var portalTitle = portalData.title;

var pd = window.plugin.portalTags.portalTags[data.guid];
var tags;

if (pd !== undefined && portalTitle !== undefined) {
tags = pd.tags;
if (pd.n === undefined)
{
pd.n = portalTitle;
if (tags !== undefined)
{
window.plugin.portalTags.updateTags(data.guid, tags, pd.ll, pd.n);
}
}
}
if (tags === undefined) {
tags = '';
}

var html = 'guid:'+data.guid+'X';
html += '#x&lt #x&gt';
$('#portaldetails').append(html);

};

var setup = window.plugin.portalTags.setup;

// PLUGIN END //////////////////////////////////////////////////////////

setup.info = plugin_info; //add the script info data to the function as a property
if (!window.bootPlugins) window.bootPlugins = [];
window.bootPlugins.push(setup);
// if IITC has already booted, immediately run the 'setup' function
if (window.iitcLoaded && typeof setup === 'function') setup();
})({"script":{"version":null,"name":"portalTags","description":""}});
(function wrapper(plugin_info) {
// ensure plugin framework is there, even if iitc is not yet loaded
if (typeof window.plugin !== 'function') {
window.plugin = function () {
};
}

// PLUGIN START ////////////////////////////////////////////////////////

// use own namespace for plugin
window.plugin.portalTags = function () {
};

window.plugin.portalTags.version = '0.4.10';

window.plugin.portalTags.markers = {
"white": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAoCAQAAAA1IDASAAAAAmJLR0QA/4ePzL8AAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQffAxoWCQZ3sgjPAAAFDElEQVRIx32W228UdRTHP3PZO7u9LNCyUiMNlxJUSCBEo2KRWKmlahNNTHixiQnGB15I1AdeiPwFhgdfjCGRSBOKNAaJNMUmINICtpFLL5TSxHYr3bbjsjszO7tz8WFmL715fg8z88vvfM/3fM+ZMyOw3AQARGQkQPJ2LcDCxAbAWX586bOITLy1PbgntMvd1B/khq/08RSrBOKwqgkISASaO06MdSdnslbBcRzHKsxku5Mnxpo7iBMlgISwInCFe7j12JmpmaxmOBWmGTPZM1Otx0gQJ7w6RMm9O7nUuQzSnWw/tTaEgESg9Vh30iVeabZ3tQolCDeRCpUFwNf87sFTnyZE2dVIAMYzC/l4QPCeBXFHSGl05iYeY+FgIYBYYiCybsvpT+qK7q5dSF1IFe8dQJQ71tcfZwN+JNe3DCA3HzhSk4hU1vNh+o/bE7mkWlntRORITesr1BBCLgMIiEhbTh+uLesJcGnh8Z+3zv40X7kHh2vrjxMhgISIUGaQ2BoMB8p0NeO2MpEbGRwZvKs+TGtGOa1wYGuQmqJ+cjGB1kNNIYDxzG9p00pbE7nJvuEbKKhPTp5saXyrVq6SZOlg1faoQ1No5/6RaQzy5IsAkpxoCDoIRIOPZu/8OjednEqPoaJB/wADfFu1Y8/rLW3RIEBDcOPmEa+GolcB5I0R0QI2+b5+oaVt4+b0HKBhkCGDgXpg10fvfdG4yee+V7U+IgQqU/D6IQP4/F89X/dB46Hv3wfy5AE6e16Ldm7KowMhImKhplh8cXlH5yggyEcTtTIRDMDEJForH03YcoEcAKrtU4phiwwsc061ixA+bHPRBALeJABs05Ry3uGstVgoTgmXgQ2Z4b+yEsUjU7nUPWB7+/H2L9kGY0P/mpoHLzGpz017B+0Sg/57e3XHlGQL0BjV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Q1rZfRiJ8YO+3QlkDDwVWe0vN/r6RlX+v84AAEArJWy7vvL86X2t57bgv8b6aajJ47Rir87VWKPw4CT4nYc7T94UdAFJH5hhAeMe9eWm5PVuzSip4JMHllutC4e/ZueTgkYRVUnHDvtqq+WvvZNgHaVsPKsUcwLrPnU82l3odNUe3jT9UgRxF85bnOLHtD2C/6/yHASqIZHIYCPfyYuNKwyqpyJdMGMxKgLg7erLbIV8yYZVULKzP1tvh3fcAtDKkRPpy8iAF4n5KdqLal81bnnNfBXf3ppWM9dl3wrrTT71Efi8dfA8EkFEhiET414X12bpVUsEIg0Zzu77RaA6MMFglFYsbc80++2zwZa9mD9uOYwBezV+b64R1p3nLc4oVY9sN6WYwC8WKgeYtz0kXnkGpty8AWRU83n1rYX22rhqUZ1Xos1cNytO+T7EP06n3KArsUqFxy+sVK8auScWKgV419Af4fpv9oOv5fgDsUGGxcaWhGpRbSgEazUGjOVhKAapB+bW1T+49Cvs9r+eZ/aF/s5Vu3GkYbKiS9yaOHRi3TOkp0KiO/JiO6rftzje9hX/Xg42PAPgSsgOgByACIPf6h4Tus7puqxAI9/Jye7am5xnPj20Z1/OML7dna63g3qUk72uDyu4jK7CHCncMxbJYN/+9ydNjulFU5Mr1m63V3tKHdlS7ltrxvIex37cC2ep4x7156YZ9rdp/f8O+Vq0Hty9lav7AvN91E8ajtThRbT2WwQdffHb1twAQy+CDAdLH+1mQPIr11A06B0AbN6d/CQDJP2NuKurd/bAHgP8Dtc8flm3QFHMAAAAASUVORK5CYII=",
};

window.plugin.portalTags.highlight = function (data) {
var guid = data.portal.options.ent[0];
if (window.plugin.portalTags.portalTags[guid] !== undefined) {
data.portal.setStyle({fillColor: 'yellow'});
}
};

window.plugin.portalTags.highlightRefresh = function (data) {
if (_current_highlighter === 'Tagged Portals') {
if (data.action === 'sync' || data.target === 'portal' || (data.target === 'folder' && data.action === 'remove') || (data.target === 'all' && data.action === 'import') || (data.target === 'all' && data.action === 'reset')) {
window.resetHighlightedPortals();
}
}
};

window.plugin.portalTags.saveStorage = function () {
localStorage.portalTags = JSON.stringify(window.plugin.portalTags.portalTags);
};

window.plugin.portalTags.loadStorage = function () {
window.plugin.portalTags.removeAllMarkers();
var x = localStorage.portalTags;
if (x !== undefined) {
window.plugin.portalTags.portalTags = JSON.parse(x);
}

if (window.plugin.portalTags.portalTags === undefined) {
window.plugin.portalTags.portalTags = {};
}
window.plugin.portalTags.addAllMarkers();
};

window.plugin.portalTags.removeAllMarkers = function () {
var list = window.plugin.portalTags.tagMarkers;
if (list === undefined) {
return;
}
for (var guid in list) {
var marker = list[guid];
window.plugin.portalTags.taggedLayerGroup.removeLayer(marker);
delete window.plugin.portalTags.tagMarkers[guid];
}
};

window.plugin.portalTags.addAllMarkers = function () {
var list = window.plugin.portalTags.portalTags;

for (var guid in list) {
var data = list[guid];
window.plugin.portalTags.updateMarker(guid, data.ll, data.tags, data.n);
}
};

window.plugin.portalTags.sizes = [[[15,40],[30,40]],[[8,20],[16,20]],[[30,80],[60,80]]];
window.plugin.portalTags.getMarker = function(tags,n) {
if (n === undefined) {
return {size: window.plugin.portalTags.sizes[2], img:window.plugin.portalTags.markers.yellow};
}
var markerImg = window.plugin.portalTags.markers.violet;
var size = 0;
if (tags.indexOf("#resx")!=-1) {
markerImg = window.plugin.portalTags.markers.blue;
} else if (tags.indexOf('#enlx')!=-1) {
markerImg = window.plugin.portalTags.markers.green;
} else if (tags.indexOf('#res')!=-1) {
markerImg = window.plugin.portalTags.markers.orange;
size = 1;
} else if (tags.indexOf('#enl')!=-1) {
markerImg = window.plugin.portalTags.markers.red;
size = 1;
} else if (tags.indexOf('#-')!=-1) {
markerImg = window.plugin.portalTags.markers.black;
size = 1;
} else if (tags.indexOf('#+')!=-1) {
markerImg = window.plugin.portalTags.markers.white;
size = 1;
}
return {size: window.plugin.portalTags.sizes[size], img:markerImg};
};

window.plugin.portalTags.updateMarker = function (guid, latlng, tags, title) {
var md;

if (latlng===undefined) {
return;
}
var marker = window.plugin.portalTags.tagMarkers[guid];
if (marker === undefined) {
if (tags === '') {
return;
}

md = window.plugin.portalTags.getMarker(tags, title);
marker = L.marker(
latlng,
{
title: tags,
icon: L.icon(
{
iconUrl: md.img,
iconAnchor: md.size[0], // [15, 40],
iconSize: md.size[1] // [30, 40]
}
)
}
);
window.plugin.portalTags.tagMarkers[guid] = marker;
window.registerMarkerForOMS(marker);
marker.on('spiderfiedclick', function () {
renderPortalDetails(guid);
});
marker.addTo(window.plugin.portalTags.taggedLayerGroup);
}

window.plugin.portalTags.taggedLayerGroup.removeLayer(marker);
if (tags === '') {
delete window.plugin.portalTags.tagMarkers[guid];
return;
}

{
md = window.plugin.portalTags.getMarker(tags, title);
marker.options.icon.options.iconUrl = md.img;
marker.options.icon.options.iconAnchor = md.size[0];
marker.options.icon.options.iconSize = md.size[1];
marker.options.title = tags;
marker.addTo(window.plugin.portalTags.taggedLayerGroup);
}
};

window.plugin.portalTags.setup = function () {
if (window.plugin.drawTools === undefined) {
alert("'portalTags' requires 'draw-tools'");
return;
}
if (window.plugin.crossLinks === undefined) {
alert("'portalTags' requires 'cross links'");
return;
}

window.plugin.portalTags.taggedLayerGroup = new L.LayerGroup();
window.plugin.portalTags.tagMarkers = {};

window.addPortalHighlighter('Tagged Portals', window.plugin.portalTags.highlight);
window.addLayerGroup('Tagged Portals', window.plugin.portalTags.taggedLayerGroup, true);

window.plugin.portalTags.loadStorage();

window.addHook('portalDetailsUpdated', window.plugin.portalTags.onPortalDetailLoaded);
$('head').append('.ui-dialog-tag-csv-export-throw-order { width: 96%; height: 250px; resize: vertical}');
var toolbox = $('#toolbox');
toolbox.append('portalTags version: '+window.plugin.portalTags.version+'TagOptions');
toolbox.append('TagDraw');
toolbox.append('TagBlockers');
};

window.plugin.portalTags.optReset = function () {
window.plugin.portalTags.portalTags = {};
window.plugin.portalTags.removeAllMarkers();
window.plugin.portalTags.saveStorage();
};

window.plugin.portalTags.optCopy = function () {
dialog({
html: 'Select all and press CTRL+C to copy it.' + localStorage.portalTags + '',
dialogClass: 'ui-dialog-drawtoolsSet-copy',
title: 'Portal Tags Copy'
});
};

window.plugin.portalTags.optPaste = function () {
var promptAction = prompt('Press CTRL+V to paste tags.', '');
if (promptAction !== null && promptAction !== '') {
try {
var data = JSON.parse(promptAction); // try to parse JSON first
localStorage.portalTags = promptAction;
window.plugin.portalTags.portalTags = data;
window.plugin.portalTags.removeAllMarkers();
window.plugin.portalTags.addAllMarkers();
} catch (e) {
console.warn('portalTags: failed to import data: ' + e);
window.plugin.portalTags.optAlert('Import failed ');
}
}
};

window.plugin.portalTags.lineColor = [
'#aa44cc',
'#aa4422',
'#44ccaa',
'#aacc44',
'#aa2244',
'#44aa44',
'#44aacc',
'#4422cc'
];

window.plugin.portalTags.precomputedDouble = {
"4": [[0,1,2,0,3,2]],
"4z": [[1,3]],
"5": [[0,1,2,0,3,2],[3,4,0]],
"5z": [[1,3],[2,4]]
/*
"6": [[0,1,2,0,3,2],[3,4,0,5,4]],
"6z": [[1,3,5],[2,4]],
"7": [[0,1,2,0,3,2],[3,4,0,5,4],[5,6,0]],
"7z": [[1,3,5],[2,4,6]],
"8": [[0,1,2,0,3,2],[3,4,0,5,4],[5,6,0,7,6]],
"8z": [[1,3,5,7],[2,4,6]],
"9": [[0,1,2,0,3,2],[3,4,0,5,4],[5,6,0,7,6],[7,8,0]],
"9z": [[1,3,5,7],[2,4,6,8]],
"10": [[0,1,2,0,3,2],[3,4,0,5,4],[5,6,0,7,6],[7,8,0,9,8]],
"10z": [[1,3,5,7,9],[2,4,6,8]],
"11": [[0,1,2,0,3,2],[3,4,0,5,4],[5,6,0,7,6],[7,8,0,9,8],[9,10,0]],
"11z": [[1,3,5,7,9],[2,4,6,8,10]],
"12": [[0,1,2,0,3,2],[3,4,0,5,4],[5,6,0,7,6],[7,8,0,9,8],[9,10,0,11,10]],
"12z": [[1,3,5,7,9,11],[2,4,6,8,10]],
"13": [[0,1,2,0,3,2],[3,4,0,5,4],[5,6,0,7,6],[7,8,0,9,8],[9,10,0,11,10],[11,12,0]],
"13z": [[1,3,5,7,9,11],[2,4,6,8,10,12]],
"14": [[0,1,2,0,3,2],[3,4,0,5,4],[5,6,0,7,6],[7,8,0,9,8],[9,10,0,11,10],[11,12,0,13,12]],
"14z": [[1,3,5,7,9,11,13],[2,4,6,8,10,12]],
"15": [[0,1,2,0,3,2],[3,4,0,5,4],[5,6,0,7,6],[7,8,0,9,8],[9,10,0,11,10],[11,12,0,13,12],[13,14,0]],
"15z": [[1,3,5,7,9,11,13],[2,4,6,8,10,12,14]],
"16": [[0,1,2,0,3,2],[3,4,0,5,4],[5,6,0,7,6],[7,8,0,9,8],[9,10,0,11,10],[11,12,0,13,12],[13,14,0,15,14]],
"16z": [[1,3,5,7,9,11,13,15],[2,4,6,8,10,12,14]],
"17": [[0,1,2,0,3,2],[3,4,0,5,4],[5,6,0,7,6],[7,8,0,9,8],[9,10,0,11,10],[11,12,0,13,12],[13,14,0,15,14],[15,16,0]],
"17z": [[1,3,5,7,9,11,13,15],[2,4,6,8,10,12,14,16]],
"18": [[0,1,2,0,3,2],[3,4,0,5,4],[5,6,0,7,6],[7,8,0,9,8],[9,10,0,11,10],[11,12,0,13,12],[13,14,0,15,14],[15,16,0,17,16]],
"18z": [[1,3,5,7,9,11,13,15,17],[2,4,6,8,10,12,14,16]],
"19": [[0,1,2,0,3,2],[3,4,0,5,4],[5,6,0,7,6],[7,8,0,9,8],[9,10,0,11,10],[11,12,0,13,12],[13,14,0,15,14],[15,16,0,17,16],[17,18,0]],
"19z": [[1,3,5,7,9,11,13,15,17],[2,4,6,8,10,12,14,16,18]],
"20": [[0,1,2,0,3,2],[3,4,0,5,4],[5,6,0,7,6],[7,8,0,9,8],[9,10,0,11,10],[11,12,0,13,12],[13,14,0,15,14],[15,16,0,17,16],[17,18,0,19,18]],
"20z": [[1,3,5,7,9,11,13,15,17,19],[2,4,6,8,10,12,14,16,18]],
"21": [[0,1,2,0,3,2],[3,4,0,5,4],[5,6,0,7,6],[7,8,0,9,8],[9,10,0,11,10],[11,12,0,13,12],[13,14,0,15,14],[15,16,0,17,16],[17,18,0,19,18],[19,20,0]],
"21z": [[1,3,5,7,9,11,13,15,17,19],[2,4,6,8,10,12,14,16,18,20]],
*/
};

window.plugin.portalTags.lookupDouble = function(n) {
var key = n+'';
if (window.plugin.portalTags.precomputedDouble[key] !== undefined)
{
return window.plugin.portalTags.precomputedDouble[key];
}
var x = JSON.parse(JSON.stringify(window.plugin.portalTags.lookupDouble(n-1))); // deep copy
var xl = x[x.length-1];
if (xl.length==3) {
xl.push(n-1,n-2);
} else {
x.push([n-2,n-1,0]);
}
window.plugin.portalTags.precomputedDouble[key]=x;
return x;
};

window.plugin.portalTags.lookupDoubleZip = function(n) {
var key = n+'z';
if (window.plugin.portalTags.precomputedDouble[key] !== undefined)
{
return window.plugin.portalTags.precomputedDouble[key];
}
var x = JSON.parse(JSON.stringify(window.plugin.portalTags.lookupDoubleZip(n-1))); // deep copy
if (n%2===0) {
x[0].push(n-1);
} else {
x[1].push(n-1);
}
window.plugin.portalTags.precomputedDouble[key]=x;
return x;
};

window.plugin.portalTags.precomputedTriple = {
"4": [[0,1,2,0],[2,3,1]],
"4z": [[0,3]]
/*
"5": [[0,1,2,0],[2,3,1],[3,4,2]],
"5z": [[0,3],[1,4]],
"6": [[0,1,2,0],[2,3,1],[3,4,2],[4,5,3]],
"6z": [[0,3],[1,4],[2,5]],
"7": [[0,1,2,0],[2,3,1],[3,4,2],[4,5,3],[5,6,4]],
"7z": [[0,3],[1,4],[2,5],[3,6]],
"8": [[0,1,2,0],[2,3,1],[3,4,2],[4,5,3],[5,6,4],[6,7,5]],
"8z": [[0,3],[1,4],[2,5],[3,6],[4,7]],
"9": [[0,1,2,0],[2,3,1],[3,4,2],[4,5,3],[5,6,4],[6,7,5],[7,8,6]],
"9z": [[0,3],[1,4],[2,5],[3,6],[4,7],[5,8]],
*/
};

window.plugin.portalTags.lookupTriple = function(n) {
var key = n+'';
if (window.plugin.portalTags.precomputedTriple[key] !== undefined)
{
return window.plugin.portalTags.precomputedTriple[key];
}
var x = JSON.parse(JSON.stringify(window.plugin.portalTags.lookupTriple(n-1))); // deep copy
var xl = x[x.length-1];
var nl = [xl[0]+1,xl[1]+1,xl[2]+1];
x.push(nl);
window.plugin.portalTags.precomputedTriple[key]=x;
return x;
};

window.plugin.portalTags.lookupTripleZip = function(n) {
var key = n+'z';
if (window.plugin.portalTags.precomputedTriple[key] !== undefined)
{
return window.plugin.portalTags.precomputedTriple[key];
}
var x = JSON.parse(JSON.stringify(window.plugin.portalTags.lookupTripleZip(n-1))); // deep copy
var xl = x[x.length-1];
var nl = [xl[0]+1,xl[1]+1];
x.push(nl);
window.plugin.portalTags.precomputedTriple[key]=x;
return x;
};

window.plugin.portalTags.drawLines = function(lines, set, lineOptions) {
if (lines !== undefined) {
for (var li in lines) {
var line = lines[li];
var ll = [];

for (var lli in line) {
ll[lli] = set[line[lli]].data.ll;
}

map.fire('draw:created', {
layer: L.geodesicPolyline(ll, lineOptions),
layerType: 'polyline'
});
}
}
};

window.plugin.portalTags.computeSets = function () {
var sets = {};
var setOpts = {};
// for each tagged portal
// add to set based on first character

for (var tp in window.plugin.portalTags.portalTags) {
var data = window.plugin.portalTags.portalTags[tp];
var tags = data.tags;

var asArr = tags.split(/[,\s]+/);
console.log(asArr);
console.log(tp + ": " + JSON.stringify(asArr));
for (var tagIndex in asArr) {
var tag = asArr[tagIndex];

var setChar = tag.charAt(0);
if (setChar === '#') {
continue;
}
if (setChar === '@') {
var rx = /@(.)\[([^;]*)(?:;([^;]*))*\]/g;

var grps = rx.exec(tag);
if (!grps) {
var message = "Invalid tag: " + tag + " on " + data.guid + ' ' + data.n;
console.log(message);
window.alert(message);
continue;
}
if (grps.length < 2) {
continue;
}
setChar = grps[1];
if (setOpts[setChar] === undefined) {
setOpts[setChar] = {};
}

for (var grpIndex = 2; grpIndex < grps.length; ++grpIndex) {
var opt = grps[grpIndex];
if (opt === undefined) {
continue;
}
var sOpt = opt.split(':');
if (sOpt.length == 1) {
setOpts[setChar][opt] = 1;
}
else {
setOpts[setChar][sOpt[0]] = sOpt[1];
}
}

console.log(setChar + ": " + JSON.stringify(setOpts[setChar]));
continue;
}
console.log(tag + ": " + setChar);
if (sets[setChar] === undefined) {
sets[setChar] = [];
}
sets[setChar].push({data:data,t:tag});
}
}
for(var s in sets) {
sets[s] = sets[s].sort(function(a,b) { if (a.tb.t) return 1; return 0;} );
}
console.log(sets);
return {sets: sets, setOpts: setOpts};
};

window.plugin.portalTags.tagDraw = function () {

// window.plugin.portalTags.tagClearBlockers();

var __ret = window.plugin.portalTags.computeSets();
var sets = __ret.sets;
var setOpts = __ret.setOpts;

try {
window.plugin.drawTools.optReset();
} catch (e) {
console.log(e);
}

var seti = 0;

var globalOpts = setOpts['*'];
if (globalOpts === undefined) {
globalOpts = {};
}

for (var setIndex in sets) {
var set = sets[setIndex];
if (set===undefined)
{
continue;
}
if (set.length==1)
{
continue;
}

var opts = {};
if (setOpts[setIndex] !== undefined) {
opts = setOpts[setIndex];
}
var zip = opts.zip;

if (zip === undefined) {
zip = globalOpts.zip;
}
var lineColor = opts.color;
if (lineColor === undefined) {
lineColor = globalOpts.color;
}
if (lineColor === undefined) {
var lci = seti++ % window.plugin.portalTags.lineColor.length;
lineColor = window.plugin.portalTags.lineColor[lci];
}
var lineOptions = {stroke: true, color: lineColor, weight: 4, opacity: 0.5, fill: false, clickable: true};

if (set.length==2)
{
map.fire('draw:created', {
layer: L.geodesicPolyline([set[0].data.ll,set[1].data.ll], lineOptions),
layerType:'polyline'
});
continue;
}

var pull = opts.pull;
if (pull === undefined)
{
pull = 'single';
}

if (pull === 'single') {
var latlngs = [];
var ziplatlngs = [];
latlngs.push(set[0].data.ll);
latlngs.push(set[1].data.ll);

var ai = 0;
for (var i = 2; i < set.length; ++i) {
latlngs.push(set[i].data.ll);
ziplatlngs.push(set[i].data.ll);
latlngs.push(latlngs[ai]);
ai ^= 1;
}

var layerType = 'polyline';
var layer = L.geodesicPolyline(latlngs, lineOptions);
map.fire('draw:created', {
layer: layer,
layerType: layerType
});

if (zip === 1 && ziplatlngs.length > 0) {
var ziplayer = L.geodesicPolyline(ziplatlngs, lineOptions);
map.fire('draw:created', {
layer: ziplayer,
layerType: layerType
});
}
} else if (pull === 'double') {
// first is pivot, then throws in alternating order
// use a+ for the pivot and then evens (0,2,4,6,...) for one direction and odds (1,3,5,7,...) for the other.

var lines = window.plugin.portalTags.lookupDouble(set.length);
window.plugin.portalTags.drawLines(lines, set, lineOptions);
if (zip)
{
lines = window.plugin.portalTags.lookupDoubleZip(set.length);
window.plugin.portalTags.drawLines(lines, set, lineOptions);
}
} else if (pull === 'triple') {
// use a0, a1, a2 and then by 3's in each director (0,3,6,9,...), (1,4,7,10,...), (2,5,8,11,...)
var lines = window.plugin.portalTags.lookupTriple(set.length);
window.plugin.portalTags.drawLines(lines, set, lineOptions);
if (zip)
{
lines = window.plugin.portalTags.lookupTripleZip(set.length);
window.plugin.portalTags.drawLines(lines, set, lineOptions);
}
}
}
};

window.plugin.portalTags.optAlert = function (message) {
$('.ui-dialog-drawtoolsSet .ui-dialog-buttonset').prepend('' + message + '');
$('.drawrtools-alert').delay(2500).fadeOut();
};

window.plugin.portalTags.showOptionsDialog = function () {
console.log("Portal Tags: showOptionsDialog");
var actions = '';
actions += 'Reset All Tags';
actions += 'Reset Only Blocker Tags';
actions += 'Copy Tags';
actions += 'Paste Tags';
actions += 'CSV Export';

var html = '' + actions + '';

dialog({
html: html,
dialogClass: 'ui-dialog-drawtoolsSet',
title: 'Tags Options'
});
};

window.plugin.portalTags.optExportThrow = function() {
var csv = '';
var csv_escape = function(x){
if (x===undefined) { return "undefined"; }
return x.replace(/"/g,'').replace(/[\x00-\x1f]/g,'');
};
var __ret = window.plugin.portalTags.computeSets();
var sets = __ret.sets;
var setOpts = __ret.setOpts;

var globalOpts = setOpts['*'];
if (globalOpts === undefined) {
globalOpts = {};
}

for (var setIndex in sets) {
var set = sets[setIndex];
if (set === undefined) {
continue;
}
if (set.length == 1) {
continue;
}

var opts = {};
if (setOpts[setIndex] !== undefined) {
opts = setOpts[setIndex];
}
var zip = opts.zip;
var sbla = opts.sbla;

if (zip === undefined) {
zip = globalOpts.zip;
}

var keys = {};
var addKey = function (k) {
if (keys[k] === undefined) {
keys[k] = 0;
}
++keys[k];
};

if (set.length == 2) {
csv += '"' + csv_escape(set[0].data.n) + '","' + csv_escape(set[1].data.n) + "\"\n";
addKey(set[1].data.n);
continue;
}

var pull = opts.pull;
var csvEscape0;
var csvEscape1;
var ai;
var x;
var y;
var z;
var w;

if (pull === undefined) {
pull = 'single';
}

if (pull === 'single' || set.length == 3) {
// first two are baseline
csvEscape0 = csv_escape(set[0].data.n);
csvEscape1 = csv_escape(set[1].data.n);
var csvEscapePrev;

csv += '"' + csvEscape0 + '","' + csvEscape1 + "\"\n";
addKey(set[1].data.n);

for (ai = 2; ai < set.length; ++ai) {
var csvEscape = csv_escape(set[ai].data.n);
if (!sbla) {
csv += '"' + csvEscape + '","' + csvEscape0 + "\"\n";
addKey(set[0].data.n);
csv += '"' + csvEscape + '","' + csvEscape1 + "\"\n";
addKey(set[1].data.n);
} else {
csv += '"' + csvEscape0 + '","' + csvEscape + "\"\n";
addKey(set[ai].data.n);
csv += '"' + csvEscape1 + '","' + csvEscape + "\"\n";
addKey(set[ai].data.n);
}
if (zip == 1 && csvEscapePrev !== undefined) {
csv += '"' + csvEscape + '","' + csvEscapePrev + "\"\n";
addKey(set[ai - 1].data.n);
}
csvEscapePrev = csvEscape;
}
} else if (pull === 'double') {
csvEscape0 = csv_escape(set[0].data.n);
csvEscape1 = csv_escape(set[1].data.n);
csvEscape2 = csv_escape(set[2].data.n);
csv += '"' + csvEscape1 + '","' + csvEscape0 + "\"\n";
addKey(set[0].data.n);
csv += '"' + csvEscape2 + '","' + csvEscape1 + "\"\n";
addKey(set[1].data.n);
csv += '"' + csvEscape2 + '","' + csvEscape0 + "\"\n";
addKey(set[0].data.n);

for (ai = 3; ai < set.length; ++ai) {
w = csv_escape(set[ai].data.n);
x = csv_escape(set[ai - 1].data.n);
csv += '"' + w + '","' + x + "\"\n";
addKey(set[ai - 1].data.n);
csv += '"' + w + '","' + csvEscape0 + "\"\n";
addKey(set[0].data.n);
if (zip == 1) {
z = csv_escape(set[ai - 2].data.n);
csv += '"' + w + '","' + z + "\"\n";
addKey(set[ai - 2].data.n);
}
}
} else if (pull === 'triple') {
csvEscape0 = csv_escape(set[0].data.n);
csvEscape1 = csv_escape(set[1].data.n);
csvEscape2 = csv_escape(set[2].data.n);
csv += '"' + csvEscape1 + '","' + csvEscape0 + "\"\n";
addKey(set[0].data.n);
csv += '"' + csvEscape2 + '","' + csvEscape1 + "\"\n";
addKey(set[1].data.n);
csv += '"' + csvEscape2 + '","' + csvEscape0 + "\"\n";
addKey(set[0].data.n);

for (ai = 3; ai < set.length; ++ai) {
w = csv_escape(set[ai].data.n);
x = csv_escape(set[ai - 1].data.n);
y = csv_escape(set[ai - 2].data.n);
csv += '"' + w + '","' + x + "\"\n";
addKey(set[ai - 1].data.n);
csv += '"' + w + '","' + y + "\"\n";
addKey(set[ai - 2].data.n);
if (zip == 1) {
z = csv_escape(set[ai - 3].data.n);
csv += '"' + w + '","' + z + "\"\n";
addKey(set[ai - 3].data.n);
}
}
}
}

csv += "\n\nkeys\n";
for(var k in keys) {
csv += '"'+csv_escape(k) + '",' + keys[k] + "\n";
}

csv += "\n\nblockers\n";
var ordered = Object.keys(window.plugin.portalTags.portalTags)
.filter(function(a){
var tags = window.plugin.portalTags.portalTags[a].tags;
return (tags.indexOf('#resx')>=0 || tags.indexOf('#enlx')>=0);
})
.sort(
function(a,b) {
var ad = window.plugin.portalTags.portalTags[a];
var abg = ad.tags.match(/#=([^,]+)/);
if (!abg){
abg = ad.n;
} else {
abg = abg[1] + "/" + ad.n;
}

var bd = window.plugin.portalTags.portalTags[b];
var bbg = bd.tags.match(/#=([^,]+)/);
if (!bbg){
bbg = bd.n;
} else {
bbg = bbg[1] + "/" + bd.n;
}
console.log(abg + " <=> " + bbg);
if (abgbbg) return 1;
return 0;
}
);

for(var pio in ordered) {
var pi = ordered[pio];
var pd = window.plugin.portalTags.portalTags[pi];
var tags = pd.tags;
if (tags !== undefined) {
if (tags.indexOf('#resx')!=-1) {
csv += '"RES","';
} else if (tags.indexOf('#enlx')!=-1) {
csv += '"ENL","';
} else {
continue;
}
var abg = tags.match(/#=([^,]+)/);
if (!abg){
abg = "-";
} else {
abg = abg[1];
}
csv += abg + '","';
var ll = pd.ll.lat + ',' + pd.ll.lng;
var title = pd.n;
if (title===undefined) { title = 'undefined';}
csv += csv_escape(title)+'","https://www.ingress.com/intel?ll='+ll+'&pll='+ll+'","https://www.google.com/maps?ll='+ll+'&q='+ll+'+('+encodeURIComponent(title)+")\"\n";
}
}
var html = ''+csv+'';

dialog({html:html, width: 600, title: 'CSV Export', dialogClass: 'ui-dialog-tag-csv-export-throw-order'});
};

window.plugin.portalTags.updateTags = function(guid, tags, ll, title) {
var p = window.portals[guid];

// lazy update these if we can
if (p!==undefined) {
if (!ll) {
ll = p._latlng;
}
if (p.options && p.options.data) {
if (!title) {
title = p.options.data.title;
}
}
}

if (tags === '') {
delete window.plugin.portalTags.portalTags[guid];
} else {
window.plugin.portalTags.portalTags[guid] = {ll: ll, tags: tags, n: title};
}

window.plugin.portalTags.updateMarker(guid, ll, tags, title);
window.plugin.portalTags.saveStorage();
};

window.plugin.portalTags.submitTags = function () {
var tags = $('#portalTagsTags').val();
console.log("portalTags.submitTags: " + tags);
var guid = window.selectedPortal;

window.plugin.portalTags.updateTags(guid, tags);
};

window.plugin.portalTags.tagClearBlockers = function () {
for (var pi in window.plugin.portalTags.portalTags) {
var ptd = window.plugin.portalTags.portalTags[pi];
if (ptd.tags !== undefined) {
var ot = ptd.tags;
var tags = ot.replace(/#(enlx?|resx?),?/g, '');
if (tags != ot) {
window.plugin.portalTags.updateTags(pi, tags, ptd.ll, ptd.n);
}
}
}
};
window.plugin.portalTags.tagBlockers = function () {
var blockerData = {};

for(var lgi in plugin.crossLinks.linkLayerGuids)
{
if (!window.links[lgi]) continue;
if (!window.links[lgi].options) continue;
if (!window.links[lgi].options.data) continue;

var ld = window.links[lgi].options.data;
var team = ld.team;
var lorigin = ld.oGuid;
var ldest = ld.dGuid;
var llo = {lat:ld.oLatE6/1e6, lng:ld.oLngE6/1e6};
var lld = {lat:ld.dLatE6/1e6, lng:ld.dLngE6/1e6};

if (!blockerData[lorigin]) {
blockerData[lorigin] = {
guid: lorigin,
ll : llo,
team : team,
smash : false,
remaining : 1,
linked : [ldest]
};
} else {
blockerData[lorigin].linked.push(ldest);
++blockerData[lorigin].remaining;
}

if (!blockerData[ldest]) {
blockerData[ldest] = {
guid: ldest,
ll : lld,
team : team,
smash : false,
remaining : 1,
linked : [lorigin]
};
} else {
blockerData[ldest].linked.push(lorigin);
++blockerData[ldest].remaining;
}
}

// prefer #+ portals
for (var bi in blockerData) {

var bd = blockerData[bi];
if (bd.remaining==0) {
continue;
}
var ptd = window.plugin.portalTags.portalTags[bd.guid];

if (!ptd) {
continue;
}
if (!ptd.tags) {
continue;
}
if (ptd.tags.indexOf('#+') < 0) {
continue;
}

bd.smash = true;
bd.remaining = 0;
for (var di in bd.linked) {
var destData = blockerData[bd.linked[di]];
if (destData.remaining>0) {
--destData.remaining;
}
}
}

var ordered = Object.keys(blockerData).sort(
function(a,b){
var cmp = blockerData[b].remaining-blockerData[a].remaining;
if (cmp != 0) {
return cmp;
}
if (ab) {
return 1;
}
return 0;
}
);

for (var bi in ordered) {
var bd = blockerData[ordered[bi]];
console.log(bd.guid + " " + bd.remaining + " remaining");
}

for (var bi in ordered) {
var bd = blockerData[ordered[bi]];
console.log(bd.guid + " " + bd.remaining + " remaining");
if (bd.remaining<=0) {
continue;
}
var ptd = window.plugin.portalTags.portalTags[bd.guid];

if (ptd !== undefined && ptd.tags !== undefined && ptd.tags.indexOf('#-') != -1) {
// don't smash #- portals
continue;
}

bd.smash = true;
bd.remaining = 0;
for (var di in bd.linked) {
var destData = blockerData[bd.linked[di]];
if (destData.remaining>0) {
--destData.remaining;
}
}
}

for (var bi in blockerData) {
var bd = blockerData[bi];
var ptd = window.plugin.portalTags.portalTags[bd.guid];
var pd = window.portals[bd.guid];
var title;
if (pd !== undefined && pd.options !== undefined && pd.options.data !== undefined) {
title = pd.options.data.title;
}

if (ptd === undefined) {
ptd = { ll: bd.ll, tags: '', n : title};
window.plugin.portalTags.portalTags[bd.guid] = ptd;
}
if (ptd.ll === undefined)
{
ptd.ll = bd.ll;
}
if (ptd.tags === undefined)
{
ptd.tags = '';
}
if (ptd.n === undefined) {
ptd.n = title;
}
var tags = ptd.tags;

var orignalTags=tags;

tags = tags.replace(/#(enlx?|resx?|enl|res),?/g,'');

var btag;
if (bd.team == 'E') {
btag = '#enl';
} else {
btag = '#res';
}
if (bd.smash) {
btag += 'x';
}
if (tags.length>0) {
tags = btag + ',' + tags;
} else {
tags = btag;
}

if (orignalTags != tags) {
window.plugin.portalTags.updateTags(bd.guid,tags,ptd.ll,ptd.n);
}
}
};

window.plugin.portalTags.gotoTag = function(guid, pd) {
var position = L.latLng(pd.ll.lat, pd.ll.lng);
zoomToAndShowPortal(guid, position);
};

window.plugin.portalTags.gotoNext = function(guid, dir, rx) {
var ordered = Object.keys(window.plugin.portalTags.portalTags).sort();
var i=0;
var iguid;
var pd;

if (ordered.length==0) {
return;
}

for (i=0;i=ordered.length) {
console.log("gotoNext: bailed")
return;
}
i = (i+dir) % ordered.length;
iguid = ordered[i];
pd = window.plugin.portalTags.portalTags[iguid];
if (!pd || !pd.tags) {
continue;
}
if (pd.tags.match(rx)) {
break;
}
}

window.plugin.portalTags.gotoTag(iguid, pd);
};

window.plugin.portalTags.onPortalDetailLoaded = function (data) {
console.log("portalTags: onPortalDetailLoaded");

var portalData = window.portals[data.guid].options.data;
if (portalData === undefined) {
return;
}
var portalTitle = portalData.title;

var pd = window.plugin.portalTags.portalTags[data.guid];
var tags;

if (pd !== undefined && portalTitle !== undefined) {
tags = pd.tags;
if (pd.n === undefined)
{
pd.n = portalTitle;
if (tags !== undefined)
{
window.plugin.portalTags.updateTags(data.guid, tags, pd.ll, pd.n);
}
}
}
if (tags === undefined) {
tags = '';
}

var html = 'guid:'+data.guid+'X';
html += '#x&lt #x&gt';
$('#portaldetails').append(html);

};

var setup = window.plugin.portalTags.setup;

// PLUGIN END //////////////////////////////////////////////////////////

setup.info = plugin_info; //add the script info data to the function as a property
if (!window.bootPlugins) window.bootPlugins = [];
window.bootPlugins.push(setup);
// if IITC has already booted, immediately run the 'setup' function
if (window.iitcLoaded && typeof setup === 'function') setup();
})({"script":{"version":null,"name":"portalTags","description":""}});