forked from uber-archive/vis-academy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reactmapgl deckgl new syntax (uber-archive#72)
* upgraded scaffold from buble to babel 7, react to react 16, all vis libraries to latest version * updating starting-with-map * updated up to module 3 * updated lesson 4 * update all lessons * modifying the docs * forgot those 2 files * changes to webpack config files
- Loading branch information
Jerome Cukier
authored
Nov 14, 2018
1 parent
eb10472
commit d144742
Showing
103 changed files
with
35,461 additions
and
11,366 deletions.
There are no files selected for viewing
2 changes: 0 additions & 2 deletions
2
src/demos/building-a-geospatial-app/1-starting-with-map/.npmrc
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 0 additions & 14 deletions
14
src/demos/building-a-geospatial-app/1-starting-with-map/index.html
This file was deleted.
Oops, something went wrong.
40 changes: 27 additions & 13 deletions
40
src/demos/building-a-geospatial-app/1-starting-with-map/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,35 @@ | ||
{ | ||
"name": "building-a-geospatial-app", | ||
"version": "0.0.1", | ||
"scripts": { | ||
"start-local": "webpack-dev-server --env.local --progress --hot --port 3030 --open", | ||
"start": "webpack-dev-server --progress --hot --port 3030 --open", | ||
"build": "NODE_ENV=production webpack --env.prod=true" | ||
"start": "webpack-dev-server --config ./webpack.config.js --mode development" | ||
}, | ||
"dependencies": { | ||
"deck.gl": "^4.1.0", | ||
"immutable": "^3.8.1", | ||
"luma.gl": "^4.0.1", | ||
"react": "^15.4.1", | ||
"react-dom": "^15.4.1", | ||
"react-map-gl": "^3.0.4", | ||
"react-vis": "^1.7.2" | ||
"deck.gl": "^6.2.4", | ||
"luma.gl": "^6.2.0", | ||
"react": "^16.6.1", | ||
"react-dom": "^16.6.1", | ||
"react-map-gl": "^4.0.0", | ||
"react-vis": "^1.11.4" | ||
}, | ||
"babel": { | ||
"presets": [ | ||
"@babel/preset-env", | ||
"@babel/preset-react" | ||
], | ||
"plugins": [ | ||
"@babel/plugin-proposal-class-properties" | ||
] | ||
}, | ||
"devDependencies": { | ||
"buble-loader": "^0.4.0", | ||
"webpack": "^2.2.0", | ||
"webpack-dev-server": "^2.2.0" | ||
"@babel/core": "^7.1.5", | ||
"@babel/plugin-proposal-class-properties": "^7.1.0", | ||
"@babel/preset-env": "^7.1.5", | ||
"@babel/preset-react": "^7.0.0", | ||
"babel-loader": "^8.0.4", | ||
"react-hot-loader": "^4.3.12", | ||
"webpack": "^4.25.1", | ||
"webpack-cli": "^3.1.2", | ||
"webpack-dev-server": "^3.1.10" | ||
} | ||
} |
10 changes: 0 additions & 10 deletions
10
src/demos/building-a-geospatial-app/1-starting-with-map/root.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/demos/building-a-geospatial-app/1-starting-with-map/src/charts.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from "react"; | ||
import { charts } from "./style"; | ||
|
||
import { VerticalBarSeries, XAxis, XYPlot, YAxis } from "react-vis"; | ||
|
||
export default function Charts({ pickups }) { | ||
return ( | ||
<div style={charts}> | ||
<h2>Pickups by hour</h2> | ||
<p>As percentage of all trips</p> | ||
<XYPlot height={140} width={480}> | ||
<XAxis /> | ||
<YAxis /> | ||
<VerticalBarSeries data={pickups} /> | ||
</XYPlot> | ||
</div> | ||
); | ||
} |
195 changes: 195 additions & 0 deletions
195
src/demos/building-a-geospatial-app/1-starting-with-map/src/controls.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
import React, { Component } from 'react'; | ||
import { mapStylePicker, layerControl } from './style'; | ||
|
||
export const HEXAGON_CONTROLS = { | ||
showHexagon: { | ||
displayName: 'Show Hexagon', | ||
type: 'boolean', | ||
value: true | ||
}, | ||
radius: { | ||
displayName: 'Hexagon Radius', | ||
type: 'range', | ||
value: 250, | ||
step: 50, | ||
min: 50, | ||
max: 1000 | ||
}, | ||
coverage: { | ||
displayName: 'Hexagon Coverage', | ||
type: 'range', | ||
value: 0.7, | ||
step: 0.1, | ||
min: 0, | ||
max: 1 | ||
}, | ||
upperPercentile: { | ||
displayName: 'Hexagon Upper Percentile', | ||
type: 'range', | ||
value: 100, | ||
step: 0.1, | ||
min: 80, | ||
max: 100 | ||
}, | ||
radiusScale: { | ||
displayName: 'Scatterplot Radius', | ||
type: 'range', | ||
value: 30, | ||
step: 10, | ||
min: 10, | ||
max: 200 | ||
} | ||
}; | ||
|
||
export const SCATTERPLOT_CONTROLS = { | ||
radiusScale: { | ||
displayName: 'Scatterplot Radius', | ||
type: 'range', | ||
value: 30, | ||
step: 10, | ||
min: 10, | ||
max: 200 | ||
}, | ||
showHexagon: { | ||
displayName: 'Show Hexagon', | ||
type: 'boolean', | ||
value: true | ||
} | ||
}; | ||
|
||
const MAPBOX_DEFAULT_MAPSTYLES = [ | ||
{ label: 'Streets V10', value: 'mapbox://styles/mapbox/streets-v10' }, | ||
{ label: 'Outdoors V10', value: 'mapbox://styles/mapbox/outdoors-v10' }, | ||
{ label: 'Light V9', value: 'mapbox://styles/mapbox/light-v9' }, | ||
{ label: 'Dark V9', value: 'mapbox://styles/mapbox/dark-v9' }, | ||
{ label: 'Satellite V9', value: 'mapbox://styles/mapbox/satellite-v9' }, | ||
{ | ||
label: 'Satellite Streets V10', | ||
value: 'mapbox://styles/mapbox/satellite-streets-v10' | ||
}, | ||
{ | ||
label: 'Navigation Preview Day V4', | ||
value: 'mapbox://styles/mapbox/navigation-preview-day-v4' | ||
}, | ||
{ | ||
label: 'Navitation Preview Night V4', | ||
value: 'mapbox://styles/mapbox/navigation-preview-night-v4' | ||
}, | ||
{ | ||
label: 'Navigation Guidance Day V4', | ||
value: 'mapbox://styles/mapbox/navigation-guidance-day-v4' | ||
}, | ||
{ | ||
label: 'Navigation Guidance Night V4', | ||
value: 'mapbox://styles/mapbox/navigation-guidance-night-v4' | ||
} | ||
]; | ||
|
||
export function MapStylePicker({ currentStyle, onStyleChange }) { | ||
return ( | ||
<select | ||
className="map-style-picker" | ||
style={mapStylePicker} | ||
value={currentStyle} | ||
onChange={e => onStyleChange(e.target.value)} | ||
> | ||
{MAPBOX_DEFAULT_MAPSTYLES.map(style => ( | ||
<option key={style.value} value={style.value}> | ||
{style.label} | ||
</option> | ||
))} | ||
</select> | ||
); | ||
} | ||
|
||
export class LayerControls extends Component { | ||
_onValueChange(settingName, newValue) { | ||
const { settings } = this.props; | ||
// Only update if we have a confirmed change | ||
if (settings[settingName] !== newValue) { | ||
// Create a new object so that shallow-equal detects a change | ||
const newSettings = { | ||
...this.props.settings, | ||
[settingName]: newValue | ||
}; | ||
|
||
this.props.onChange(newSettings); | ||
} | ||
} | ||
|
||
render() { | ||
const { title, settings, propTypes = {} } = this.props; | ||
|
||
return ( | ||
<div className="layer-controls" style={layerControl}> | ||
{title && <h4>{title}</h4>} | ||
{Object.keys(settings).map(key => ( | ||
<div key={key}> | ||
<label>{propTypes[key].displayName}</label> | ||
<div style={{ display: 'inline-block', float: 'right' }}> | ||
{settings[key]} | ||
</div> | ||
<Setting | ||
settingName={key} | ||
value={settings[key]} | ||
propType={propTypes[key]} | ||
onChange={this._onValueChange.bind(this)} | ||
/> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
const Setting = props => { | ||
const { propType } = props; | ||
if (propType && propType.type) { | ||
switch (propType.type) { | ||
case 'range': | ||
return <Slider {...props} />; | ||
|
||
case 'boolean': | ||
return <Checkbox {...props} />; | ||
default: | ||
return <input {...props} />; | ||
} | ||
} | ||
}; | ||
|
||
const Checkbox = ({ settingName, value, onChange }) => { | ||
return ( | ||
<div key={settingName}> | ||
<div className="input-group"> | ||
<input | ||
type="checkbox" | ||
id={settingName} | ||
checked={value} | ||
onChange={e => onChange(settingName, e.target.checked)} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
const Slider = ({ settingName, value, propType, onChange }) => { | ||
const { max = 100 } = propType; | ||
|
||
return ( | ||
<div key={settingName}> | ||
<div className="input-group"> | ||
<div> | ||
<input | ||
type="range" | ||
id={settingName} | ||
min={0} | ||
max={max} | ||
step={max / 100} | ||
value={value} | ||
onChange={e => onChange(settingName, Number(e.target.value))} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; |
8 changes: 8 additions & 0 deletions
8
src/demos/building-a-geospatial-app/1-starting-with-map/src/deckgl-layers.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import React, { Component } from 'react'; | ||
|
||
const PICKUP_COLOR = [114, 19, 108]; | ||
const DROPOFF_COLOR = [243, 185, 72]; | ||
|
||
export function renderLayers(props) { | ||
return []; | ||
} |
6 changes: 6 additions & 0 deletions
6
src/demos/building-a-geospatial-app/1-starting-with-map/src/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
|
||
import App from './app'; | ||
ReactDOM.render(<App />, document.getElementById('app')); | ||
module.hot.accept(); |
Oops, something went wrong.