add simpler geojson support
This commit is contained in:
parent
2e500c39d8
commit
e29f06f1e8
@ -1,5 +1,6 @@
|
|||||||
### Change Log for Node-RED Worldmap
|
### Change Log for Node-RED Worldmap
|
||||||
|
|
||||||
|
- v2.3.2 - Add better geojson support - name plus geojson properties
|
||||||
- v2.3.1 - Stop adding point when you add a circle
|
- v2.3.1 - Stop adding point when you add a circle
|
||||||
- v2.3.0 - Add colour options for drawing layer
|
- v2.3.0 - Add colour options for drawing layer
|
||||||
- v2.2.1 - Better implementation of legend create/show/hide
|
- v2.2.1 - Better implementation of legend create/show/hide
|
||||||
|
@ -208,6 +208,12 @@ a number of degrees.
|
|||||||
msg.payload = { "name":"Bristol Channel", "lat":51.5, "lon":-2.9, "radius":[30000,70000], "tilt":45 };
|
msg.payload = { "name":"Bristol Channel", "lat":51.5, "lon":-2.9, "radius":[30000,70000], "tilt":45 };
|
||||||
|
|
||||||
|
|
||||||
|
### GeoJSON
|
||||||
|
|
||||||
|
If the msg.payload contains a **geojson** property, and no **lat** and **lon**, then rather than draw a point
|
||||||
|
it will render the geojson. Other optional properties (see below) can be used to style the geojson.
|
||||||
|
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
Areas, Rectangles, Lines, Circles and Ellipses can also specify more optional properties:
|
Areas, Rectangles, Lines, Circles and Ellipses can also specify more optional properties:
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "node-red-contrib-web-worldmap",
|
"name": "node-red-contrib-web-worldmap",
|
||||||
"version": "2.3.1",
|
"version": "2.3.2",
|
||||||
"description": "A Node-RED node to provide a web page of a world map for plotting things on.",
|
"description": "A Node-RED node to provide a web page of a world map for plotting things on.",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cgi": "0.3.1",
|
"cgi": "0.3.1",
|
||||||
|
@ -292,15 +292,15 @@ function doTidyUp(l) {
|
|||||||
if ((l && (l == markers[m].lay)) || typeof markers[m].ts != "undefined") {
|
if ((l && (l == markers[m].lay)) || typeof markers[m].ts != "undefined") {
|
||||||
if ((l && (l == markers[m].lay)) || (markers[m].hasOwnProperty("ts") && (Number(markers[m].ts) < d) && (markers[m].lay !== "_drawing"))) {
|
if ((l && (l == markers[m].lay)) || (markers[m].hasOwnProperty("ts") && (Number(markers[m].ts) < d) && (markers[m].lay !== "_drawing"))) {
|
||||||
//console.log("STALE :",m);
|
//console.log("STALE :",m);
|
||||||
layers[markers[m].lay].removeLayer(markers[m]);
|
|
||||||
if (typeof polygons[m] != "undefined") {
|
|
||||||
layers[markers[m].lay].removeLayer(polygons[m]);
|
|
||||||
delete polygons[m];
|
|
||||||
}
|
|
||||||
if (typeof polygons[m+"_"] != "undefined") {
|
if (typeof polygons[m+"_"] != "undefined") {
|
||||||
layers[polygons[m+"_"].lay].removeLayer(polygons[m+"_"]);
|
layers[polygons[m+"_"].lay].removeLayer(polygons[m+"_"]);
|
||||||
delete polygons[m+"_"];
|
delete polygons[m+"_"];
|
||||||
}
|
}
|
||||||
|
if (typeof polygons[m] != "undefined") {
|
||||||
|
layers[markers[m].lay].removeLayer(polygons[m]);
|
||||||
|
delete polygons[m];
|
||||||
|
}
|
||||||
|
layers[markers[m].lay].removeLayer(markers[m]);
|
||||||
delete markers[m];
|
delete markers[m];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1104,6 +1104,9 @@ function setMarker(data) {
|
|||||||
polygons[data.name] = rangerings(new L.LatLng((data.lat*1), (data.lon*1)), data.arc);
|
polygons[data.name] = rangerings(new L.LatLng((data.lat*1), (data.lon*1)), data.arc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (data.hasOwnProperty("geojson")) {
|
||||||
|
doGeojson(data.geojson,(data.layer || "geojson"),opt);
|
||||||
|
}
|
||||||
|
|
||||||
if (polygons[data.name] !== undefined) {
|
if (polygons[data.name] !== undefined) {
|
||||||
polygons[data.name].lay = lay;
|
polygons[data.name].lay = lay;
|
||||||
@ -2021,14 +2024,18 @@ function doCommand(cmd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// handle any incoming GEOJSON directly - may style badly
|
// handle any incoming GEOJSON directly - may style badly
|
||||||
function doGeojson(g) {
|
function doGeojson(g,l,o) {
|
||||||
console.log("GEOJSON",g);
|
var glayer = l || "geojson";
|
||||||
if (!basemaps["geojson"]) {
|
if (!basemaps[glayer]) {
|
||||||
var opt = { style: function(feature) {
|
var opt = { style: function(feature) {
|
||||||
var st = { stroke:true, color:"#910000", weight:2, fill:true, fillColor:"#910000", fillOpacity:0.3 };
|
var st = { stroke:true, color:"#910000", weight:2, fill:true, fillColor:"#910000", fillOpacity:0.3 };
|
||||||
|
st = Object.assign(st,o);
|
||||||
if (feature.hasOwnProperty("properties")) {
|
if (feature.hasOwnProperty("properties")) {
|
||||||
console.log("GPROPS", feature.properties)
|
console.log("GPROPS", feature.properties)
|
||||||
}
|
}
|
||||||
|
if (feature.hasOwnProperty("geometry") && feature.geometry.hasOwnProperty("type") && feature.geometry.type === "LineString") {
|
||||||
|
st.fill = false;
|
||||||
|
}
|
||||||
if (feature.hasOwnProperty("style")) {
|
if (feature.hasOwnProperty("style")) {
|
||||||
console.log("GSTYLE", feature.style)
|
console.log("GSTYLE", feature.style)
|
||||||
}
|
}
|
||||||
@ -2037,10 +2044,11 @@ function doGeojson(g) {
|
|||||||
opt.onEachFeature = function (f,l) {
|
opt.onEachFeature = function (f,l) {
|
||||||
if (f.properties) { l.bindPopup('<pre>'+JSON.stringify(f.properties,null,' ').replace(/[\{\}"]/g,'')+'</pre>'); }
|
if (f.properties) { l.bindPopup('<pre>'+JSON.stringify(f.properties,null,' ').replace(/[\{\}"]/g,'')+'</pre>'); }
|
||||||
}
|
}
|
||||||
overlays["geojson"] = L.geoJson(g,opt);
|
overlays[glayer] = L.geoJson(g,opt);
|
||||||
layercontrol.addOverlay(overlays["geojson"],"geojson");
|
//layercontrol.addOverlay(overlays[glayer],glayer);
|
||||||
|
map.addLayer(overlays[glayer]);
|
||||||
}
|
}
|
||||||
overlays["geojson"].addData(g);
|
overlays[glayer].addData(g);
|
||||||
}
|
}
|
||||||
|
|
||||||
connect();
|
connect();
|
||||||
|
Loading…
Reference in New Issue
Block a user