deck.gl icon indicating copy to clipboard operation
deck.gl copied to clipboard

The updated Hexagon bars start from shorter elevation than the height in the former state when doing transitions in 3d-heatmap layer

Open ricardoCyy opened this issue 8 years ago • 3 comments

Actual Result

Actual Result As is shown above, I use a 'time slider' to upload points data in an aggregating layer hour-by-hour, but I met with two issues:

  1. After data get uploaded(this.setState(data : newdata)) from the former state to the current state, in some cells there weren't any point in the former state but have some in the current state, and instead of transition they just shows up. And when there are points in former state and now have nothing, the bars disappear immediately.
  2. After data get uploaded(this.setState(data : newdata)) from the former state to the current state, in some cells where they have points in both states, when they were doing the transition the bars don't transform from where they exactly were but from somewhere lower(or even higher) than the former height to current height(current heights are correct), which makes the transition rough rather than smooth.

Expected Result

  1. When data gets updated transition the current bars from the exact current heights to the new heights.
  2. Bars not disappear/show up immidiately in some cells when data updated(from some value -> 0 OR from 0 -> some value).

Is there any chance my layer could transits as smooth as this project? Expect Result

Code Example

#function to update data when time slider change _handleChange(event) { this.setState({value: event.target.value}); const DATA_URL=this.state.Station+'/'+event.target.value+'.csv'; require('d3-request').csv(DATA_URL, (error, response) => { if (!error) { const data = response.map(d => [Number(d.lng), Number(d.lat)]); console.log() this.setState({DATA_URL:DATA_URL,data: data}); } }); }

#how I set up my layer _renderLayers() { const {radius = 200, upperPercentile = 100, coverage = 0.8} = this.props; const {data} = this.state; return [ new HexagonLayer({ id: 'heatmap', colorDomain: [0,100],//30:[0,460] 27:[0,300] daily:[0,45]v0:[1,360] colorRange, coverage, data, elevationDomain: [0,100], elevationRange: [0, 320],//[0,250] elevationScale: this.state.elevationScale, extruded: true, getPosition: d => d, lightSettings: LIGHT_SETTINGS, onHover: this._onHover, opacity: 1, pickable: true, radius, upperPercentile, transitions:{ // getColorValue: { // duration: 1000, // easing: d3.easeCubicInOut // }, getElevationValue: { duration: 950, easing: d3.easeCubicInOut, } } }) ]; }

render() { const {viewState, controller = true, baseMap = true} = this.props; const {data} = this.state; return (

	  <DeckGL
		layers={this._renderLayers()}
		initialViewState={INITIAL_VIEW_STATE}
		viewState={viewState}
		controller={controller}
		data={data}
	  >
		{baseMap && (
		  <StaticMap
			reuseMaps
			mapStyle="mapbox://styles/mapbox/dark-v9"
			preventStyleDiffing={true}
			mapboxApiAccessToken={MAPBOX_TOKEN}
		  />
		)}
	  </DeckGL>
	</div>
            ......
            <div>
                <input type='range' id='time'  min="0" max="767" value={this.state.value} className="slider" onChange={this._handleChange.bind(this)} step="1"/>
          </div>
  </div>

)}

ricardoCyy avatar Sep 18 '18 15:09 ricardoCyy

@ricardoCyy To get the proper transition effect that you are after, the hexagons generated by HexagonLayer must be of the same count and in the same order.

Instead of updating the data prop hour-by-hour, you pass all the data points together, so that the hexagons covered by your data are generated once and never change. Then, every time the user operates the slider, you update the getElevationValue prop like this:


// Called when user manipulates the slider
_updateTimeWindow([start, end]) {
	this.setState({
		getHexagonElevationValue: points =>
			// `points` are all the objects that fall into this bin
            // Count the ones that are within the current time window
			points.filter(p => p.time >= start && p.time < end).length
	});
}

_renderLayers() {
	return [
		new HexagonLayer({
		  // other props stay the same...
		  getElevationValue: this.state.getHexagonElevationValue
		})
	];
}

This way, each hexagon always has a height (might be 0) to transition to/from wherever the time window moves to.

@heshan0131

Pessimistress avatar Sep 18 '18 20:09 Pessimistress

Great answer, Maybe add FAQ label on this issue?

ibgreen avatar Sep 18 '18 21:09 ibgreen

It worked! thx! @Pessimistress

ricardoCyy avatar Sep 19 '18 16:09 ricardoCyy