-
Notifications
You must be signed in to change notification settings - Fork 5
/
draw-tools-plus.user.js
161 lines (132 loc) · 6.42 KB
/
draw-tools-plus.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// ==UserScript==
// @author Zaso
// @name IITC plugin: Draw tools plus
// @category Layer
// @version 0.1.10.20210103.185428
// @description Edit and improve Draw tools.
// @id draw-tools-plus
// @namespace https://github.com/IITC-CE/ingress-intel-total-conversion
// @downloadURL https://github.com/MysticJay/ZasoItems.CE/raw/master/draw-tools-plus.user.js
// @match 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 AUTHORS: writing a plugin outside of the IITC build environment? if so, delete these lines!!
//(leaving them in place might break the 'About IITC' page or break update checks)
plugin_info.buildName = 'ZasoItems';
plugin_info.dateTimeVersion = '2021-01-03-185428';
plugin_info.pluginId = 'draw-tools-plus';
//END PLUGIN AUTHORS NOTE
// PLUGIN START ////////////////////////////////////////////////////////
// history
// 0.1.10 stripped all code for EDF, merge and MPE
// 0.1.9 Headers updated. Ready for IITC-CE
// 0.1.8 Original script
/*
// "color" is optional
window.plugin.drawToolsPlus.drawPolyline(arrCoordArr, color);
window.plugin.drawToolsPlus.drawPolygon(arrCoordArr, color);
window.plugin.drawToolsPlus.drawCircle(coord, radius, color);
window.plugin.drawToolsPlus.drawMarker(coord, color);
*/
// use own namespace for plugin
window.plugin.drawToolsPlus = {};
// ---------------------------------------------------------------------------------
// MODDING DRAW TOOLS
// ---------------------------------------------------------------------------------
window.plugin.drawToolsPlus.boot = function(){
window.plugin.drawToolsPlus.storageKEY = 'plugin-draw-tools-layer';
// Add FA icon to sidebar
window.addHook('iitcLoaded', function(){
$('#toolbox a:contains(\'DrawTools Opt\')').addClass('list-group-item').prepend('<i class="fa fa-pencil"></i>');
});
};
// FUNCTIONS TO DRAW
window.plugin.drawToolsPlus.fireDraw = function(layer, layerType){
map.fire('draw:created', {
layer: layer,
layerType: layerType
});
}
window.plugin.drawToolsPlus.drawPolyline = function(arrCoordArr, color){
if(color !== undefined){
var oldColor = window.plugin.drawTools.currentColor;
window.plugin.drawTools.setDrawColor(color);
}
var drawOpt = window.plugin.drawTools.lineOptions;
var layer = L.geodesicPolyline(arrCoordArr, drawOpt);
var layerType = 'polyline';
window.plugin.drawToolsPlus.fireDraw(layer, layerType);
if(color !== undefined){ window.plugin.drawTools.setDrawColor(oldColor); }
return layer;
}
window.plugin.drawToolsPlus.drawPolygon = function(arrCoordArr, color){
if(color !== undefined){
var oldColor = window.plugin.drawTools.currentColor;
window.plugin.drawTools.setDrawColor(color);
}
var drawOpt = window.plugin.drawTools.polygonOptions;
var layer = L.geodesicPolygon(arrCoordArr, drawOpt);
var layerType = 'polygon';
window.plugin.drawToolsPlus.fireDraw(layer, layerType);
if(color !== undefined){ window.plugin.drawTools.setDrawColor(oldColor); }
return layer;
}
window.plugin.drawToolsPlus.drawCircle = function(coord, radius, color){
if(color !== undefined){
var oldColor = window.plugin.drawTools.currentColor;
window.plugin.drawTools.setDrawColor(color);
}
var drawOpt = window.plugin.drawTools.polygonOptions;
var layer = L.geodesicCircle(coord, radius, drawOpt);
var layerType = 'circle';
window.plugin.drawToolsPlus.fireDraw(layer, layerType);
if(color !== undefined){ window.plugin.drawTools.setDrawColor(oldColor); }
return layer;
}
window.plugin.drawToolsPlus.drawMarker = function(coord, color){
if(color !== undefined){
var oldColor = window.plugin.drawTools.currentColor;
window.plugin.drawTools.setDrawColor(color);
}
var drawOpt = window.plugin.drawTools.markerOptions;
var layer = L.marker(coord, drawOpt);
var layerType = 'marker';
window.plugin.drawToolsPlus.fireDraw(layer, layerType);
if(color !== undefined){ window.plugin.drawTools.setDrawColor(oldColor); }
return layer;
}
// *********************************************************************************
window.plugin.drawToolsPlus.setupCSS = function(){
$("<style>").prop("type", "text/css").html(''
+'.leaflet-bar{box-shadow:0 1px 5px rgba(0,0,0,.65);}'
+'.leaflet-draw .leaflet-draw-section .leaflet-bar{box-shadow:none;}'
+'.leaflet-draw{box-shadow:0 1px 5px rgba(0,0,0,.65);border-radius:4px;}'
+'.leaflet-draw .leaflet-draw-section .leaflet-bar.leaflet-draw-toolbar-top a:last-child{border-bottom:2px solid #999;}'
+'.leaflet-draw .leaflet-draw-section .leaflet-bar a{border-radius:0;}'
+'.leaflet-draw .leaflet-draw-section .leaflet-bar{border-radius:0 0 4px 4px;overflow:hidden;margin-top:0;}'
+'.leaflet-draw .leaflet-draw-section .leaflet-bar.leaflet-draw-toolbar-top{border-radius:4px 4px 0 0;}'
).appendTo("head");
}
function setup (){
if(window.plugin.drawTools){
window.pluginCreateHook('pluginDrawTools');
window.plugin.drawToolsPlus.boot();
window.plugin.drawToolsPlus.setupCSS();
}
}
// 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);