diff --git a/plugins/cache-portals-on-map.js b/plugins/cache-portals-on-map.js index 2819452b2..1242c31b8 100644 --- a/plugins/cache-portals-on-map.js +++ b/plugins/cache-portals-on-map.js @@ -1,7 +1,7 @@ // @author jonatkins // @name Cache viewed portals on map // @category Cache -// @version 0.1.0 +// @version 0.2.0 // @description Cache the details of recently viewed portals and use this to populate the map when possible @@ -31,8 +31,8 @@ window.plugin.cachePortalDetailsOnMap.entityInject = function(data) { }; // extend portal's GUID lookup to search in cached portals as well -window.cachePortalDetailsOnMap.findPortalGuidByCacheE6 = function(latE6, lngE6) { - let guid = window.cachePortalDetailsOnMap.findPortalGuidByPositionE6old(latE6, lngE6); +window.plugin.cachePortalDetailsOnMap.findPortalGuidByCacheE6 = function(latE6, lngE6) { + let guid = window.plugin.cachePortalDetailsOnMap.findPortalGuidByPositionE6old(latE6, lngE6); // PLUGIN: cache > cache if (guid == null) { @@ -41,7 +41,7 @@ window.cachePortalDetailsOnMap.findPortalGuidByCacheE6 = function(latE6, lngE6) for (let g in cache.cache) { let p = cache.cache[g]; if (latE6 == p.ent[2][2] && lngE6 == p.ent[2][3]) { -// console.log("newFindPortalGuidByPositionE6 matched in cache! %s %s -> [%s] = %o", latE6, lngE6, g, p); + console.log("findPortalGuidByCacheE6 matched in cache! %s %s -> [%s] = %o", latE6, lngE6, g, p); guid = g; break; } @@ -49,17 +49,18 @@ window.cachePortalDetailsOnMap.findPortalGuidByCacheE6 = function(latE6, lngE6) } } return guid; -}; +} -window.cachePortalDetailsOnMap.searchInit = function () { - window.cachePortalDetailsOnMap.findPortalGuidByPositionE6old = window.findPortalGuidByPositionE6; - window.findPortalGuidByPositionE6 = window.cachePortalDetailsOnMap.findPortalGuidByCacheE6; -}; +window.plugin.cachePortalDetailsOnMap.searchInit = function () { + window.plugin.cachePortalDetailsOnMap.findPortalGuidByPositionE6old = window.findPortalGuidByPositionE6; + window.findPortalGuidByPositionE6 = window.plugin.cachePortalDetailsOnMap.findPortalGuidByCacheE6; + console.log ("findPortalGuidByCacheE6 code injected"); +} window.plugin.cachePortalDetailsOnMap.setup = function() { window.plugin.cachePortalDetailsOnMap.cache = {}; - window.plugin.cachePortaldetailsOnMap.searchInit; + window.plugin.cachePortalDetailsOnMap.searchInit (); addHook('portalDetailLoaded', window.plugin.cachePortalDetailsOnMap.portalDetailLoaded); addHook('mapDataEntityInject', window.plugin.cachePortalDetailsOnMap.entityInject); diff --git a/plugins/draw-tools.js b/plugins/draw-tools.js index 81cba4572..11188d4c4 100644 --- a/plugins/draw-tools.js +++ b/plugins/draw-tools.js @@ -1,9 +1,8 @@ // @author breunigs // @name Draw tools // @category Draw -// @version 0.8.0 -// @description Allow drawing things onto the current map so you may plan your next move. Supports Multi-Project-Extension. - +// @version 0.8.2 +// @description Allow drawing things onto the current map so you may plan your next move. Supports Multi-Project-Extension and Empty Drawn Fields (EDF) // HOOK: pluginDrawTools // custom hook for draw tools to share it's activity with other plugins @@ -13,6 +12,14 @@ window.plugin.drawTools = function() {}; window.plugin.drawTools.KEY_STORAGE = 'plugin-draw-tools-layer'; +window.plugin.drawTools.merge = {}; +window.plugin.drawTools.merge.status = true; +window.plugin.drawTools.merge.toggle() = function() { + var status = window.plugin.drawTools.merge.status; + status = Boolean(!status); + window.plugin.drawTools.merge.status = status; + } + window.plugin.drawTools.getMarkerIcon = function(color) { if (!color) { console.warn('Color is not set (default #a24ac3 will be used)'); @@ -258,9 +265,17 @@ window.plugin.drawTools.import = function(data) { //Draw Tools Options - // Manual import, export and reset data window.plugin.drawTools.manualOpt = function() { + var mergeStatusCheck = ''; + if(!window.plugin.drawTools.merge.status){ + mergeStatusCheck = 'checked'; + } + + var edfStatusCheck = ''; + if(!window.plugin.drawTools.edf.obj.status){ + edfStatusCheck = 'checked'; + } var html = '
' + '' @@ -268,11 +283,17 @@ window.plugin.drawTools.manualOpt = function() { + '
' + '
' + 'Copy Drawn Items' + + '
' + //+ '
Do not overwrite, merge!
' + 'Paste Drawn Items' + 'Import Drawn Items' + 'Export Drawn Items' + 'Reset Drawn Items' + 'Snap to portals' + + '
' + '
'; dialog({ @@ -359,11 +380,30 @@ window.plugin.drawTools.optCopy = function() { if (stockWarnings.noCircle) stockWarnTexts.push('Warning: Circles cannot be exported to stock intel'); if (stockWarnings.noMarker) stockWarnTexts.push('Warning: Markers cannot be exported to stock intel'); if (stockWarnings.unknown) stockWarnTexts.push('Warning: UNKNOWN ITEM TYPE'); - +/* var html = '

