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

spatialconnect

v0.12.0

Published

Javascript Library for SpatialConnect

Downloads

41

Readme

SpatialConnect Javascript Library for Android & iOS

Build Status Version 0.11.0

Philosophy

The SpatialConnect javascript bridge is a cross platform solution for letting webviews access native functionality. This has a number of benefits pertaining to performance, security, and persistence to name a few. The request/response pattern is similar to the one way data flow paradigm found in the Flux architecture. A request occurs by calling an action in the library, and then all subscribers to the response observable will receive the result. The subscribers can use RxJS Observable instance methods to filter and operate on events that are emitted. We use the term spatial to refer to data with a finite number of dimensions. We use the term geospatial to refer to data with a finite number of dimensions where one of those dimensions have geographic coordinates.

Getting Started

Pull down dependencies

npm install

Run Tests

npm run test

Build distribution file

npm run build

Installation in your project

npm install spatialconnect

Usage in your project

In WebView

import * as sc from 'spatialconnect';

In React Native

import * as sc from 'spatialconnect/native';

Communicating with the Bridge

For iOS, JSON objects are sent to the SpatialConnect native library, and for Android, JSON is stringified and sent to the SpatialConnect native library. This is automatically detected in the library by using the user agent for each platform. The envelope for each message is as follows:

{
  "action":<integer>,
  "payload":<JSON Object>
}

Available Actions

DATASERVICE_ACTIVESTORESLIST = 100
DATASERVICE_ACTIVESTOREBYID = 101
DATASERVICE_SPATIALQUERY = 110
DATASERVICE_SPATIALQUERYALL = 111
DATASERVICE_GEOSPATIALQUERY = 112
DATASERVICE_GEOSPATIALQUERYALL = 113
DATASERVICE_CREATEFEATURE = 114
DATASERVICE_UPDATEFEATURE = 115
DATASERVICE_DELETEFEATURE = 116
DATASERVICE_FORMSLIST = 117
SENSORSERVICE_GPS = 200

These integer codes are bidirectional and are the same across platforms.

SpatialData Transmission

For sending and receiving geospatial data, the transmission format is using GeoJSON. You can encode geographic features like so:

var gj = {
  "type": "Feature",
  "properties": {
    "foo": "bar"
  },
  "geometry": {
    "type": "Point",
    "coordinates": [ 10, 20 ]
  }
};
var store_name = 'a5d93796-5026-46f7-a2ff-e5dec85heh6b';
var layer_name = 'point_features';
var feature = sc.geometry(store_name, layer_name, gj);
sc.createFeature(feature).subscribe(function(f) {
  //add feature to OpenLayers map
  var gj = (new ol.format.GeoJSON()).readFeature(f);
  vectorSource.addFeature(gj);
});

You can also create non geographic features (spatial).

var properties = { foo: "bar" };
var feature = sc.spatialFeature(store_name, layer_name, properties);

Querying Data

Getting the current viewport from OpenLayers

var extent = map.getView().calculateExtent(map.getSize());
var filter = sc.Filter().geoBBOXContains(extent);
sc.geospatialQuery(filter);
var storeId = 'a5fdreg22';
var filter = { $gte : 5 };
sc.spatialQuery(filter,storeId); //For one Store
sc.spatialQuery(filter); //For all stores

The data responds on the query observable. All components (listview,map) wanting the data can subscribe to that observable

var that = this;
sc.spatialQuery().subscribe(
  (data) => {
    var gj = (new ol.format.GeoJSON()).readFeature(data);
    vectorSource.addFeature(gj);
  },
  (err) => {
    this.setState({
      error : err
    });
  },
  () => {
    this.setState({
      error : {}
    });
  }
);

Data Store Info

Get all stores

sc.stores().subscribe(
  (storesArray) => {
    setState({stores:storesArray});
  }
);
var storeId = 'afdse4';
sc.store(storeId).filter((s) => return s.storeId === storeId;)subscribe(
  (store) => {
    setState({storeInfo:store});
  }
);

Location Services

Location Services

sc.lastKnownLocation().subscribe(
  (loc) => { console.log(loc); }
);
sc.enableGPS();//Enables GPS
sc.disableGPS();//Disable GPS

Custom Actions

You can send arbitrary messages to the native bridge like so:

sc.action.sendMessage(998,payload);