some cleanups to #746
This commit is contained in:
parent
c174cbe20b
commit
af491221dc
@ -2,7 +2,7 @@
|
|||||||
// @id iitc-plugin-draw-tools@breunigs
|
// @id iitc-plugin-draw-tools@breunigs
|
||||||
// @name IITC plugin: draw tools
|
// @name IITC plugin: draw tools
|
||||||
// @category Layer
|
// @category Layer
|
||||||
// @version 0.5.3.@@DATETIMEVERSION@@
|
// @version 0.6.0.@@DATETIMEVERSION@@
|
||||||
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
|
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
|
||||||
// @updateURL @@UPDATEURL@@
|
// @updateURL @@UPDATEURL@@
|
||||||
// @downloadURL @@DOWNLOADURL@@
|
// @downloadURL @@DOWNLOADURL@@
|
||||||
@ -32,11 +32,12 @@ window.plugin.drawTools.loadExternals = function() {
|
|||||||
$('head').append('<style>@@INCLUDESTRING:external/leaflet.draw.css@@</style>');
|
$('head').append('<style>@@INCLUDESTRING:external/leaflet.draw.css@@</style>');
|
||||||
}
|
}
|
||||||
|
|
||||||
window.plugin.drawTools.setOptions = function(setcolor) {
|
window.plugin.drawTools.setOptions = function(color) {
|
||||||
|
if (color === undefined) color = '#a24ac3';
|
||||||
|
|
||||||
window.plugin.drawTools.lineOptions = {
|
window.plugin.drawTools.lineOptions = {
|
||||||
stroke: true,
|
stroke: true,
|
||||||
color: setcolor,
|
color: color,
|
||||||
weight: 4,
|
weight: 4,
|
||||||
opacity: 0.5,
|
opacity: 0.5,
|
||||||
fill: false,
|
fill: false,
|
||||||
@ -62,7 +63,7 @@ window.plugin.drawTools.setOptions = function(setcolor) {
|
|||||||
|
|
||||||
|
|
||||||
// renders the draw control buttons in the top left corner
|
// renders the draw control buttons in the top left corner
|
||||||
window.plugin.drawTools.DrawControl = function() {
|
window.plugin.drawTools.addDrawControl = function() {
|
||||||
var drawControl = new L.Control.Draw({
|
var drawControl = new L.Control.Draw({
|
||||||
draw: {
|
draw: {
|
||||||
rectangle: false,
|
rectangle: false,
|
||||||
@ -124,9 +125,8 @@ window.plugin.drawTools.DrawControl = function() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
});
|
});
|
||||||
return drawControl;
|
|
||||||
|
|
||||||
|
|
||||||
|
map.addControl(drawControl);
|
||||||
// plugin.drawTools.addCustomButtons();
|
// plugin.drawTools.addCustomButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,27 +196,19 @@ window.plugin.drawTools.load = function() {
|
|||||||
var layer = null;
|
var layer = null;
|
||||||
switch(item.type) {
|
switch(item.type) {
|
||||||
case 'polyline':
|
case 'polyline':
|
||||||
if (typeof item.color === 'undefined'){
|
window.plugin.drawTools.setOptions(item.color);
|
||||||
window.plugin.drawTools.setOptions('#a24ac3');
|
|
||||||
}else{
|
|
||||||
window.plugin.drawTools.setOptions(item.color);}
|
|
||||||
layer = L.geodesicPolyline(item.latLngs,window.plugin.drawTools.lineOptions);
|
layer = L.geodesicPolyline(item.latLngs,window.plugin.drawTools.lineOptions);
|
||||||
break;
|
break;
|
||||||
case 'polygon':
|
case 'polygon':
|
||||||
if (typeof item.color === 'undefined'){
|
window.plugin.drawTools.setOptions(item.color);
|
||||||
window.plugin.drawTools.setOptions('#a24ac3');
|
|
||||||
}else{
|
|
||||||
window.plugin.drawTools.setOptions(item.color);}
|
|
||||||
layer = L.geodesicPolygon(item.latLngs,window.plugin.drawTools.polygonOptions);
|
layer = L.geodesicPolygon(item.latLngs,window.plugin.drawTools.polygonOptions);
|
||||||
break;
|
break;
|
||||||
case 'circle':
|
case 'circle':
|
||||||
if (typeof item.color === 'undefined'){
|
window.plugin.drawTools.setOptions(item.color);
|
||||||
window.plugin.drawTools.setOptions('#a24ac3');
|
|
||||||
}else{
|
|
||||||
window.plugin.drawTools.setOptions(item.color);}
|
|
||||||
layer = L.geodesicCircle(item.latLng,item.radius,window.plugin.drawTools.polygonOptions);
|
layer = L.geodesicCircle(item.latLng,item.radius,window.plugin.drawTools.polygonOptions);
|
||||||
break;
|
break;
|
||||||
case 'marker':
|
case 'marker':
|
||||||
|
// TODO? marker colours
|
||||||
layer = L.marker(item.latLng,window.plugin.drawTools.markerOptions)
|
layer = L.marker(item.latLng,window.plugin.drawTools.markerOptions)
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -232,64 +224,63 @@ window.plugin.drawTools.load = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Draw Tools Options
|
//Draw Tools Options
|
||||||
// Manual import, export and reset data
|
|
||||||
window.plugin.drawTools.manualOpt = function() {
|
// Manual import, export and reset data
|
||||||
|
window.plugin.drawTools.manualOpt = function() {
|
||||||
|
dialog({
|
||||||
|
html: plugin.drawTools.htmlSetbox,
|
||||||
|
dialogClass: 'ui-dialog-drawtoolsSet',
|
||||||
|
title: 'Draw Tools Options'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
window.plugin.drawTools.optAlert = function(message) {
|
||||||
|
$('.ui-dialog-drawtoolsSet .ui-dialog-buttonset').prepend('<p class="drawtools-alert" style="float:left;margin-top:4px;">'+message+'</p>');
|
||||||
|
$('.drawtools-alert').delay(2500).fadeOut();
|
||||||
|
}
|
||||||
|
|
||||||
|
window.plugin.drawTools.optCopy = function() {
|
||||||
dialog({
|
dialog({
|
||||||
html: plugin.drawTools.htmlSetbox,
|
html: '<p><a onclick="$(\'.ui-dialog-drawtoolsSet-copy textarea\').select();">Select all</a> and press CTRL+C to copy it.</p><textarea readonly onclick="$(\'.ui-dialog-drawtoolsSet-copy textarea\').select();">'+localStorage['plugin-draw-tools-layer']+'</textarea>',
|
||||||
dialogClass: 'ui-dialog-drawtoolsSet',
|
width: 600,
|
||||||
title: 'Draw Tools Options'
|
dialogClass: 'ui-dialog-drawtoolsSet-copy',
|
||||||
|
title: 'Draw Tools Export'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
window.plugin.drawTools.optAlert = function(message) {
|
window.plugin.drawTools.optPaste = function() {
|
||||||
$('.ui-dialog-drawtoolsSet .ui-dialog-buttonset').prepend('<p class="drawtools-alert" style="float:left;margin-top:4px;">'+message+'</p>');
|
var promptAction = prompt('Press CTRL+V to paste it.', '');
|
||||||
$('.drawtools-alert').delay(2500).fadeOut();
|
if(promptAction !== null && promptAction !== '') {
|
||||||
|
localStorage['plugin-draw-tools-layer'] = promptAction;
|
||||||
|
window.plugin.drawTools.drawnItems.clearLayers();
|
||||||
|
window.plugin.drawTools.load();
|
||||||
|
console.log('DRAWTOOLS: reset and imported drawn tiems');
|
||||||
|
window.plugin.drawTools.optAlert('Import Successful.');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
window.plugin.drawTools.optCopy = function() {
|
window.plugin.drawTools.optReset = function() {
|
||||||
dialog({
|
var promptAction = confirm('All drawn items will be deleted. Are you sure?', '');
|
||||||
html: '<p><a onclick="$(\'.ui-dialog-drawtoolsSet-copy textarea\').select();">Select all</a> and press CTRL+C to copy it.</p><textarea readonly>'+localStorage['plugin-draw-tools-layer']+'</textarea>',
|
if(promptAction) {
|
||||||
dialogClass: 'ui-dialog-drawtoolsSet-copy',
|
delete localStorage['plugin-draw-tools-layer'];
|
||||||
title: 'Draw Tools Export'
|
window.plugin.drawTools.drawnItems.clearLayers();
|
||||||
});
|
window.plugin.drawTools.load();
|
||||||
|
console.log('DRAWTOOLS: reset all drawn items');
|
||||||
|
window.plugin.drawTools.optAlert('Reset Successful. ');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
window.plugin.drawTools.optPaste = function() {
|
window.plugin.drawTools.optColor = function() {
|
||||||
var promptAction = prompt('Press CTRL+V to paste it.', '');
|
var promptAction = prompt('Current Color is '+window.plugin.drawTools.lineOptions.color, '');
|
||||||
if(promptAction !== null && promptAction !== '') {
|
if(promptAction !== null && promptAction !== '') {
|
||||||
localStorage['plugin-draw-tools-layer'] = promptAction;
|
window.plugin.drawTools.setOptions(promptAction);
|
||||||
window.plugin.drawTools.drawnItems.clearLayers();
|
console.log('DRAWTOOLS: color changed');
|
||||||
window.plugin.drawTools.load();
|
window.plugin.drawTools.optAlert('Color Changed. ');
|
||||||
console.log('DRAWTOOLS: reset and imported drawn tiems');
|
|
||||||
window.plugin.drawTools.optAlert('Import Successful. ');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
window.plugin.drawTools.optReset = function() {
|
|
||||||
var promptAction = prompt('All drawn items will be deleted. Are you sure? [Y/N]', '');
|
|
||||||
if(promptAction !== null && (promptAction === 'Y' || promptAction === 'y')) {
|
|
||||||
delete localStorage['plugin-draw-tools-layer'];
|
|
||||||
window.plugin.drawTools.drawnItems.clearLayers();
|
|
||||||
window.plugin.drawTools.load();
|
|
||||||
console.log('DRAWTOOLS: reset all drawn items');
|
|
||||||
window.plugin.drawTools.optAlert('Reset Successful. ');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
window.plugin.drawTools.optColor = function() {
|
|
||||||
var promptAction = prompt('Current Color is '+window.plugin.drawTools.lineOptions.color, '');
|
|
||||||
if(promptAction !== null && promptAction !== '') {
|
|
||||||
plugin.drawTools.controller.removeFrom(map);
|
|
||||||
window.plugin.drawTools.setOptions(promptAction);
|
|
||||||
plugin.drawTools.controller = plugin.drawTools.DrawControl();
|
|
||||||
plugin.drawTools.controller.addTo(map);
|
|
||||||
console.log('DRAWTOOLS: color changed');
|
|
||||||
window.plugin.drawTools.optAlert('Color Changed. ');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
window.plugin.drawTools.boot = function() {
|
window.plugin.drawTools.boot = function() {
|
||||||
window.plugin.drawTools.setOptions('#a24ac3');
|
window.plugin.drawTools.setOptions();
|
||||||
|
|
||||||
//create a leaflet FeatureGroup to hold drawn items
|
//create a leaflet FeatureGroup to hold drawn items
|
||||||
window.plugin.drawTools.drawnItems = new L.FeatureGroup();
|
window.plugin.drawTools.drawnItems = new L.FeatureGroup();
|
||||||
@ -298,8 +289,7 @@ window.plugin.drawTools.boot = function() {
|
|||||||
plugin.drawTools.load();
|
plugin.drawTools.load();
|
||||||
|
|
||||||
//add the draw control - this references the above FeatureGroup for editing purposes
|
//add the draw control - this references the above FeatureGroup for editing purposes
|
||||||
plugin.drawTools.controller = plugin.drawTools.DrawControl();
|
plugin.drawTools.addDrawControl();
|
||||||
plugin.drawTools.controller.addTo(map);
|
|
||||||
|
|
||||||
//start off hidden. if the layer is enabled, the below addLayerGroup will add it, triggering a 'show'
|
//start off hidden. if the layer is enabled, the below addLayerGroup will add it, triggering a 'show'
|
||||||
$('.leaflet-draw-section').hide();
|
$('.leaflet-draw-section').hide();
|
||||||
@ -344,10 +334,11 @@ window.plugin.drawTools.boot = function() {
|
|||||||
+'<a onclick="window.plugin.drawTools.optPaste();return false;">Paste/Import Drawn Items</a>'
|
+'<a onclick="window.plugin.drawTools.optPaste();return false;">Paste/Import Drawn Items</a>'
|
||||||
+'<a onclick="window.plugin.drawTools.optReset();return false;">Reset Drawn Items</a>'
|
+'<a onclick="window.plugin.drawTools.optReset();return false;">Reset Drawn Items</a>'
|
||||||
+'</div>';
|
+'</div>';
|
||||||
|
|
||||||
$('head').append('<style>' +
|
$('head').append('<style>' +
|
||||||
'#drawtoolsSetbox a{display:block; color:#ffce00; border:1px solid #ffce00; padding:3px 0; margin:10px auto; width:80%; text-align:center; background:rgba(8,48,78,.9);}'+
|
'#drawtoolsSetbox a { display:block; color:#ffce00; border:1px solid #ffce00; padding:3px 0; margin:10px auto; width:80%; text-align:center; background:rgba(8,48,78,.9); }'+
|
||||||
'.ui-dialog-drawtoolsSet-copy textarea{width:96%; height:120px; resize:vertical;}'+
|
'.ui-dialog-drawtoolsSet-copy textarea { width:96%; height:250px; resize:vertical; }'+
|
||||||
'</style>');
|
'</style>');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user