Skip to content

Commit

Permalink
t push origin master<Down>Merge branch 'hardillb-master'
Browse files Browse the repository at this point in the history
Fixup merge changes with Real Master
  • Loading branch information
Dave Conway-Jones committed Jun 9, 2022
2 parents 7deff2a + 5fafdfa commit 734a2ba
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 9 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,7 @@ These are arround the "add 'inarea'" mode
into a WorldMap node so that it will be drawn on the geofence layer.

This output is triggered by a message with `msg.payload.action` set to `send`. This can be
initiated by using the WorldMap in node when a new browser connects.
initiated by using the WorldMap in node when a new browser connects.

Messages with `msg.payload.action` set to `send`will not be processed against the geofence,
these messages are only intended to come from the WorldMap in node.
64 changes: 62 additions & 2 deletions geofence.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ <h2>WorldMap</h2>
var osmLayer = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 20,
attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors'

}).addTo(map);
basemaps["OSM"] = osmLayer;
var Esri_WorldImagery = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
Expand All @@ -120,6 +121,55 @@ <h2>WorldMap</h2>
basemaps["Satellite"] = Esri_WorldImagery;
layercontrol = L.control.layers(basemaps,null).addTo(map);

//extend Leaflet to create a GeoJSON layer from a TopoJSON file
L.TopoJSON = L.GeoJSON.extend({
addData: function (data) {
var geojson, key;
if (data.type === "Topology") {
for (key in data.objects) {
if (data.objects.hasOwnProperty(key)) {
geojson = topojson.feature(data, data.objects[key]);
L.GeoJSON.prototype.addData.call(this, geojson);
}
}
return this;
}
L.GeoJSON.prototype.addData.call(this, data);
return this;
}
});
L.topoJson = function (data, options) {
return new L.TopoJSON(data, options);
};
//create an empty geojson layer
//with a style and a popup on click
var geojson = L.topoJson(null, {
style: function(feature) {
return {
color: "#8080c0",
opacity: 1,
weight: 2,
fill: "#888",
fillOpacity: 0
}
}
}).addTo(map);

async function getGeoData(url) {
let response = await fetch(url);
let data = await response.json();
return data;
}

var loadedCountries = false;
//fetch the geojson and add it to our geojson layer if osm tiles fail to load
osmLayer.on("tileerror", function (error, tile) {
if (!loadedCountries) {
getGeoData('geofence/js/world-50m-flat.json').then(data => geojson.addData(data));
loadedCountries = true;
}
});

var drawnItems = new L.FeatureGroup();
map.addLayer(drawnItems);

Expand Down Expand Up @@ -229,8 +279,15 @@ <h2>WorldMap</h2>
.done(function(data, textStatus, jqxhr){
$.getScript('geofence/js/L.GeoSearch/src/js/l.geosearch.provider.openstreetmap.js')
.done(function(data, textStatus, jqxhr) {
setupMap(n);

$.getScript('geofence/js/topojson.v1.min.js')
.done(function(data, textStatus, jqxhr) {
setupMap(n);
})
.fail(function(jqxhr, settings, exception ){
console.log("failed5");
console.log(exception);
console.log(exception.stack);
});
})
.fail(function(jqxhr, settings, exception ){
console.log("failed4");
Expand Down Expand Up @@ -277,6 +334,9 @@ <h2>WorldMap</h2>
n.rad = 0;
n.centre = {};
for (x in layer._latlngs) {
if (layer._latlngs[x].lng < -180) {
layer._latlngs[x].lng += 360
}
n.points.push({latitude: layer._latlngs[x].lat, longitude: layer._latlngs[x].lng});
}
}
Expand Down
6 changes: 6 additions & 0 deletions geofence.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ module.exports = function(RED) {
this.worldmap = n.worldmap;
var node = this;

node.points.forEach(point => {
if (point.longitude < -180) {
point.longitude += 360;
}
})

node.on('input', function(msg, send, done) {
var loc = undefined;
send = send || function() { node.send.apply(node,arguments) }
Expand Down
16 changes: 10 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
"name": "node-red-node-geofence",
"version": "0.3.4",
"description": "A simple node to filter based on location",
"dependencies" :{
"geolib": "^2.0.23"
"dependencies": {
"geolib": "^2.0.24"
},
"repository" : {
"type":"git",
"url":"https://github.com/hardillb/node-red-node-geofence.git"
"repository": {
"type": "git",
"url": "https://github.com/hardillb/node-red-node-geofence.git"
},
"license": "Apache-2.0",
"keywords": [ "node-red", "geofence", "location" ],
"keywords": [
"node-red",
"geofence",
"location"
],
"node-red": {
"nodes": {
"geofence": "geofence.js"
Expand Down
2 changes: 2 additions & 0 deletions static/topojson.v1.min.js

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

1 change: 1 addition & 0 deletions static/world-50m-flat.json

Large diffs are not rendered by default.

0 comments on commit 734a2ba

Please sign in to comment.