From 2fec8a3eebbbddb03c63045149ae3208dde79043 Mon Sep 17 00:00:00 2001 From: Alex <jack-blackson@users.noreply.github.com> Date: Mon, 29 Jan 2024 21:28:15 +0100 Subject: [PATCH] var --- admin/index_m.html | 28 ++++++++++++++++++- main.js | 68 +++++++++++++++++++++++++++++++++++++++++++++- package.json | 2 +- 3 files changed, 95 insertions(+), 3 deletions(-) diff --git a/admin/index_m.html b/admin/index_m.html index 2e3c003..00172b6 100755 --- a/admin/index_m.html +++ b/admin/index_m.html @@ -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; + } + */ } diff --git a/main.js b/main.js index 77edb33..12b3d09 100755 --- a/main.js +++ b/main.js @@ -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 @@ -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){ @@ -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(); diff --git a/package.json b/package.json index 595268e..262d6fe 100644 --- a/package.json +++ b/package.json @@ -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",