0.1.2 • Published 9 years ago

analyst.js v0.1.2

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

analyst.js

Lightweight client library for making requests to Analyst Server

Analyst(L, options, [options.baseUrl], [options.apiUrl], [options.tileUrl], [options.connectivityType], [options.timeLimit], [options.showPoints], [options.showIso], [options.requestOptions], [options.tileLayerOptions])

Create an instance of Analyst.js for use with single point requests.

Parameters

parametertypedescription
LLeafletPass in an instance of Leaflet so that it doesn't need to be packaged as a dependency.
optionsObjectOptions object.
[options.baseUrl]Stringoptional: The base url, will set the tile and api urls if they are left unset
[options.apiUrl]Stringoptional:
[options.tileUrl]Stringoptional:
[options.connectivityType]Stringoptional:
[options.timeLimit]Numberoptional: Defaults to 3600
[options.showPoints]Booleanoptional: Defaults to false
[options.showIso]Booleanoptional: Defaults to true
[options.requestOptions]Objectoptional: Pass in default request options to be used.
[options.tileLayerOptions]Objectoptional: Pass in default tileLayerOptions to use.

Example

const analyst = new Analyst(window.L, {
  apiUrl: 'http://localhost:3000/api',
  tileUrl: 'http://localhost:4000/tile',
  baseUrl: 'http://localhost:3000'
})

updateSinglePointLayer(key, [comparisonKey])

Update/create the single point layer for this Analyst.js instance.

Parameters

parametertypedescription
keyStringKey for accessing the single point layer tiles.
[comparisonKey]Stringoptional: Key for the layer to compare against.

Example

analyst.updateSinglePointLayer(key).redraw()

Returns TileLayer, A Leaflet tile layer that pulls in the generated single point tiles.

shapefiles

Get all of the available shapefiles.

Example

analyst.shapefiles().then(function (shapefiles) {
  console.log(shapefiles)
})

Returns Promise, Resolves with a JSON list of shapefiles.

singlePointRequest(point, graphId, [shapefileId], [options])

Run a single point request and generate a tile layer.

Parameters

parametertypedescription
pointLatLng
graphIdStringGraph ID to use for this request.
[shapefileId]Stringoptional: Shapefile ID to be used with this request, can be omitted for a vector request.
[options]Objectoptional: Options object.

Example

analyst
  .singlePointRequest(marker.getLatLng())
  .then(function (data) {
    analyst.updateSinglePointLayer(data.key)
  })

Returns Promise, Resolves with an object containing the results data.

singlePointComparison(point, options, comparisonOptions)

Compare two scenarios.

Parameters

parametertypedescription
pointLatLng
optionsObject
comparisonOptionsObject

Example

analyst
  .singlePointComparison(marker.getLatLng(), { graphId: 'graph1' }, { graphId: 'graph2' })
  .then(([res, cres]) => {
    analyst.updateSinglePointLayer(res.key, cres.key)
  })

Returns Promise, Resolves with an array containing [results, comparisonResults]

setClientCredentials(clientCredentials)

Set the client credentials for this analyst.js instance

Parameters

parametertypedescription
clientCredentialsString

obtainClientCredentials(key, secret, refresh)

Get client credentials for this instance, optionally keeping them up-to-date automatically. Note that using this function on the client side requires your API key and secret to be sent to the client, which is non-ideal; a better pattern would be to keep the API key/secret on the server and only retrieve client credentials there, and then deliver only the client credentials to the client. Client credentials have a limited time to live, so they are less sensitive than API keys.

Parameters

parametertypedescription
keyStringYour API key
secretStringYour API secret
refreshbooleanif true (default), automatically update client credentials when they are about to expire.

Returns h, client credentials. They will also be set as the client credentials for this analyst instance.

Installation

Requires nodejs.

$ npm install analyst.js

Tests

$ npm test
0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago

0.0.7

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago