npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

q3-fence

v1.0.9

Published

Interface to communicate with geofencing library

Downloads

17

Readme

Q3-Fence

A polygon geofencing library


Requirements

For development, you will only need Node.js and a node global package, NPM, installed in your environement.

Install

  $ npm install q3-fence

Usage

   const { init } = require("q3-fence");
   
   let mongoDBUrl = "...";
   
   await init(mongoDBUrl);

This should be called when your program/app starts.

Create new geofence

Geofences are created using the addGeofence function the type paramer value can be one of "area" or "region". In the coordinates array, longitudes should come first before latitudes. Any other data in the payload will be added to the metadata field.

const {
    init,
    updateGeofenceDoc,
    removeGeofenceDoc,
    allUsersInGeofence,
    allGeofence,
    allGeofenceForUser,
    deleteGeofence,
    updateGeofence,
    addGeofence,
    addGeofenceDoc,
    serializeUser,
    findGeofenceDocForUser} = require("q3-fence"); // import the ones you need

const payload = {"areas":[{"coordinates":[
    [3.5826842486858372,6.513636165419227],
    [3.574883043766022,6.505586785393162],
    [3.5806953907012944,6.496937655454424],
    [3.5889177024364476,6.499954407858632],
    [3.590706735849381,6.509557526975297],
    [3.5826842486858372,6.513636165419227]]}],
    "name":"Geofence name",
    "description":"geofence description","type":"area"};

addGeofence(payload)

Delete a geofence

const payload = {id: geofenceId};
deleteGeofence(payload);

Add a document to geofence

Once a geofence has been created, documents can be add to it. To add a document to a geofence, use the function addGeofenceDoc. areaId is the id of the geofence the document will be added.

const doc = {
    "areaId": "62334ab836017f4970c38446",
    "name": "Unity Bank",
    "age": {
        "max": 60,
        "min": 18
    },
    "start": "2022-03-11T09:42:36.185Z",
    "end": "2022-03-16T10:05:01.548Z",
    "time": {
        "max": 12345,
        "min": 1234
    },
    "gender": ["male", "all"],
    "approval_status": true
};

addGeofenceDoc(payload)

Remove document from a geofence

To remove a document from a geofence/area, call the removeGeofenceDoc with an object containing the areaId and document id

const query = {areaId: "563uqad...", docId:"12e6ioisda..."}
removeGeofenceDoc(query);

Update document in a geofence

To update a document in a geofence, supply an object that has the same with the document in the geofence but with the updated value. If the new key value pairs were not in the existing document, it will be added

const payload = {areaId: "563uqad...", docId:"12e6ioisda...", ...data}
updateGeofenceDoc(payload);

Serialize User

Add user data to the collection the proper way, setting longitude and latitude

const user = {long: longitudeValue, lat: latitudeValue, ...} // user data
serializeUser(user)

All users in a geofence

To get all users in a particular geofence, use allUsersInGeofence, and pass an object that has either the area id or lat and lng

const query = {lng: longitudeValue, lat: latitudeValue, ...} // user data
allUsersInGeofence(query);

or

const query = {areaId: areaIdValue}
allUsersInGeofence(query);

Features

init
addGeofence
updateGeofence
deleteGeofence
allGeofence

addGeofenceDoc
updateGeofenceDoc
removeGeofenceDoc

allUsersInGeofence
allGeofenceForUser

serializeUser
findGeofenceDocForUser