let user set context menu for drawings

(pretty ugly but)
This commit is contained in:
Dave Conway-Jones 2023-10-07 14:15:31 +01:00
parent b6bbdb64ef
commit 668e232718
No known key found for this signature in database
GPG Key ID: 1DDB0E91A28C2643
3 changed files with 25 additions and 24 deletions

View File

@ -27,16 +27,6 @@ Feel free to [![](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%
- v2.41.0 - Bump leaflet libs to latest stable (1.9.4) - v2.41.0 - Bump leaflet libs to latest stable (1.9.4)
- v2.40.1 - Fix missing countries overlay when starting disconnected. - v2.40.1 - Fix missing countries overlay when starting disconnected.
- v2.40.0 - Add handling for TAK event points from TAK ingest node. - v2.40.0 - Add handling for TAK event points from TAK ingest node.
- v2.39.0 - Add client timezone to connect message. PR #245
- v2.38.3 - Better fix for geojson multipoint icons.
- v2.38.1 - Fix for geojson multipoint icons.
- v2.38.0 - Return client headers as part of connect message.
- v2.37.4 - Fix sessionid specific data not to be sent on reload/refresh
- v2.37.3 - Fix hang on layer change
- v2.37.2 - If custom layer is only layer then show it automatically. Issue #230
- v2.37.1 - Warn (and drop) messages that are missing a payload. Issue #229
- v2.37.0 - Allow fly instead of fit option when using command to move view window. (PR #225)
- v2.36.0 - Add edge icons for SIDC markers just off the map.
- see [CHANGELOG](https://github.com/dceejay/RedMap/blob/master/CHANGELOG.md) for full list of changes. - see [CHANGELOG](https://github.com/dceejay/RedMap/blob/master/CHANGELOG.md) for full list of changes.

View File

@ -316,7 +316,7 @@ module.exports = function(RED) {
if ((node.events.indexOf("draw")!==-1) && ((message.action === "draw")||(message.action === "drawdelete"))) { if ((node.events.indexOf("draw")!==-1) && ((message.action === "draw")||(message.action === "drawdelete"))) {
setImmediate(function() {node.send({payload:message, topic:node.path.substr(1), _sessionid:client.id, _sessionip:sessionip})}); setImmediate(function() {node.send({payload:message, topic:node.path.substr(1), _sessionid:client.id, _sessionip:sessionip})});
} }
if (node.events.indexOf("other")!==-1 && "connected,point,delete,move,draw,files,bounds".indexOf(message.action) === -1) { if (node.events.indexOf("other")!==-1 && "connected,point,delete,move,draw,drawdelete,files,bounds".indexOf(message.action) === -1) {
setImmediate(function() {node.send({payload:message, topic:node.path.substr(1), _sessionid:client.id, _sessionip:sessionip})}); setImmediate(function() {node.send({payload:message, topic:node.path.substr(1), _sessionid:client.id, _sessionip:sessionip})});
} }
} }

View File

@ -30,6 +30,7 @@ var sidebyside;
var layercontrol; var layercontrol;
var drawCount = 0; var drawCount = 0;
var drawingColour = "#910000"; var drawingColour = "#910000";
var drawcontextmenu = "";
var sendDrawing; var sendDrawing;
var colorControl; var colorControl;
var sendRoute; var sendRoute;
@ -836,6 +837,8 @@ var addThing = function() {
map.addLayer(layers[lay]); map.addLayer(layers[lay]);
} }
var form = {};
var addToForm = function(n,v) { form[n] = v; }
var feedback = function(n,v,a,c) { var feedback = function(n,v,a,c) {
if (v === "$form") { v = form; } if (v === "$form") { v = form; }
if (markers[n]) { if (markers[n]) {
@ -846,6 +849,9 @@ var feedback = function(n,v,a,c) {
if (v !== undefined) { fb.value = v; } if (v !== undefined) { fb.value = v; }
ws.send(JSON.stringify(fb)); ws.send(JSON.stringify(fb));
} }
else if (polygons[n]) {
sendDrawing(n,v,a)
}
else { else {
if (n === undefined) { n = "map"; } if (n === undefined) { n = "map"; }
ws.send(JSON.stringify({action:a||"feedback", name:n, value:v, lat:rclk.lat, lon:rclk.lng})); ws.send(JSON.stringify({action:a||"feedback", name:n, value:v, lat:rclk.lat, lon:rclk.lng}));
@ -853,11 +859,6 @@ var feedback = function(n,v,a,c) {
if (c === true) { map.closePopup(); } if (c === true) { map.closePopup(); }
} }
var form = {};
var addToForm = function(n,v) {
form[n] = v;
}
// map.on('click', function(e) { // map.on('click', function(e) {
// ws.send(JSON.stringify({action:"click", lat:e.latlng.lat.toFixed(5), lon:e.latlng.lng.toFixed(5)})); // ws.send(JSON.stringify({action:"click", lat:e.latlng.lat.toFixed(5), lon:e.latlng.lng.toFixed(5)}));
// }); // });
@ -1113,7 +1114,8 @@ var addOverlays = function(overlist) {
L.DomEvent.stopPropagation(e); L.DomEvent.stopPropagation(e);
var name = e.target.name; var name = e.target.name;
var rmen = L.popup({offset:[0,-12]}).setLatLng(e.latlng); var rmen = L.popup({offset:[0,-12]}).setLatLng(e.latlng);
rmen.setContent("<input type='text' value='"+name+"' id='dinput' placeholder='name (,icon, layer)'/><br/><button onclick='editPoly(\""+name+"\");'>Edit points</button><button onclick='editPoly(\""+name+"\",\"drag\");'>Drag</button><button onclick='editPoly(\""+name+"\",\"rot\");'>Rotate</button><button onclick='delMarker(\""+name+"\",true);'>Delete</button><button onclick='sendDrawing();'>OK</button>"); var d = drawcontextmenu || "<input type='text' value='$name' id='dinput' placeholder='name (,icon, layer)'/><br/><button onclick='editPoly(\"$name\");'>Edit points</button><button onclick='editPoly(\"$name\",\"drag\");'>Drag</button><button onclick='editPoly(\"$name\",\"rot\");'>Rotate</button><button onclick='delMarker(\"$name\",true);'>Delete</button><button onclick='sendDrawing();'>OK</button>";
rmen.setContent(d.replace(/\$name/g,name));
map.openPopup(rmen); map.openPopup(rmen);
}); });
e.layer.bindPopup(name); e.layer.bindPopup(name);
@ -1139,21 +1141,24 @@ var addOverlays = function(overlist) {
polygons[name].name = name; polygons[name].name = name;
layers["_drawing"].addLayer(shape.layer); layers["_drawing"].addLayer(shape.layer);
var rightmenuMarker = L.popup({offset:[0,-12]}).setContent("<input type='text' autofocus value='"+name+"' id='dinput' placeholder='name (,icon, layer)'/><br/><button onclick='editPoly(\""+name+"\");'>Edit points</button><button onclick='editPoly(\""+name+"\",\"drag\");'>Drag</button><button onclick='editPoly(\""+name+"\",\"rot\");'>Rotate</button><button onclick='delMarker(\""+name+"\",true);'>Delete</button><button onclick='sendDrawing(\""+name+"\");'>OK</button>"); var rightmenuMarker = L.popup({offset:[0,-12]}).setContent(drawcontextmenu.replace(/\$name/g,name) || "<input type='text' autofocus value='"+name+"' id='dinput' placeholder='name (,icon, layer)'/><br/><button onclick='editPoly(\""+name+"\");'>Edit points</button><button onclick='editPoly(\""+name+"\",\"drag\");'>Drag</button><button onclick='editPoly(\""+name+"\",\"rot\");'>Rotate</button><button onclick='delMarker(\""+name+"\",true);'>Delete</button><button onclick='sendDrawing(\""+name+"\");'>OK</button>");
if (e.layer.options.fill === false && navigator.onLine) { if (e.layer.options.fill === false && navigator.onLine) {
rightmenuMarker = L.popup({offset:[0,-12]}).setContent("<input type='text' autofocus value='"+name+"' id='dinput' placeholder='name (,icon, layer)'/><br/><button onclick='editPoly(\""+name+"\");'>Edit points</button><button onclick='editPoly(\""+name+"\",\"drag\");'>Drag</button><button onclick='editPoly(\""+name+"\",\"rot\");'>Rotate</button><button onclick='delMarker(\""+name+"\",true);'>Delete</button><button onclick='sendRoute(\""+name+"\");'>Route</button><button onclick='sendDrawing(\""+name+"\");'>OK</button>"); rightmenuMarker = L.popup({offset:[0,-12]}).setContent(drawcontextmenu.replace(/\$name/g,name) || "<input type='text' autofocus value='"+name+"' id='dinput' placeholder='name (,icon, layer)'/><br/><button onclick='editPoly(\""+name+"\");'>Edit points</button><button onclick='editPoly(\""+name+"\",\"drag\");'>Drag</button><button onclick='editPoly(\""+name+"\",\"rot\");'>Rotate</button><button onclick='delMarker(\""+name+"\",true);'>Delete</button><button onclick='sendRoute(\""+name+"\");'>Route</button><button onclick='sendDrawing(\""+name+"\");'>OK</button>");
} }
rightmenuMarker.setLatLng(cent); rightmenuMarker.setLatLng(cent);
setTimeout(function() {map.openPopup(rightmenuMarker)},25); setTimeout(function() {map.openPopup(rightmenuMarker)},25);
}); });
sendDrawing = function(n) { sendDrawing = function(n,v,a) {
var thing = document.getElementById('dinput').value; var thing = document.getElementById('dinput')?.value || n;
map.closePopup(); map.closePopup();
shape.m.name = thing; shape.m.name = thing;
shape.layer.bindPopup(thing); shape.layer.bindPopup(thing);
delMarker(n,true); delMarker(n,true);
if (v) {
shape.layer.form = v;
shape.m.form = v;
}
polygons[thing] = shape.layer; polygons[thing] = shape.layer;
polygons[thing].lay = "_drawing"; polygons[thing].lay = "_drawing";
polygons[thing].name = thing; polygons[thing].name = thing;
@ -1405,8 +1410,8 @@ var delMarker = function(dname,note) {
} }
delete allData[dname]; delete allData[dname];
if (note) { if (note) {
if (pol === false) { ws.send(JSON.stringify({action:"delete", name:dname, deleted:true})); } if (pol === true) { ws.send(JSON.stringify({action:"drawdelete", name:dname, deleted:true})); }
else { ws.send(JSON.stringify({action:"drawdelete", name:dname, deleted:true}))} else { ws.send(JSON.stringify({action:"delete", name:dname, deleted:true})); }
} }
} }
@ -1426,6 +1431,7 @@ var editPoly = function(pname,fun) {
lo = e.target._latlng.lng; lo = e.target._latlng.lng;
} }
var m = {action:"draw", name:pname, layer:polygons[pname].lay, options:e.target.options, radius:e.target._mRadius, lat:la, lon:lo}; var m = {action:"draw", name:pname, layer:polygons[pname].lay, options:e.target.options, radius:e.target._mRadius, lat:la, lon:lo};
if (e.target.form) { m.form = e.target.form; }
if (e.target.hasOwnProperty("_latlngs")) { if (e.target.hasOwnProperty("_latlngs")) {
if (e.target.options.fill === false) { m.line = e.target._latlngs; } if (e.target.options.fill === false) { m.line = e.target._latlngs; }
else { m.area = e.target._latlngs[0]; } else { m.area = e.target._latlngs[0]; }
@ -2385,6 +2391,11 @@ function doCommand(cmd) {
rightmenuMap.setContent(addmenu); rightmenuMap.setContent(addmenu);
} }
} }
if (cmd.hasOwnProperty("drawcontextmenu")) {
if (typeof cmd.drawcontextmenu === "string") {
drawcontextmenu = cmd.drawcontextmenu;
}
}
if (cmd.hasOwnProperty("allowFileDrop")) { if (cmd.hasOwnProperty("allowFileDrop")) {
if (typeof cmd.allowFileDrop === "string") { if (typeof cmd.allowFileDrop === "string") {
allowFileDrop = cmd.allowFileDrop === "false" ? false : true; allowFileDrop = cmd.allowFileDrop === "false" ? false : true;