Skip to content

Commit

Permalink
Allow generic overrides for geojson
Browse files Browse the repository at this point in the history
using .icon and .layer
  • Loading branch information
dceejay committed Apr 2, 2024
1 parent d1def61 commit 246f209
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,5 +1,6 @@
### Change Log for Node-RED Worldmap

- v4.6.5 - Let geojson allow for generic overrides with .icon and .layer.
- v4.6.4 - Fix deletion of layers logic to actually fully remove points.
- v4.6.3 - Fix sending of layer events when not wanted. Issue #262
- v4.6.2 - Fix multiple use of contextmenu feedback. Issue #259
Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -13,6 +13,7 @@ Feel free to [![](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%

### Updates

- v4.6.5 - Let geojson allow for generic overrides with .icon and .layer.
- v4.6.4 - Fix deletion of layers logic to actually fully remove points.
- v4.6.3 - Fix sending of layer events when not wanted. Issue #262
- v4.6.2 - Fix multiple use of contextmenu feedback. Issue #259
Expand Down
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
@@ -1,12 +1,12 @@
{
"name": "node-red-contrib-web-worldmap",
"version": "4.6.4",
"version": "4.6.5",
"description": "A Node-RED node to provide a web page of a world map for plotting things on.",
"dependencies": {
"@turf/bezier-spline": "~6.5.0",
"cgi": "0.3.1",
"compression": "^1.7.4",
"express": "^4.18.2",
"express": "^4.19.2",
"sockjs": "~0.3.24"
},
"bundledDependencies": [
Expand Down
6 changes: 3 additions & 3 deletions worldmap.js
Expand Up @@ -129,7 +129,7 @@ module.exports = function(RED) {
if (node.name) { c.toptitle = node.name; }
//console.log("INIT",c)
client.write(JSON.stringify({command:c}));
for (var p=0; p<pmtiles.length; p++) {
for (var p=0; p < pmtiles.length; p++) {
fs.symlink(RED.settings.userDir+'/'+pmtiles[p], __dirname+'/worldmap/'+pmtiles[p], 'file', (err) => {
if (err) {
if (err.code !== "EEXIST") { console.log(err); }
Expand Down Expand Up @@ -200,7 +200,6 @@ module.exports = function(RED) {
if (msg.payload.ttl && msg.payload.ttl < t) { t = msg.payload.ttl; }
allPoints[msg.payload.name].tout = setTimeout( function() { delete allPoints[msg.payload.name] }, t * 1000 );
}

if (msg?.payload?.command?.map?.delete) {
var ddd = msg.payload.command.map.delete;
if (!Array.isArray(ddd)) { ddd = [cmd.map.delete]; }
Expand All @@ -214,8 +213,8 @@ module.exports = function(RED) {
}
}
}

});

node.on("close", function() {
for (var c in clients) {
if (clients.hasOwnProperty(c)) {
Expand All @@ -232,6 +231,7 @@ module.exports = function(RED) {
}
node.status({});
});

sockets[node.path].on('connection', callback);
}
var WorldMap = function(n) {
Expand Down
13 changes: 7 additions & 6 deletions worldmap/worldmap.js
Expand Up @@ -150,10 +150,10 @@ var handleData = function(data) {

// handle raw geojson type msg
if (data.hasOwnProperty("type") && data.type.indexOf("Feature") === 0) {
if (data.hasOwnProperty('properties') && data.properties.hasOwnProperty('title')) {
doGeojson(data.properties.title,data)
if (data?.properties?.title) {
doGeojson(data.properties.title,data,data?.layer,data?.options,data?.icon) // name, geojson, layer, options, icon
}
else { doGeojson("geojson",data); }
else { doGeojson("geojson",data,data?.layer,data?.options,data?.icon); }
}
// handle TAK json (from tak-ingest node or fastxml node)
else if (data.hasOwnProperty("event") && data.event.hasOwnProperty("point")) {
Expand Down Expand Up @@ -3084,7 +3084,7 @@ function doCommand(cmd) {
}

// handle any incoming GEOJSON directly - may style badly
function doGeojson(n,g,l,o) { // name, geojson, layer, options
function doGeojson(n,g,l,o,i) { // name, geojson, layer, options, icon
var lay = l ?? g.name ?? "unknown";
// if (!basemaps[lay]) {
var opt = { style: function(feature) {
Expand Down Expand Up @@ -3132,13 +3132,14 @@ function doGeojson(n,g,l,o) { // name, geojson, layer, options
additionalInformation:feature.properties.modifier,
size:25
});
var anc = myMarker.getAnchor();
if (myMarker.hasOwnProperty("metadata") && myMarker.metadata.hasOwnProperty("echelon")) {
var sz = iconSz[myMarker.metadata.echelon];
myMarker.setOptions({size:sz});
}
myMarker = L.icon({
iconUrl: myMarker.toDataURL(),
iconAnchor: [myMarker.getAnchor().x, myMarker.getAnchor().y],
iconAnchor: [anc.x, anc.y],
className: "natoicon",
});
}
Expand All @@ -3156,7 +3157,7 @@ function doGeojson(n,g,l,o) { // name, geojson, layer, options
}
else {
myMarker = L.VectorMarkers.icon({
icon: feature.properties["marker-symbol"] ?? "circle",
icon: feature.properties["marker-symbol"] ?? i ?? "circle",
markerColor: (feature.properties["marker-color"] ?? "#910000"),
prefix: 'fa',
iconColor: 'white'
Expand Down

0 comments on commit 246f209

Please sign in to comment.