Skip to content

Commit

Permalink
var
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-blackson committed Jan 29, 2024
1 parent 0b26483 commit 2fec8a3
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 3 deletions.
28 changes: 27 additions & 1 deletion admin/index_m.html
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,35 @@
return arr; // returns array
}

function loadSetup() {
function loadSetup() {
//var newValue = JSON.stringify(getSettings());
console.log('Testfunction')
var longSetup = ''
var latSetup = ''
socket.emit('getObject', 'system.config', function (err, obj) {
latSetup = parseFloat(obj.common.latitude)
longSetup = parseFloat(obj.common.longitude)
console.log(' Long Setup: ' + longSetup)
console.log(' Lat Setup: ' + latSetup)
$("#lat").val(latSetup);
$("#long").val(longSetup);

})
/*
let obj = getForeignObjectAsync('system.config');
if (!obj) {
console.log.error('Adapter was not able to read iobroker configuration');
this.terminate ? this.terminate(utils.EXIT_CODES.INVALID_CONFIG_OBJECT) : process.exit(0);
return;
}
this.latitude = parseFloat(obj.common.latitude);
this.longitude = parseFloat(obj.common.longitude);
if (!this.latitude || !this.longitude) {
this.log.error('Latitude or Longitude not set in main configuration!');
this.terminate ? this.terminate(utils.EXIT_CODES.INVALID_CONFIG_OBJECT) : process.exit(0);
return;
}
*/
}


Expand Down
68 changes: 67 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const utils = require('@iobroker/adapter-core');
//const request = require('request');
const moment = require('moment');
const util = require('util')
const turf = require('@turf/boolean-point-in-polygon')
const turf = require('@turf/turf')
var parseString = require('xml2js').parseString;
var parseStringPromise = require('xml2js').parseStringPromise;
const stateAttr = require('./lib/stateAttr.js'); // State attribute definitions
Expand Down Expand Up @@ -244,6 +244,33 @@ async function getData(){
latConfig = adapter.config.lat
longConfig = adapter.config.long

//TEMP
var poly = [
[
9.499034790710823,
47.609799475661305
],
[
9.499034790710823,
47.31622193879272
],
[
10.060589182917425,
47.31622193879272
],
[
10.060589182917425,
47.609799475661305
],
[
9.499034790710823,
47.609799475661305
]
]

adapter.log.debug('Before check poly')
checkIfInPoly(poly)

//adapter.log.debug('Longitute : ' + longConfig)

if (regionConfig == "0"|| !regionConfig){
Expand Down Expand Up @@ -684,6 +711,45 @@ function checkDuplicates(){
//adapter.log.debug('9.3.1 alarmAll sorted by sent1 date:' + JSON.stringify(alarmAll.sort((a, b) => a.Alarm_Sent - b.Alarm_Sent)))
}

function checkIfInPoly(polyData){
var myLoc = {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [longConfig, latConfig]
}
};

var poly = {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
polyData
]
}
};

adapter.log.debug('Coordinates1: ' + [longConfig, latConfig])
adapter.log.debug('Coordinates2: ' + [polyData])



adapter.log.debug('MyLoc: ' + myLoc)
adapter.log.debug('poly: ' + polyData)

//=features

var isInside = turf.booleanPointInPolygon(myLoc, poly);

//=isInside1
adapter.log.debug(isInside)
return isInside


}

function checkRelevante(entry){
var i = 0
var now = new Date();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"csv-parse": "4.16.3",
"moment": "2.30.1",
"xml2js": "^0.5.0",
"@turf/boolean-point-in-polygon": "^6.5.0"
"@turf/turf": "^6.5.0"
},
"scripts": {
"test": "npm run test:package && npm run test:unit",
Expand Down

0 comments on commit 2fec8a3

Please sign in to comment.