Skip to content

Instantly share code, notes, and snippets.

@johnd0e
Last active July 4, 2020 09:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnd0e/df3315e0578b1ac0df6fd87241089030 to your computer and use it in GitHub Desktop.
Save johnd0e/df3315e0578b1ac0df6fd87241089030 to your computer and use it in GitHub Desktop.
IITC plugin: Draw multi links and fields (forked from https://github.com/kewwwa/iitc-plugin-multidraw)
// ==UserScript==
// @id iitc-plugin-multidraw@jd
// @name IITC plugin: Multi draw
// @description Draw multiple links/fields
// *: Draw line between this and prev portal
// O: Draw field from selected portal to base portals
// (available after drawing a line)
// Close panel to draw new set
// @category Layer
// @version 0.1.7
// @author jd, kewwwa
// @namespace https://github.com/johnd0e/
// @updateURL https://gist.github.com/johnd0e/df3315e0578b1ac0df6fd87241089030/raw/iitc-multi-draw.user.js
// @downloadURL https://gist.github.com/johnd0e/df3315e0578b1ac0df6fd87241089030/raw/iitc-multi-draw.user.js
// @include https://intel.ingress.com/*
// @grant none
// ==/UserScript==
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
var multidraw = function () {};
window.plugin.multidraw = multidraw;
var multidrawControl = L.Control.extend({
options: {position:'topleft'},
initialize: function () {
this.lastPortal = []
},
onAdd: function () {
var container = L.DomUtil.create('div', 'leaflet-control-multidraw leaflet-draw');
L.DomEvent.disableClickPropagation(container);
var section = L.DomUtil.create('div', 'leaflet-draw-section', container);
this._toolbar = L.DomUtil.create('div', 'leaflet-bar leaflet-draw-toolbar-top', section);
var button = L.DomUtil.create('a', 'leaflet-multidraw-edit', this._toolbar);
button.title = 'Draw multi links';
L.DomEvent.on(button, 'click', this.toggleMenu, this);
this._actions = L.DomUtil.create('ul', 'leaflet-draw-actions leaflet-draw-actions-top leaflet-draw-actions-bottom', section);
this._actionField = L.DomUtil.create('li');
var setFieldLink = L.DomUtil.create('a', null, this._actionField);
setFieldLink.innerHTML = 'O';
setFieldLink.title = 'Set Field';
L.DomEvent.on(setFieldLink, 'click', this.setField, this);
this._actionLine = L.DomUtil.create('li');
var setLineLink = L.DomUtil.create('a', null, this._actionLine);
setLineLink.innerHTML = '*';
setLineLink.title = 'Set Line';
L.DomEvent.on(setLineLink, 'click', this.setLine, this);
return container;
},
toggleMenu: function () {
if (this._actions.classList.contains('active')) {
this._actions.classList.remove('active');
this._toolbar.classList.remove('leaflet-draw-toolbar-notop', 'leaflet-draw-toolbar-nobottom');
delete this.portalA;
delete this.portalB;
this.lastPortal = [];
this._actionField.remove();
} else {
this._actions.appendChild(this._actionLine);
this._actions.classList.add('active');
this._toolbar.classList.add('leaflet-draw-toolbar-notop', 'leaflet-draw-toolbar-nobottom');
}
},
setField: function () {
if (!selectedPortal || !portals[selectedPortal]) { return };
if (!this.portalA) {
var len = this.lastPortal.length
if (len<2) return;
this.portalA = this.lastPortal[len-2];
this.portalB = this.lastPortal[len-1];
}
if (selectedPortal === this.portalA || selectedPortal === this.portalB) { return; }
this._draw([this.portalA, selectedPortal, this.portalB]);
this._actionLine.remove();
this.lastPortal.push(selectedPortal);
},
setLine: function () {
if (!selectedPortal || !portals[selectedPortal]) { return };
var last = this.lastPortal[this.lastPortal.length-1]
if (last) {
if (last === selectedPortal) { return };
this._draw([last, selectedPortal]);
this._actions.appendChild(this._actionField);
}
this.lastPortal.push(selectedPortal);
},
_draw: function (guids) {
var layer, layerType;
var latlngs = guids.map(function (guid) {
return window.portals[guid].getLatLng();
});
if (latlngs.length === 2) {
layer = L.geodesicPolyline(latlngs, window.plugin.drawTools.lineOptions);
layerType = 'polyline';
} else {
layer = L.geodesicPolygon(latlngs, window.plugin.drawTools.polygonOptions);
layerType = 'polygon';
}
this._map.fire('draw:created', {
layer: layer,
layerType: layerType
});
if (!this._map.hasLayer(window.plugin.drawTools.drawnItems)) {
this._map.addLayer(window.plugin.drawTools.drawnItems);
}
}
});
function setup() {
$('<style>').prop('type', 'text/css')
.html('.leaflet-draw-actions.active{display:block; top:-1px;} .leaflet-draw-actions a {width:inherit;} ' +
'.leaflet-draw-actions a.active {background-color:#008902;} ' +
'.leaflet-touch .leaflet-draw-actions-top.leaflet-draw-actions-bottom a {height:30px; line-height:30px;} ' +
'.leaflet-touch .leaflet-draw-actions {top:1px;} ' +
'a.leaflet-multidraw-edit {background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAIAAAC0Ujn1AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjEuNv1OCegAAAIlSURBVEhLvVWvswFRGN1kBEEQmBEM/gAzBNEYwRhRFN4YURQEM6IgCKIgmCEIgiAKgmiMIAqCIAiCIHjnvfvN3d37Y9/15nknmD13d889e3zfd63n2/Dv0o/HIxqN3u934hI8bnGopTebTTabJSLhdDrFYrHL5UJcA7V0t9tttVpEJBQKhXa7TUQPtXSxWFwul0Tc6Pf7mUwGiRHXQyGN14LB4O12I+7Afr8PhUKHw4G4JxTSuqCxZSqVGgwGxH+CQloXdLPZLJfLRAygkFYGvVqtwuHw+XwmbgBRWhk0KKptNpsRN4MorQz64xtEjCFKy0HDLCwrC8YborQQNBoPEa/Xa+JueLe7S1oOGjvp2hJViF2v1ytxCS5pIWi8jEKWG+94POZyOdzabre0pIJL2hk0Wg5fIDce9sN6p9ORtxTgkuZB4zUMCowLts5gaJbDlnYGjcGG8cbWGczNctjSPGhcYAahNtj6q2Y5bGkWtNB4vzDLYUuzoOv1erVaBTU0i4+bz+eYXHg4EAg4C5ekWdCTyQSWUaoeZvEyOqjX61UqFZyfeAye8ORisRBqnKSRbzqdRsTT6VQ2ixNgNBo1Gg2s+/1+/OJ6PB57nwkkjaATiUQ+n2dmMTzhAnUCR1iBO3hELcKvyVnOQNLxeNzn80UikVKplEwmkRq8419Fji/NaCe+pHHsW5YFd7VabTgcvlpkOpDr3W7HLv4QJP0OvE36+fwEa9FfUxJlSk0AAAAASUVORK5CYII="); background-size: 70%;}')
.appendTo('head');
multidraw.control = (new multidrawControl).addTo(window.map);
}
// 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();
} // wrapper end
// inject code into site context
var script = document.createElement('script');
var info = {};
if (typeof GM_info !== 'undefined' && GM_info && GM_info.script) info.script = { version: GM_info.script.version, name: GM_info.script.name, description: GM_info.script.description };
script.appendChild(document.createTextNode('('+ wrapper +')('+JSON.stringify(info)+');'));
(document.body || document.head || document.documentElement).appendChild(script);
@ryantheleach
Copy link

Does this have any major differences then the original?

@johnd0e
Copy link
Author

johnd0e commented Jul 2, 2020

This is early fork of https://kewwwa.github.io/
At the time of forking that was completely non-functional.

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