diff --git a/BeenThere.js b/BeenThere.js
index 1493b83..7d94099 100644
--- a/BeenThere.js
+++ b/BeenThere.js
@@ -12,7 +12,7 @@
// @require https://greasyfork.org/scripts/27254-clipboard-js/code/clipboardjs.js
// @require https://greasyfork.org/scripts/28687-jquery-ui-1-11-4-custom-min-js/code/jquery-ui-1114customminjs.js
// @resource jqUI_CSS https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css
-// @version 2019.03.14.01
+// @version 2019.04.10.01
// ==/UserScript==
//---------------------------------------------------------------------------------------
@@ -24,24 +24,26 @@
/* global _ */
/* global WazeWrap */
/* global require */
+/* global Clipboard */
/* eslint curly: ["warn", "multi-or-nest"] */
- var beenTheresettings = [];
- var attributes = {
- name: ""
- };
- var layerFuture = [];
- var pointStyle = {
- pointRadius: 3,
- fillOpacity: 50,
- strokeColor: '#00ece3',
- strokeWidth: '2',
- strokeLinecap: 'round'
- };
- var clickCount = 0;
- var userRectPoint1 = null;
- var userCircleCenter = null;
- var currColor;
+var beenTheresettings = [];
+var attributes = {
+ name: ""
+};
+var layerFuture = [];
+var pointStyle = {
+ pointRadius: 3,
+ fillOpacity: 50,
+ strokeColor: '#00ece3',
+ strokeWidth: '2',
+ strokeLinecap: 'round'
+};
+var clickCount = 0;
+var userRectPoint1 = null;
+var userCircleCenter = null;
+var currColor;
+const updateMessage = "Introducing groups! It is now possible to create groups for projects and keep your on-screen markings separated per project!
Any existing history will automatically be merged into the 'default' group.";
(function() {
//var jqUI_CssSrc = GM_getResourceText("jqUI_CSS");
@@ -51,7 +53,7 @@
if (W && W.map &&
W.model && W.loginManager.user &&
$ && window.jscolor &&
- WazeWrap.Ready)
+ WazeWrap.Ready)
init();
else if (tries < 1000)
setTimeout(function () {bootstrap(tries++);}, 200);
@@ -84,7 +86,7 @@
radius: null
};
- beenTheresettings.layerHistory.push(groupPoints2);
+ beenTheresettings.Groups[beenTheresettings.CurrentGroup].push(groupPoints2);
DrawFeature(groupPoints2);
}
@@ -231,7 +233,7 @@
type : "circle"
};
- beenTheresettings.layerHistory.push(circleData);
+ beenTheresettings.Groups[beenTheresettings.CurrentGroup].push(circleData);
saveSettings();
DrawFeature(circleData);
EndUserCircleMode();
@@ -266,7 +268,7 @@
color: currColor,
type: "rectangle"
};
- beenTheresettings.layerHistory.push(groupPoints2);
+ beenTheresettings.Groups[beenTheresettings.CurrentGroup].push(groupPoints2);
saveSettings();
DrawFeature(groupPoints2);
EndUserRectMode();
@@ -408,8 +410,8 @@
var mro_mapLayers_mapLayerLength = mro_mapLayers[0].features.length;
if (mro_mapLayers_mapLayerLength > 0)
mro_mapLayers[0].features[mro_mapLayers_mapLayerLength - 1].destroy();
- if(beenTheresettings.layerHistory.length > 0)
- layerFuture.push(beenTheresettings.layerHistory.pop());
+ if(beenTheresettings.Groups[beenTheresettings.CurrentGroup].length > 0)
+ layerFuture.push(beenTheresettings.Groups[beenTheresettings.CurrentGroup].pop());
saveSettings();
updateTotalRectCount();
}
@@ -417,13 +419,13 @@
function RedoLastBox(){
if(layerFuture.length >0){
var rect = layerFuture.pop();
- beenTheresettings.layerHistory.push(rect);
+ beenTheresettings.Groups[beenTheresettings.CurrentGroup].push(rect);
DrawFeature(rect);
}
}
function RemoveAllBoxes() {
- if(beenTheresettings.layerHistory.length > 0)
+ if(beenTheresettings.Groups[beenTheresettings.CurrentGroup].length > 0)
if(confirm("Clearing all boxes cannot be undone.\nPress OK to clear all boxes.")){
var mro_Map = W.map;
var mro_mapLayers = mro_Map.getLayersBy("uniqueName", "__beenThere");
@@ -431,7 +433,7 @@
var mro_mapLayers_mapLayerLength = mro_mapLayers[0].features.length;
if (mro_mapLayers_mapLayerLength > 0)
mro_mapLayers[0].destroyFeatures();
- beenTheresettings.layerHistory = [];
+ beenTheresettings.Groups[beenTheresettings.CurrentGroup] = [];
layerFuture = [];
saveSettings();
updateTotalRectCount();
@@ -483,14 +485,14 @@
'
',
'',//close left side container
'', //right side container
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
'
' //close right side container
].join(' '));
@@ -535,10 +537,20 @@
saveSettings();
}
});
+
+ $('#BeenThereSettings').draggable({
+ stop: function(event, ui) {
+ beenTheresettings.SettingsLocLeft = $('#BeenThereSettings').css('left');
+ beenTheresettings.SettingsLocTop = $('#BeenThereSettings').css('top');
+ saveSettings();
+ }
+ });
}
initColorPicker();
LoadSettings();
+
+ WazeWrap.Interface.ShowScriptUpdate("WME BeenThere", GM_info.script.version, updateMessage, "https://greasyfork.org/scripts/27035-wme-beenthere", "https://www.waze.com/forum/viewtopic.php?f=819&t=218182");
}
function LayerToggled(checked){
@@ -550,56 +562,73 @@
Takes the settings loaded into the settings obj and loads them into the interface and draws any features that were saved
*/
function LoadSettings(){
- if(beenTheresettings.layerHistory.length > 0)
- for(var i=0;i", {style:"padding:8px 16px", id:"WMEBeenThereSettings"});
$section.html([
- '',
- '
',
- '
Drawing
',
- '
Draw shape border',
- '
Fill shape',
+ `
`,
+ '
', //top div - split left/right
+ '
', //left side div
+ '
Drawing
',
+ 'Draw shape border',
+ 'Fill shape',
'',//close drawing div
- '
',
- '
Export/Import
',
- '
',
- '
',
+ '
Export/Import
',
+ '
',
'',
'
',//end export div
- '
',
+ '
', // import div
'',
'',
'
',//end import div
'
',//close import/export div
- '
', //save/cancel buttons
- '',
- '',
+ '
', //close left side div
+
+ '
', //right side div
+ '
Groups
',
+ '
',
+ '
',
+ '
',
+ '
',//textboxes div
+ '',
+ '
', //End textboxes div
+
+ '
',//button div
+ '',
+ '
',//close button div
+ '
', //close BeenThereGroups
+ '
', //close right side div
+ '
', //close top div
+
+ '
', //save/cancel buttons
+ '',
'
',//end save/cancel buttons
'
'
].join(' '));
$("#WazeMap").append($section.html());
- $("#BeenThereSettingsCancel").click(function(){
- $('#BeenThereSettings').css({'visibility':'hidden'}); //hide the settings window
- });
-
- $("#BeenThereSettingsSave").click(function(){
+ $('.btOptions').change(function(){
beenTheresettings.DrawShapeBorder = isChecked('chkBTShapeBorder');
beenTheresettings.FillShape = isChecked('chkBTShapeFill');
saveSettings();
+ });
+ $("#BeenThereSettingsClose").click(function(){
$('#BeenThereSettings').css({'visibility':'hidden'}); //hide the settings window
});
@@ -611,9 +640,60 @@
}
});
+ LoadCustomGroups();
+
+ $('#btAddGroup').click(function(){
+ if($('#btGroupName').val() !== ""){
+ let name = $('#btGroupName').val();
+ let exists = beenTheresettings.Groups[name];
+ if(exists == null){
+ beenTheresettings.Groups[name] = [];
+ $('#btGroupsName').val("");
+ LoadCustomGroups();
+ saveSettings();
+ }
+ }
+ });
+
new Clipboard('#btnBTCopySettings');
}
+ function LoadCustomGroups(){
+ $('#BeenThereGroupsList').empty();
+ var groups = "";
+ $.each(beenTheresettings.Groups, function(k, v){
+ groups += '
' + k + '
';
+ });
+
+ groups += 'Current group:
';
+
+ $('#BeenThereGroupsList').prepend(groups);
+
+ $('#btCurrGroup')[0].value = beenTheresettings.CurrentGroup;
+
+ $('#btCurrGroup').change(function(){
+ beenTheresettings.CurrentGroup = $(this)[0].value;
+ clearLayer();
+ mapLayers.removeAllFeatures();
+ loadGroup(beenTheresettings.CurrentGroup);
+ saveSettings();
+ });
+
+ $('[id^="BTGroupsClose"]').click(function(){
+ if(getObjectPropertyCount(beenTheresettings.Groups) > 1){
+ delete beenTheresettings.Groups[this.id.replace('BTGroupsClose','')];
+ saveSettings();
+ LoadCustomGroups();
+ }
+ else
+ alert("There must be at least one group");
+ });
+ }
+
function isChecked(checkboxId) {
return $('#' + checkboxId).is(':checked');
}
@@ -622,19 +702,17 @@
$('#' + checkboxId).prop('checked', checked);
}
- function initColorPicker(tries){
- tries = tries || 1;
-
- if ($('#colorPicker1')[0].jscolor && $('#colorPicker2')[0].jscolor) {
- $('#colorPicker1')[0].jscolor.fromString(beenTheresettings.CP1);
- $('#colorPicker2')[0].jscolor.fromString(beenTheresettings.CP2);
- $('#colorPicker3')[0].jscolor.fromString(beenTheresettings.CP3);
- $('#colorPicker4')[0].jscolor.fromString(beenTheresettings.CP4);
+ function initColorPicker(tries = 1){
+ if ($('#btcolorPicker1')[0].jscolor && $('#btcolorPicker2')[0].jscolor) {
+ $('#btcolorPicker1')[0].jscolor.fromString(beenTheresettings.CP1);
+ $('#btcolorPicker2')[0].jscolor.fromString(beenTheresettings.CP2);
+ $('#btcolorPicker3')[0].jscolor.fromString(beenTheresettings.CP3);
+ $('#btcolorPicker4')[0].jscolor.fromString(beenTheresettings.CP4);
$('[id^="colorPicker"]')[0].jscolor.closeText = 'Close';
- $('#colorPicker1')[0].jscolor.onChange = jscolorChanged;
- $('#colorPicker2')[0].jscolor.onChange = jscolorChanged;
- $('#colorPicker3')[0].jscolor.onChange = jscolorChanged;
- $('#colorPicker4')[0].jscolor.onChange = jscolorChanged;
+ $('#btcolorPicker1')[0].jscolor.onChange = jscolorChanged;
+ $('#btcolorPicker2')[0].jscolor.onChange = jscolorChanged;
+ $('#btcolorPicker3')[0].jscolor.onChange = jscolorChanged;
+ $('#btcolorPicker4')[0].jscolor.onChange = jscolorChanged;
} else if (tries < 1000)
@@ -642,15 +720,32 @@
}
function jscolorChanged(){
- beenTheresettings.CP1 = "#" + $('#colorPicker1')[0].jscolor.toString();
- beenTheresettings.CP2 = "#" + $('#colorPicker2')[0].jscolor.toString();
- beenTheresettings.CP3 = "#" + $('#colorPicker3')[0].jscolor.toString();
- beenTheresettings.CP4 = "#" + $('#colorPicker4')[0].jscolor.toString();
+ beenTheresettings.CP1 = "#" + $('#btcolorPicker1')[0].jscolor.toString();
+ beenTheresettings.CP2 = "#" + $('#btcolorPicker2')[0].jscolor.toString();
+ beenTheresettings.CP3 = "#" + $('#btcolorPicker3')[0].jscolor.toString();
+ beenTheresettings.CP4 = "#" + $('#btcolorPicker4')[0].jscolor.toString();
//In case they changed the color of the currently selected color, re-set currColor
currColor = '#' + $('#' + $("input[type='radio'][name='currColor']:checked").val())[0].jscolor.toString();
saveSettings();
}
+ function objectHasProperties(object) {
+ for (var prop in object) {
+ if (object.hasOwnProperty(prop))
+ return true;
+ }
+ return false;
+ }
+
+ function getObjectPropertyCount(object){
+ let count = 0;
+ for (var prop in object) {
+ if (object.hasOwnProperty(prop))
+ count++;
+ }
+ return count;
+ }
+
function LoadSettingsObj() {
var loadedSettings;
try{
@@ -675,19 +770,29 @@
NewUserCircleShortcut: "",
RemoveLastShapeShortcut: "",
RedoLastShapeShortcut: "",
- RemoveAllShapesShortcut: ""
+ RemoveAllShapesShortcut: "",
+ SettingsLocTop: "40%",
+ SettingsLocLeft: "50%",
+ Groups: {"default": []},
+ CurrentGroup: "default"
};
beenTheresettings = loadedSettings ? loadedSettings : defaultSettings;
for (var prop in defaultSettings) {
if (!beenTheresettings.hasOwnProperty(prop))
beenTheresettings[prop] = defaultSettings[prop];
}
- if(parseInt(beenTheresettings.LocLeft.replace('px', '')) < 0)
- beenTheresettings.LocLeft = "6px";
- if(parseInt(beenTheresettings.LocTop.replace('px','')) < 0)
- beenTheresettings.LocTop = "280px";
+ if(parseInt(beenTheresettings.LocLeft.replace('px', '')) < 0)
+ beenTheresettings.LocLeft = "6px";
+ if(parseInt(beenTheresettings.LocTop.replace('px','')) < 0)
+ beenTheresettings.LocTop = "280px";
currColor = beenTheresettings.CP1;
+
+ if(beenTheresettings.layerHistory.length > 0){ //move our old layers into the default group
+ beenTheresettings.Groups.default = [...beenTheresettings.layerHistory];
+ beenTheresettings.layerHistory = [];
+ saveSettings();
+ }
}
function saveSettings() {
@@ -707,9 +812,13 @@
NewUserCircleShortcut: beenTheresettings.NewUserCircleShortcut,
RemoveLastShapeShortcut: beenTheresettings.RemoveLastShapeShortcut,
RedoLastShapeShortcut: beenTheresettings.RedoLastShapeShortcut,
- RemoveAllShapesShortcut: beenTheresettings.RemoveAllShapesShortcut
+ RemoveAllShapesShortcut: beenTheresettings.RemoveAllShapesShortcut,
+ SettingsLocTop: beenTheresettings.SettingsLocTop,
+ SettingsLocLeft: beenTheresettings.SettingsLocLeft,
+ Groups: beenTheresettings.Groups,
+ CurrentGroup: beenTheresettings.CurrentGroup
};
- if(parseInt(localsettings.LocLeft.replace('px', '')) < 0)
+ if(parseInt(localsettings.LocLeft.replace('px', '')) < 0)
localsettings.LocLeft = "6px";
if(parseInt(localsettings.LocTop.replace('px','')) < 0)
localsettings.LocTop = "280px";