Select all and press CTRL+C to copy it.

' +'' +'

or, export as a link for the standard intel map (for non IITC users)

' +''; +*/ + // Export Normal draw + var html = '' + +'

Normal export:

' + +'

Select all and press CTRL+C to copy it.

' + +''; + + // Export draw (polygons as lines) + html += '
' + +'

or export with polygons as lines (not filled):

' + +'

Select all and press CTRL+C to copy it.

' + +''; + + // Export for intel stock URL (only lines) + html += '
' + +'

or export as a link for the standard intel map (for non IITC users):

' + +'

Select all and press CTRL+C to copy it.

' + +''; + if (stockWarnTexts.length>0) { html += ''; } @@ -388,6 +428,7 @@ window.plugin.drawTools.optExport = function() { } window.plugin.drawTools.optPaste = function() { +// if (merge === undefined) merge = true; //default to true var promptAction = prompt('Press CTRL+V to paste (draw-tools data or stock intel URL).', ''); promptAction = promptAction && promptAction.trim(); if (promptAction) { @@ -428,17 +469,26 @@ window.plugin.drawTools.optPaste = function() { } // all parsed OK - clear and insert - window.plugin.drawTools.drawnItems.clearLayers(); + if (!window.plugin.drawTools.merge.status) { + window.plugin.drawTools.drawnItems.clearLayers(); + } for (var i=0; i 4 + ? window.localStorage[window.plugin.drawTools.KEY_STORAGE].slice(0,-1) + ',' + promptAction.slice(1) + : promptAction); + } var data; try{ data = JSON.parse(promptAction); @@ -455,7 +505,7 @@ window.plugin.drawTools.optPaste = function() { } window.plugin.drawTools.drawnItems.clearLayers(); window.plugin.drawTools.import(data); - console.log('DRAWTOOLS: reset and imported drawn items'); + console.log('DRAWTOOLS: '+(window.plugin.drawTools.merge.status?'':'reset and ')+'pasted drawn items'); window.plugin.drawTools.optAlert('Import Successful.'); } @@ -473,9 +523,11 @@ window.plugin.drawTools.optImport = function() { .on('load',function (e) { try { var data = JSON.parse(e.reader.result); - window.plugin.drawTools.drawnItems.clearLayers(); + if (!window.plugin.drawTools.merge.status) { + window.plugin.drawTools.drawnItems.clearLayers(); + } window.plugin.drawTools.import(data); - console.log('DRAWTOOLS: reset and imported drawn tiems'); + console.log('DRAWTOOLS: '+(window.plugin.drawTools.merge.status?'':'reset and ')+'imported drawn items'); window.plugin.drawTools.optAlert('Import Successful.'); // to write back the data to localStorage @@ -654,7 +706,7 @@ window.plugin.drawTools.boot = function() { $('head').append(''); } @@ -710,9 +762,111 @@ window.plugin.drawTools.mpe.initMPE = function(){ }); } +// EXPORT (POLYS AS LINES) +// --------------------------------------------------------------------------------- +window.plugin.drawTools.getDrawAsLines = function(){ + var rawDraw = JSON.parse(window.localStorage[window.plugin.drawTools.KEY_STORAGE]); + var draw = []; + + for(i in rawDraw){ + var elemDraw = rawDraw[i]; + + if(elemDraw.type === 'polygon'){ + var convElemDraw = {}; + convElemDraw.color = elemDraw.color; + convElemDraw.type = 'polyline'; + convElemDraw.latLngs = []; + + var v = elemDraw.latLngs.length; + for(j in elemDraw.latLngs){ + var ll = elemDraw.latLngs[j]; + convElemDraw.latLngs.push(ll); + } + convElemDraw.latLngs.push(elemDraw.latLngs[0]); + + draw.push(convElemDraw); + }else{ + draw.push(elemDraw); + } + } + + return JSON.stringify(draw); +} + +// --------------------------------------------------------------------------------- +// EMPTY POLYGONS (EMPTY DRAWN FIELDS) +// --------------------------------------------------------------------------------- +window.plugin.drawTools.edf = {}; +window.plugin.drawTools.edf.storage = {}; +window.plugin.drawTools.edf.draw = {}; +window.plugin.drawTools.edf.obj = {}; +window.plugin.drawTools.edf.action = {}; +window.plugin.drawTools.edf.ui = {}; + +window.plugin.drawTools.edf.boot = function(){ + window.addHook('pluginDrawTools', window.plugin.drawTools.edf.hookManagement); + window.addHook('iitcLoaded', function(){ + if(window.plugin.drawTools.edf.obj.status){ + window.plugin.drawTools.edf.draw.toggleOpacityOpt(); + window.plugin.drawTools.edf.draw.clearAndDraw(); + } + }); +}; + +window.plugin.drawTools.edf.obj.status = false; +window.plugin.drawTools.edf.obj.toggle = function(){ + var status = window.plugin.drawTools.edf.obj.status; + status = Boolean(!status); + window.plugin.drawTools.edf.obj.status = status; +} +window.plugin.drawTools.edf.draw.toggleOpacityOpt = function(){ + if(window.plugin.drawTools.edf.obj.status){ + window.plugin.drawTools.polygonOptions.fillOpacity = 0.0; + }else{ + window.plugin.drawTools.polygonOptions.fillOpacity = 0.2; + } +} +window.plugin.drawTools.edf.draw.clearAndDraw = function(){ + window.plugin.drawTools.drawnItems.clearLayers(); + window.plugin.drawTools.load(); + console.log('DRAWTOOLS: reset all drawn items'); +} + +window.plugin.drawTools.edf.action.toggle = function(){ + window.plugin.drawTools.edf.obj.toggle(); + window.plugin.drawTools.edf.draw.toggleOpacityOpt(); + window.plugin.drawTools.edf.draw.clearAndDraw(); +} + +window.plugin.drawTools.edf.hookManagement = function(data){ + if(data.event === 'openOpt'){ + }else if(data.event == 'layerCreated'){ + if(window.plugin.drawTools.edf.obj.status){ + // window.plugin.drawTools.edf.draw.toggleOpacityOpt(); // disabled by Zaso + window.plugin.drawTools.edf.draw.clearAndDraw(); + } + } +} + +window.plugin.drawTools.setupCSS = function(){ + $("