|
3 | 3 | [![NPM version][npm-image]][npm-url] |
4 | 4 | [![Build status][travis-image]][travis-url] |
5 | 5 |
|
6 | | -Create isochrones and accessibility images in the browser |
| 6 | +Create isochrones and accessibility images in the browser. |
7 | 7 |
|
8 | | -## How to create and display an isochrone (assuming you have the data!) |
| 8 | +## API |
9 | 9 |
|
10 | | -```js |
11 | | -const b = new Browsochrones({webpack: false}) // set to true if using webpack to bundle |
12 | | -const baseUrl = 'https://s3.amazon.com/bucket' |
13 | | -const cutoff = 60 // minutes |
14 | | -const map = Leaflet.map('map') |
15 | | -const lonlat = {lat: 39.766667, lon: -86.15} |
16 | | - |
17 | | -(async function () { |
18 | | - const query = await fetch(baseUrl + '/query.json').then((res) => res.json()) |
19 | | - const stopTrees = await fetch(baseUrl + '/stop_trees.dat').then((res) => res.arrayBuffer()) |
20 | | - const grid1 = await fetch(gridUrl + '/Jobs_total.grid').then((res) => res.arrayBuffer()) |
21 | | - const grid2 = await fetch(gridUrl + '/Workers_total.grid').then((res) => res.arrayBuffer()) |
22 | | - |
23 | | - await b.setQuery(query) |
24 | | - await b.setStopTrees(stopTrees) |
25 | | - await b.putGrid(grid1, 'jobs') |
26 | | - await b.putGrid(grid2, 'workforce') |
27 | | - await b.setTransitiveNetwork(query.transitiveData) |
28 | | - |
29 | | - const point = b.pixelToOriginPoint(map.project(lonlat), map.getZoom()) |
30 | | - const data = await fetch(baseUrl + '/' + (point.x | 0) + '/' + (point.y | 0) + '.dat').then((res) => res.arrayBuffer()) |
31 | | - |
32 | | - await b.setOrigin(data.slice(0), point) |
33 | | - await b.generateSurface('jobs') |
34 | | - await b.generateSurface('workforce') |
35 | | - |
36 | | - const surfaceLayer = new Leaflet.GridLayer() |
37 | | - surfaceLayer.createTile = b.createTile // automatically bound to the instance |
38 | | - surfaceLayer.addTo(map) |
39 | | - |
40 | | - const isochrone = await b.getIsochrone(cutoff) // minutes |
41 | | - const isoLayer = Leaflet.geoJSON(isochrone, { |
42 | | - style: { |
43 | | - weight: 3, |
44 | | - color: '#f00', |
45 | | - opacity: 1, |
46 | | - fillColor: '#222', |
47 | | - fillOpacity: 0.3 |
48 | | - } |
49 | | - }).addTo(map) |
50 | | - |
51 | | - const jobAccess = await b.getAccessibilityForGrid('jobs', cutoff) |
52 | | - console.log('job access', jobAccess) |
53 | | - const workforceAccess = await b.getAccessibilityForGrid('workforce', cutoff) |
54 | | - console.log('workforce access', workforceAccess) |
55 | | -})() |
56 | | -``` |
| 10 | +Check out the [example](example.js) or the [tests](__tests__/index.js). |
57 | 11 |
|
58 | 12 | [npm-image]: https://img.shields.io/npm/v/browsochrones.svg?maxAge=2592000&style=flat-square |
59 | 13 | [npm-url]: https://www.npmjs.com/package/browsochrones |
|
0 commit comments