phulst / node-tile38 Goto Github PK
View Code? Open in Web Editor NEWNode driver for Tile38
Node driver for Tile38
Hi,
Firstly thank you for the great work on this node driver. Are there any plans to add handling for the newly announced expansion of FIELDS from float numbers to strings, booleans and JSON?
https://tile38.com/topics/filter-expressions
Currently, if you attempt to set any field that is not a float using this node client, it is simply dropped.
Result:
127.0.0.1:9851> scan users
{"ok":true,"fields":["acc","alt","bat","spd","ts"],"objects":["id":"V1StGXR8_Z5jdHi6B-myU","object":{"type":"Point","coordinates":[-0.116926,51.508663]},"fields":[5,432,0.759999,14.1,1667937547000]}],"count":1,"cursor":0,"elapsed":"63.668µs"}
It seems that the library does not support WHEREIN search option which is available for NEARBY, WITHIN, INTERSECTS, and SCAN commands.
it would be great if this module just took the constructor args and passed them straight through, so we could use URLs instead of host/port. this makes it much easier to provide this info via env vars.
When I
console.log(Object.getOwnPropertyNames(this.userResultsFence));
I get
[ 'debug', 'socket' ]
Note: there is no close method present.
Thus when I call close on the fence, nothing happens.
However, if I instead call
this.userResultsFence.socket.destroy();
This successfully closes the handle. I see this in node because I am exporting the nodejs_active_handles prometheus metric and only this reduces the handle count on close.
Hi @phulst thanks for your great job! We think we have hit a problem with your latest release (0.9.0)
0.9.0 claims to solve problems with executeCommand, but once installed (with npm) we cannot see any reference to executeCommand in tile38.js. But in your repo ( branch 0.9.0), clearly exists ( tile 38.js line 51). After scraching our heads and taking a look to the npmjs repo, we have compared your github release 0.8.0 with 0.9.0 and both seems to have the same code.
May be you created release 0.9.0 with the 0.8.0 branch or code?
Can you recreate it with the latest changes or create a new release 0.9.1 ?
Thanks!
TIA
I found a few methods that are not available on version 0.9.0 when installed from npm, like timeout
and executeCommand
. Can we please update the code on npm?
Hi, I'm using the below example. It triggered only enter event not getting the exit event but the exit point also present.
let query = client.intersectsQuery('fleet').detect('enter','exit').circle(43.686, -114.367, 100)
// start the live geofence
let fence = query.executeFence((err, results) => {
// this callback will be called multiple times
if (err) {
console.log("error: " + err);
} else {
console.dir(results);
}
});
// set a coordinate
client.set('fleet', 'truck1', [43.6855, -114.36803]); // Detect as enter
client.set('fleet', 'truck2', [43.68579, -114.367]); // Detect as enter
client.set('fleet', 'truck3', [43.68507, -114.36746]); // Not detected
client.set('fleet', 'truck4', [43.68192, -114.36595]); // Not detected
tried the above example. Please suggest me
The ping command sent using client.ping()
never returns if the server is down.
Is there a way by which we can know that the server is down?
It does return the correct pong
response when the server is up though.
Downloaded, and ran the test cases. It is passing all, except for one, as shown below. This is against the latest tile38 server running.
key commands
bounds
Unhandled rejection TypeError: Cannot read property 'lat' of undefined
at tile38.bounds.then (C:\Users\user\Desktop\node-tile38\test\test_keys_commands.js:24:27)
at tryCatcher (C:\Users\user\Desktop\node-tile38\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (C:\Users\user\Desktop\node-tile38\node_modules\bluebird\js\release\promise.js:512:31)
at Promise._settlePromise (C:\Users\user\Desktop\node-tile38\node_modules\bluebird\js\release\promise.js:569:18)
at Promise._settlePromise0 (C:\Users\user\Desktop\node-tile38\node_modules\bluebird\js\release\promise.js:614:10)
at Promise._settlePromises (C:\Users\user\Desktop\node-tile38\node_modules\bluebird\js\release\promise.js:693:18)
at Async._drainQueue (C:\Users\user\Desktop\node-tile38\node_modules\bluebird\js\release\async.js:133:16)
at Async._drainQueues (C:\Users\user\Desktop\node-tile38\node_modules\bluebird\js\release\async.js:143:10)
at Immediate.Async.drainQueues [as _onImmediate] (C:\Users\user\Desktop\node-tile38\node_modules\bluebird\js\release\async.js:17:14)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
1) should return bounds for a key
Hi
I wanted get to notify live, if the point is entered or exited from the given radius or polygon, so I've tried the following code: (index2.js)
var Tile38 = require('tile38');
var client = new Tile38({host: 'localhost', port: 9851, debug: false });
let query = client.intersectsQuery('fleet').detect('enter','exit').bounds(33.462, -112.268, 33.491, -112.245);
let fence = query.executeFence( function (err, results) {
// this callback will be called multiple times
console.log("************");
if (err) {
console.error("something went wrong! " + err);
} else {
console.dir(results);
}
});
and
inserted the record with following set command: (index3.js)
var Tile38 = require('tile38');
var client = new Tile38({host: 'localhost', port: 9851, debug: false });
// set a simple lat/lng coordinate
client.set('fleet', 'truck1', [33.5123, -112.2693])
but I'm not getting notification in the executeFence call back in the (index2.js) ? Am I doing anything wrong?
Hi,
I tried to run client.withinQuery (on polygon) exactly like in search.js and i got the error:
message: "ERR wrong number of arguments for 'within' command"
stack: "ReplyError: ERR wrong number of arguments for 'within' command\n at parseError (/home/stavav/projects/tile38-test/node_modules/redis-parser/lib/parser.js:193:12)\n at parseType (/home/stavav/projects/tile38-test/node_modules/redis-parser/lib/parser.js:303:14)"
After that i checked the search.js and got the same error
i am working with tile38 1.17.1
thanks for help :)
Used whereEval to run a script ("return FIELDS.specialtily > ARGV[1]", 1) which queries on custom fields, but I keep getting syntax error
All of the ES2015 features this library takes advantage of are natively supported as of Node v6, just wondering why you're requiring the extra tranpilation step.
I've got a docker-compose.yaml see below, that is spinning up Tile38 and a node/express api. First thing I'm trying to do is use node-tile to connect to the Tile38 container. My plan is to build a REST API to sit in front of Tile.
The node service spins up fine, but when I try to connect to Tile like this:
const Tile38 = require('tile38'); const tileClient = new Tile38({host: '0.0.0.0', port: 9851, debug: true });
I get this error:
Running on http://0.0.0.0:3000 Tile38 connection error: Error: Redis connection to localhost:9851 failed - connect ECONNREFUSED 127.0.0.1:9851 Tile38 connection error: Error: Redis connection to localhost:9851 failed - connect ECONNREFUSED 127.0.0.1:9851 Tile38 connection error: Error: Redis connection to localhost:9851 failed - connect ECONNREFUSED 127.0.0.1:9851 Tile38 connection error: Error: Redis connection to localhost:9851 failed - connect ECONNREFUSED 127.0.0.1:9851 Tile38 connection error: Error: Redis connection to localhost:9851 failed - connect ECONNREFUSED 127.0.0.1:9851 Tile38 connection error: Error: Redis connection to localhost:9851 failed - connect ECONNREFUSED 127.0.0.1:9851 Tile38 connection error: Error: Redis connection to localhost:9851 failed - connect ECONNREFUSED 127.0.0.1:9851 Tile38 connection error: Error: Redis connection to localhost:9851 failed - connect ECONNREFUSED 127.0.0.1:9851
Here's my Docker-compose.yaml
version: '3' services: tile38: image: "tile38/tile38" ports: - "9851:9851" webapi: build: . image: "node-tile38:1.7" ports: - "49160:3000" links: - tile38
(node:98273) Warning: a promise was rejected with a non-error: [object String]
Type member is invalid. Expecting a string
just needs to be wrapped in an error class to get rid of these annoying warnings. would also be great if these errors had different classes, so you can differentiate between validation errors and connection errors.
Hi everybody,
I'm trying to use your library to exploit tile38 services, but I encounter problems in following the documentation.
For instance, the following statement which follow the documentation in the README
let query = client.intersectsQuery('Station').detect('inside','outside').bounds(44.64701352313015, 10.886374409919698, 44.66163938662867, 10.892356791848103);
returns error
Error: DETECT is not allowed when FENCE is not specified
However, when I try to pass such option as per documentation
let query = client.intersectsQuery('Station', { fence: true}).detect('inside','outside').bounds(44.64701352313015, 10.886374409919698, 44.66163938662867, 10.892356791848103);
the same error happens.
I tried putting the option in the detect() function, but it is not recognised as parameter.
Finally, I tried using executeCommand() function as below:
client.executeCommand('INTERSECTS Station BOUNDS 44.64701352313015, 10.886374409919698, 44.66163938662867, 10.892356791848103 FENCE DETECT inside, outside', { parseJson: false }).then(result => { console.dir(result); }).catch(err => { console.error("Error: " + err); });
but I get
TypeError: client.executeCommand is not a function
I'm stuck as I cannot rely on the documentation...can anyone help?
Thanks in advance :)
[EDIT] Tile38 nom package version:
"tile38": { "version": "0.8.0", "resolved": "https://registry.npmjs.org/tile38/-/tile38-0.8.0.tgz", "integrity": "sha512-Z7n/bsqrFHIUd+wr43wVMEwDg4wedBOznFjIDPShKnadrnuuLDHDzGdT/51L4nnX+SmJLg2B6KIxKqkZe+HlJQ==", "requires": { "redis": "^3.0.0", "redis-parser": "^3.0.0" } }
Tile38 command line server version: tile38-server version: 1.25.5 (1a0c28ce)
Helper method (or examples) to take the objects returned from the queries such as within, intersects and have them return properly formatted geojson.
when I tried the following code:
let query = client.nearbyQuery('fleet').distance().point(33.5123, -112.2693, 6000)
query.execute(function(results).then(results => {
console.dir(results); // results is an object.
}))
I'm getting
query.execute(function(results).then(results => {
^
SyntaxError: Unexpected token .
the git hub repo has executeCommand but when I npm the package the executeCommand is missing in the js file.
Hi,
Is it possible to shoe horn in the NODWELL
keyword when setting up roaming geofences?
Something like :
NEARBY fleet LIMIT 1 POINT 33.462 -112.268
I'm getting
sending live fence command "NEARBY adp-nms-push FENCE POINT 33.1212 -122.2423 1000"
TypeError: "string" must be a string, Buffer, or ArrayBuffer
in this code
const query = geoClient.nearbyQuery('adp-nms-push')
.detect('enter', 'exit')
.point(33.1212, -122.2423, 1000)
const fence = query.executeFence()
node version: v8.9.1
node-tile38 version: 0.6.4
for example to
1.client.nearbyQuery('fleet').roam('truck', 'orders', 3000) need to add also radius circle for 'orders' => client.nearbyQuery('fleet').roam('truck', 'orders', 3000, 10)
OR something like this
2. client.set('fleet', "truck" + ${1}
, [lat, lng], { radius: 3000 } )
client.set('fleet', "orders" + ${7}
, [lat, lng], { radius: 10 } )
client.nearbyQuery('fleet').roam('truck', 'orders').output('radius')
, It's possible ???
Kind Regards
Eugene.
Hi,
Using the lib, these warnings never appeared, but now it started to appear.
I am passing all parameters correctly and works. But keep giving the version warnings!
node_redis: Deprecated: The JSET command contains a "null" argument. This is converted to a "null" string now and will return an error from v.3.0 on. Please handle this in your code to make sure everything works as you intended it to.
Since error
event is no handled on internal redis client, when tile server is down, the node.js process is crashed by node-tile38
It seems like the auth()
command doesn't set the supplied password, see https://github.com/phulst/node-tile38/blob/master/src/tile38.js#L142-L144
I keep seeing errors like
events.js:165
throw er; // Unhandled 'error' event
^
ReplyError: Ready check failed: ERR authentication required
at parseError (/var/www/backend/node_modules/redis-parser/lib/parser.js:193:12)
at parseType (/var/www/backend/node_modules/redis-parser/lib/parser.js:303:14)
Emitted 'error' event at:
at RedisClient.on_info_cmd (/var/www/backend/node_modules/redis/index.js:496:14)
at /var/www/backend/node_modules/redis/index.js:535:14
at Object.callbackOrEmit [as callback_or_emit] (/var/www/backend/node_modules/redis/lib/utils.js:89:9)
at /var/www/backend/node_modules/redis/lib/individualCommands.js:157:15
at Object.callbackOrEmit [as callback_or_emit] (/var/www/backend/node_modules/redis/lib/utils.js:89:9)
at RedisClient.return_error (/var/www/backend/node_modules/redis/index.js:706:11)
at JavascriptRedisParser.returnError (/var/www/backend/node_modules/redis/index.js:196:18)
at JavascriptRedisParser.execute (/var/www/backend/node_modules/redis-parser/lib/parser.js:572:12)
at Socket.<anonymous> (/var/www/backend/node_modules/redis/index.js:274:27)
at Socket.emit (events.js:180:13)
at addChunk (_stream_readable.js:269:12)
at readableAddChunk (_stream_readable.js:256:11)
at Socket.Readable.push (_stream_readable.js:213:10)
at TCP.onread (net.js:581:20)
withinSomeBounds = tileClient.withinQuery('reg_'+locationData.user_id).detect('enter','exit').bounds(sw_lat, sw_long, ne_lat, ne_long);
withinSomeBounds.executeFence((err, results) => {
if (err) {
console.error(err);
} else {
console.log(results);
if(results.detect == "enter"){
long = results.object.coordinates[0];
lat = results.object.coordinates[1];
user_id = results.id;
var message = {
user_id: user_id,
lat:lat,
long:long,
b:1
};
pub.publish('ch_'+locationData.user_id, JSON.stringify(message));
}
}
});
We are setting up multiple geofences but when set any lat long to them it returns multiple enter exit events.
This code yields errors:
let query = client.intersectsQuery('fleet').detect('enter','exit').object(feature.geometry);
// start the live geofence
let fence = query.executeFence((err, results) => {
}
I got it fixed by (removing fence
duplicate) changing into:
diff --git a/src/tile38_query.js b/src/tile38_query.js
index 7552722..f868d55 100644
--- a/src/tile38_query.js
+++ b/src/tile38_query.js
@@ -273,7 +273,7 @@ class Tile38Query {
let commands = ['cursor', 'limit', 'sparse', 'matches', 'order', 'distance', 'where',
'whereIn', 'whereEval', 'whereEvalSha', 'clip', 'nofields', 'fence', 'detect',
'commands', 'output', 'getObject', 'bounds', 'geojson', 'tile', 'quadKey', 'hash',
- 'point', 'circle', 'roam', 'fence' ];
+ 'point', 'circle', 'roam'];
for (let c of commands) {
let opt = o[c];
if (opt !== undefined) {
Please review. (And push a fix as soon as you can.)
Regards,
Adi.
While setting JSON object to tile38 with client.set, the coordinates are set as NaN, why and how to set JSON object to tile38.
But I've done that with python, then it works fine.
Please help!
Most probably this is tile38
server issue - but just in case if this is related to any configuration (such as requesting the output format properly from the server etc.), posting here too.
The server command works fine usually (resulting in a valid JSON). However, started observing an issue when network connection is lost to the server, and the server command is queued and then network connection is restored. Afterwards, it starts giving below response:
sending command "SERVER " tile38.js:62
Array(40) ["aof_size", "345637", "avg_item_size", "178955", "cpus", "4", "heap_released", "62750720", …] tile38.js:69
which started to fail with JSON.parse()
The key, and values are returned as elements of an array side-by-side, instead of as key-value pairs of an object.
FWIW, the response is coming with type 42 in the redis-parser\lib\parser.js file (Screenshot below):
Thank you for sharing this good work. It is helpful. One suggestion.
Please accept a err function as parameter, so that we can configure which logger should be used. Currently on error
code is hard coded to use console.
Line 21 in 7b122c5
Please do something like below:
const defaultErrHandler = err =>console.error('Tile38 connection error: ' + err);
constructor({port, host, password, debug = false} = {}, onErr = defaultErrHandler ) {
// ....
this.client.on('error', onErr);
}
Similarly, replace the debug code:
Lines 41 to 43 in 7b122c5
with something as below:
if (this.debug) this.debugLog(`sending command "${cmd} ${args.join(' ')}"`);
The debugLog
callback can be accepted as parameter to the constructor, or set equal to the onErr
in the constructor (though it is strongly advised to keep both separate).
const defaultDebugHandler = msg =>console.log(msg);
constructor({port, host, password, debug = false} = {}, onErr = defaultErrHandler, debugLogFn = defaultDebugLog ) {
// ...
this.debugLog = debugLogFn;
}
Implementing this kind of inversion of control
design pattern makes this package play more nicely with other modules when used in large scale projects.
I was looking in the docs of Tile38 official site and they say that this can be done with the hooks, but in the readme.md of this node cliente they say that hooks are not available.
¿Is there any way to get the geofences that are already active?
¿can i search a geofence by some id or whatever?
I have tried with
fence.scanQuery()
But it just returns the points that i've set to the fences.
with the command:
fence.searchQuery
nothing returns.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.