forked from visgl/deck.gl
-
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.
Restore IconLayer Example (visgl#664)
- Loading branch information
1 parent
896a3f5
commit 0eb3dc1
Showing
10 changed files
with
65,652 additions
and
35,962 deletions.
There are no files selected for viewing
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,150 @@ | ||
import React, {Component} from 'react'; | ||
import {MAPBOX_STYLES} from '../../constants/defaults'; | ||
import {readableInteger} from '../../utils/format-utils'; | ||
import IconOverlay from '../../../../examples/icon/deckgl-overlay'; | ||
|
||
function stopPropagation(evt) { | ||
evt.stopPropagation(); | ||
} | ||
|
||
export default class IconDemo extends Component { | ||
|
||
static get data() { | ||
return [ | ||
{ | ||
url: 'data/meteorites.txt', | ||
worker: 'workers/meteorites-decoder.js' | ||
}, | ||
{ | ||
url: 'images/location-icon-mapping.json' | ||
} | ||
]; | ||
} | ||
|
||
static get parameters() { | ||
return { | ||
cluster: {displayName: 'Cluster', type: 'checkbox', value: true} | ||
}; | ||
} | ||
|
||
static get viewport() { | ||
return { | ||
...IconOverlay.defaultViewport, | ||
perspectiveEnabled: false, | ||
mapStyle: MAPBOX_STYLES.DARK | ||
}; | ||
} | ||
|
||
static renderInfo(meta) { | ||
return ( | ||
<div> | ||
<h3>Meteorites Landings</h3> | ||
<p>Data set from The Meteoritical Society showing information on all of | ||
the known meteorite landings.</p> | ||
<p>Hover on a pin to see the list of names</p> | ||
<p>Click on a pin to see the details</p> | ||
<p>Data source: | ||
<a href="https://data.nasa.gov/Space-Science/Meteorite-Landings/gh4g-9sfh">NASA</a> | ||
</p> | ||
<div className="layout"> | ||
<div className="stat col-1-2">No. of Meteorites | ||
<b>{ readableInteger(meta.count || 0) }</b> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
x: 0, | ||
y: 0, | ||
hoveredItems: null, | ||
expanded: false | ||
}; | ||
} | ||
|
||
_onHover({x, y, object}) { | ||
const {viewport, params} = this.props; | ||
const z = Math.floor(viewport.zoom); | ||
const showCluster = params.cluster.value; | ||
|
||
let hoveredItems = null; | ||
|
||
if (object) { | ||
if (showCluster) { | ||
hoveredItems = object.zoomLevels[z].points.sort((m1, m2) => m1.year - m2.year); | ||
} else { | ||
hoveredItems = [object]; | ||
} | ||
} | ||
|
||
this.setState({x, y, hoveredItems, expanded: false}); | ||
} | ||
|
||
_onClick() { | ||
this.setState({expanded: true}); | ||
} | ||
|
||
_renderhoveredItems() { | ||
const {x, y, hoveredItems, expanded} = this.state; | ||
|
||
if (!hoveredItems) { | ||
return null; | ||
} | ||
|
||
if (expanded) { | ||
return ( | ||
<div className="tooltip interactive" | ||
style={{left: x, top: y}} | ||
onWheel={stopPropagation} | ||
onMouseDown={stopPropagation}> | ||
{ | ||
hoveredItems.map(({name, year, mass, class: meteorClass}) => { | ||
return ( | ||
<div key={name}> | ||
<h5>{name}</h5> | ||
<div>Year: {year || 'unknown'}</div> | ||
<div>Class: {meteorClass}</div> | ||
<div>Mass: {mass}g</div> | ||
</div> | ||
); | ||
}) | ||
} | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="tooltip" style={{left: x, top: y}} > | ||
{ hoveredItems.slice(0, 20).map(({name, year}) => | ||
<div key={name}><h5>{name} {year ? `(${year})` : ''}</h5></div>) } | ||
</div> | ||
); | ||
} | ||
|
||
render() { | ||
const {viewport, params, data} = this.props; | ||
const {hoveredItems} = this.state; | ||
|
||
if (!data) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className={`icon-demo ${hoveredItems ? 'clickable' : ''}`}> | ||
<IconOverlay viewport={viewport} | ||
data={data[0]} | ||
iconAtlas="images/location-icon-atlas.png" | ||
iconMapping={data[1]} | ||
showCluster={params.cluster.value} | ||
onHover={this._onHover.bind(this)} | ||
onClick={this._onClick.bind(this)} /> | ||
|
||
{ this._renderhoveredItems() } | ||
</div> | ||
); | ||
} | ||
} |
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
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
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,45 @@ | ||
importScripts('./util.js'); | ||
let coordinates; | ||
let result = []; | ||
|
||
onmessage = function(e) { | ||
const lines = e.data.text.split('\n'); | ||
|
||
lines.forEach(function(line) { | ||
if (!line) { | ||
return; | ||
} | ||
if (!coordinates) { | ||
coordinates = decodePolyline(line, 5); | ||
return; | ||
} | ||
|
||
const parts = line.split('\t'); | ||
if (parts.length < 5) { | ||
return; | ||
} | ||
|
||
result.push({ | ||
name: parts[0], | ||
class: parts[1], | ||
coordinates: coordinates[decodeNumber(parts[2], 90, 32)], | ||
mass: decodeNumber(parts[3], 90, 32), | ||
year: decodeNumber(parts[4], 90, 32) | ||
}) | ||
|
||
}); | ||
|
||
if (e.data.event === 'load') { | ||
flush(); | ||
postMessage({action: 'end'}); | ||
} | ||
}; | ||
|
||
function flush() { | ||
postMessage({ | ||
action: 'add', | ||
data: result, | ||
meta: {count: result.length} | ||
}); | ||
result = []; | ||
} |
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
Oops, something went wrong.