diff --git a/website-gatsby/ocular-config.js b/website-gatsby/ocular-config.js index 6afce60068a..7822b804adb 100644 --- a/website-gatsby/ocular-config.js +++ b/website-gatsby/ocular-config.js @@ -160,9 +160,9 @@ based maps.', }, { title: 'TextLayer', - path: 'examples/text', + path: 'examples/website/text-layer', image: 'images/examples/demo-thumb-text.jpg', - componentUrl: resolve(__dirname, '../examples/website/tagmap/app.js') + componentUrl: resolve(__dirname, './src/examples/example-text-layer.jsx') }, { title: 'TileLayer', diff --git a/website-gatsby/src/examples/example-text-layer.jsx b/website-gatsby/src/examples/example-text-layer.jsx new file mode 100644 index 00000000000..f844f756221 --- /dev/null +++ b/website-gatsby/src/examples/example-text-layer.jsx @@ -0,0 +1,81 @@ +import React, {Component} from 'react'; +import InfoPanel from '../components/info-panel'; +import {MAPBOX_STYLES, DATA_URI, GITHUB_TREE} from '../constants/defaults'; +import {loadData} from '../utils/data-utils'; +import {readableInteger} from '../utils/format-utils'; +import App from '../../../examples/website/tagmap/app'; + +export default class TextLayerDemo extends Component { + constructor(props) { + super(props); + this.state = { + data: [], + dataCount: 0, + cluster: true, + fontSize: 32 + }; + + this._handleChange = this._handleChange.bind(this); + } + + componentDidMount() { + loadData(`${DATA_URI}/hashtags100k.txt`, '/workers/hashtags-decoder.js', (response, meta) => { + this.setState({ + data: response, + dataCount: meta.count + }); + }); + } + + _handleChange(event) { + switch (event.target.name) { + case 'font-size': + this.setState({fontSize: parseInt(event.target.value)}); + break; + case 'cluster': + this.setState({cluster: event.target.checked}); + break; + } + } + + render() { + const {data, dataCount, cluster, fontSize} = this.state; + + return ( +
+ + +

Twitter Hashtags

+

Data set from Twitter showing hashtags with geolocation.

+

+ Data source: + Twitter +

+
+
+ No. of Tweets + {readableInteger(dataCount)} +
+
+
+
+ + +
+
+ + +
+
+
+ ); + } +} diff --git a/website-gatsby/static/workers/hashtags-decoder.js b/website-gatsby/static/workers/hashtags-decoder.js new file mode 100644 index 00000000000..9cd3a99da46 --- /dev/null +++ b/website-gatsby/static/workers/hashtags-decoder.js @@ -0,0 +1,38 @@ +importScripts('./util.js'); +let result = []; + +onmessage = function(e) { + const lines = e.data.text.split('\n'); + + lines.forEach(function(line) { + if (!line) { + return; + } + + const parts = line.split('\x01'); + if (parts.length < 2) { + return; + } + + const label = parts[0]; + const coordinates = decodePolyline(parts[1]); + + coordinates.forEach(p => { + result.push({label, coordinates: p}); + }); + }); + + if (e.data.event === 'load') { + flush(); + postMessage({action: 'end'}); + } +}; + +function flush() { + postMessage({ + action: 'add', + data: result, + meta: {count: result.length} + }); + result = []; +}