diff --git a/worldmap/worldmap.js b/worldmap/worldmap.js
index c11151f..5d58e74 100644
--- a/worldmap/worldmap.js
+++ b/worldmap/worldmap.js
@@ -410,8 +410,9 @@ else {
// Create the clear heatmap button
var clrHeat = L.easyButton( 'fa-eraser', function() {
- console.log("Reset heatmap");
- if (heat) { heat.setLatLngs([]); }
+
+// console.log("Reset heatmap");
+ if (heat) {heat.setLatLngs([]);}
}, "Clears the current heatmap", {position:"bottomright"});
}
@@ -541,7 +542,7 @@ function doLock(v) {
// Remove old markers
function doTidyUp(l) {
if (l === "heatmap") {
- if (heat) { heat.setLatLngs([]); }
+ if (heat) {heat.setLatLngs([]);}
}
else {
var d = parseInt(Date.now()/1000);
@@ -938,11 +939,6 @@ map.on('moveend', function() {
map.on('locationfound', onLocationFound);
map.on('locationerror', onLocationError);
-// single right click to add a marker
-var addmenu = "Add marker
";
-addmenu += '
MilSymbol SIDC generator';
-var rightmenuMap = L.popup({keepInView:true, minWidth:260}).setContent(addmenu);
-
const rgba2hex = (rgba) => `#${rgba.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+\.{0,1}\d*))?\)$/).slice(1).map((n, i) => (i === 3 ? Math.round(parseFloat(n) * 255) : parseFloat(n)).toString(16).padStart(2, '0').replace('NaN', '')).join('')}`;
const colorKeywordToRGB = (colorKeyword) => {
let el = document.createElement('div');
@@ -953,8 +949,22 @@ const colorKeywordToRGB = (colorKeyword) => {
return rgba2hex(rgbValue);
}
-var rclk = {};
-var hiderightclick = false;
+// ********************
+// ** Right Click **
+// ********************
+var rclk = {}; // right-click object, to store lat + lon
+var hiderightclick = false; // this is disabling Marker's right-click context menu too!
+let disableaddmarker = false; // only disable the "Add Marker" context menu on the map
+
+// single right click to add a marker (if not disabled by "disableAddMarker")
+let addmenu = "";
+let rightmenuMap = null;
+
+addmenu = "Add marker
";
+addmenu += '
MilSymbol SIDC generator';
+rightmenuMap = L.popup({keepInView:true, minWidth:260}).setContent(addmenu);
+
var addThing = function() {
var thing = document.getElementById('rinput').value;
map.closePopup();
@@ -996,6 +1006,7 @@ var feedback = function(n = "map",v,a = "feedback",c) {
dataToSend.lon = rclk.lng;
}
ws.send(JSON.stringify(dataToSend));
+
if (c === true) { map.closePopup(); }
}
@@ -1003,16 +1014,10 @@ map.on('click', function(e) {
ws.send(JSON.stringify({action:"click", lat:e.latlng.lat.toFixed(5), lon:e.latlng.lng.toFixed(5)}));
});
-map.on('popupopen', function(e) {
- const mp = e.popup._source;
- ws.send(JSON.stringify({action:"openPopup",name:mp.name,layer:mp.lay,icon:mp.icon,iconColor:mp.iconColor,SIDC:mp.SIDC,draggable:true,lat:parseFloat(mp.getLatLng().lat.toFixed(6)),lon:parseFloat(mp.getLatLng().lng.toFixed(6))}));
-});
-
// allow double right click to zoom out (if enabled)
// single right click opens a message window that adds a marker
-var rclicked = false;
-var rtout = null;
-
+var rclicked = false; // to stop timeout
+var rtout = null; // timeout object itself
map.on('contextmenu', function(e) {
if (rclicked) {
@@ -1023,27 +1028,26 @@ map.on('contextmenu', function(e) {
}
}
else {
+ if ((hiderightclick === true) || (addmenu.length === 0) || (disableaddmarker === true)) { return null }
rclicked = true;
rtout = setTimeout( function() {
rclicked = false;
- if ((hiderightclick !== true) && (addmenu.length > 0)) {
- rclk = e.latlng;
- form = {};
- var ramen = ""+addmenu;
- if (typeof rmenudata !== "string") {
- for (const item in rmenudata) {
- ramen = ramen.replace(new RegExp("\\${"+item+"}","g"),rmenudata[item]);
- }
- }
- ramen = ramen.replace(/\${.*?}/g,'')
- rightmenuMap.setContent(ramen);
- rightmenuMap.setLatLng(e.latlng);
- map.openPopup(rightmenuMap);
- setTimeout( function() {
- try { document.getElementById('rinput').focus(); }
- catch(e) {}
- }, 200);
- }
+ rclk = e.latlng;
+ form = {};
+ var ramen = ""+addmenu;
+ if (typeof rmenudata !== "string") {
+ for (const item in rmenudata) {
+ ramen = ramen.replace(new RegExp("\\${"+item+"}","g"),rmenudata[item]);
+ }
+ }
+ ramen = ramen.replace(/\${.*?}/g,'')
+ rightmenuMap.setContent(ramen);
+ rightmenuMap.setLatLng(e.latlng);
+ map.openPopup(rightmenuMap);
+ setTimeout( function() {
+ try { document.getElementById('rinput').focus(); }
+ catch(e) {}
+ }, 200);
}, 300);
}
});
@@ -1260,7 +1264,7 @@ var addOverlays = function(overlist) {
}
var shape;
- map.on('pm:create', (e) => {
+ map.on("pm:create", (e) => {
drawCount = drawCount + 1;
var name = e.shape + drawCount;
@@ -1694,7 +1698,7 @@ function setMarker(data) {
opt.weight = opt.weight ?? data.weight ?? 2;
opt.opacity = opt.opacity ?? data.opacity ?? 1;
if (!data.SIDC) { opt.fillOpacity = opt.fillOpacity ?? data.fillOpacity ?? 0.2; }
- opt.clickable = (data.hasOwnProperty("clickable")) ? data.clickable : false;
+ opt.clickable = (data.clickable !== false);
opt.fill = opt.fill ?? (data.hasOwnProperty("fill")) ? data.fill : true;
if (data.hasOwnProperty("dashArray")) { opt.dashArray = data.dashArray; }
@@ -2278,8 +2282,10 @@ function setMarker(data) {
oldll = {lat:ola, lon:olo};
});
marker.on('dragend', function (e) {
- var l = marker.getLatLng().toString().replace('LatLng(','lat, lon : ').replace(')','')
- marker.setPopupContent(marker.getPopup().getContent().split("lat, lon")[0] + l);
+ // *** set up Popup Content ***
+ let l = marker.getLatLng().toString().replace('LatLng(','lat, lon : ').replace(')','')
+ let pp = marker.getPopup();
+ if (pp) {marker.setPopupContent(pp.getContent().split("lat, lon")[0] + l); } // skip, if pp is undefined
// var b = marker.getPopup().getContent().split("heading : ");
// if (b.length === 2) { b = parseFloat(b[1].split("
=0 || words.indexOf('=0 ) { wopt.maxWidth="640"; } // make popup wider if it has an image or video
if (data?.popupOptions) { // allow user to override popup options eg to add className
@@ -2442,7 +2444,7 @@ function setMarker(data) {
else {
words += '
| '+ i +' | ' + JSON.stringify(data[i]) + ' |