'+message+'
'); $('.drawtools-alert').delay(2500).fadeOut(); } window.plugin.drawTools.optCopy = function() { if (typeof android !== 'undefined' && android && android.shareString) { android.shareString(localStorage['plugin-draw-tools-layer']); } else { dialog({ html: 'Select all and press CTRL+C to copy it.
', width: 600, dialogClass: 'ui-dialog-drawtoolsSet-copy', title: 'Draw Tools Export' }); } } window.plugin.drawTools.optExport = function() { if(typeof android !== 'undefined' && android && android.saveFile) { android.saveFile('IITC-drawn-items.json', 'application/json', localStorage['plugin-draw-tools-layer']); } } window.plugin.drawTools.optPaste = function() { var promptAction = prompt('Press CTRL+V to paste it.', ''); if(promptAction !== null && promptAction !== '') { try { var data = JSON.parse(promptAction); window.plugin.drawTools.drawnItems.clearLayers(); window.plugin.drawTools.import(data); console.log('DRAWTOOLS: reset and imported drawn tiems'); window.plugin.drawTools.optAlert('Import Successful.'); // to write back the data to localStorage window.plugin.drawTools.save(); } catch(e) { console.warn('DRAWTOOLS: failed to import data: '+e); window.plugin.drawTools.optAlert('Import failed'); } } } window.plugin.drawTools.optImport = function() { if (window.requestFile === undefined) return; window.requestFile(function(filename, content) { try { var data = JSON.parse(content); window.plugin.drawTools.drawnItems.clearLayers(); window.plugin.drawTools.import(data); console.log('DRAWTOOLS: reset and imported drawn tiems'); window.plugin.drawTools.optAlert('Import Successful.'); // to write back the data to localStorage window.plugin.drawTools.save(); } catch(e) { console.warn('DRAWTOOLS: failed to import data: '+e); window.plugin.drawTools.optAlert('Import failed'); } }); } window.plugin.drawTools.optReset = function() { var promptAction = confirm('All drawn items will be deleted. Are you sure?', ''); if(promptAction) { 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.boot = function() { window.plugin.drawTools.currentMarker = window.plugin.drawTools.getMarkerIcon(window.plugin.drawTools.currentColor); window.plugin.drawTools.setOptions(); //create a leaflet FeatureGroup to hold drawn items window.plugin.drawTools.drawnItems = new L.FeatureGroup(); //load any previously saved items plugin.drawTools.load(); //add the draw control - this references the above FeatureGroup for editing purposes plugin.drawTools.addDrawControl(); //start off hidden. if the layer is enabled, the below addLayerGroup will add it, triggering a 'show' $('.leaflet-draw-section').hide(); //hide the draw tools when the 'drawn items' layer is off, show it when on map.on('layeradd', function(obj) { if(obj.layer === window.plugin.drawTools.drawnItems) { $('.leaflet-draw-section').show(); } }); map.on('layerremove', function(obj) { if(obj.layer === window.plugin.drawTools.drawnItems) { $('.leaflet-draw-section').hide(); } }); //add the layer window.addLayerGroup('Drawn Items', window.plugin.drawTools.drawnItems, true); //place created items into the specific layer map.on('draw:created', function(e) { var type=e.layerType; var layer=e.layer; window.plugin.drawTools.drawnItems.addLayer(layer); window.plugin.drawTools.save(); if(layer instanceof L.Marker) { window.registerMarkerForOMS(layer); } }); map.on('draw:deleted', function(e) { window.plugin.drawTools.save(); }); map.on('draw:edited', function(e) { window.plugin.drawTools.save(); }); //add options menu $('#toolbox').append('DrawTools Opt'); $('head').append(''); } var setup = window.plugin.drawTools.loadExternals; // PLUGIN END ////////////////////////////////////////////////////////// @@PLUGINEND@@