question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Initial position issue

See original GitHub issue

Hi,

I see animation on first pass. fitBounds don’t change. Why?

const markerLocation = [ displayLocation[1], displayLocation[0] ]; // <lng>, <lat>

<ReactMapboxGl style="mapbox://styles/mapbox/dark-v9"
    accessToken={ accessToken }
    containerStyle={{ height: '100%' }} 
    interactive={ false }
    fitBounds={ this.getBounds(displayLocation) }
    fitBoundsOptions={ {offset: [0, -100]} }>
  <Layer type="symbol" id="marker" layout={{ 'icon-image': 'marker-15' }}>
    <Feature coordinates={ markerLocation } />
  </Layer>
</ReactMapboxGl>

Looking through the code but can’t really figure out what’s going on: https://github.com/alex3165/react-mapbox-gl/blob/master/src/map.tsx#L140

PS: setting center breaks fitBounds.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:19 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
pronebirdcommented, Mar 3, 2017

While this issue has been resolved. fitBounds still animates on first pass. I solved that by disabling animation during first render:

  constructor() {
    super();
    this.state = { isFirstPass: true };
  }

  componentDidMount() {
    this.setState({ isFirstPass: false });
  }

  componentWillUnmount() {
    this.setState({ isFirstPass: true });
  }

render() {
  const ruler = cheapRuler(center[0], 'meters');

  // calculate bounds with cheap-ruler
  const bounds = ruler.bufferPoint([40.741895, -73.989308], 300);
  
  // convert lat/lng to lng/lat
  let mapBounds = [];
  for(let i = 0; i < bounds.length; i += 2) {
    mapBounds.push(bounds.slice(i, i + 2).reverse());
  }

  const mapBoundsOptions = { offset: [0, -100], animate: !this.state.isFirstPass };
  // ...
}
1reaction
alex3165commented, Feb 23, 2017

Yep seems reasonable, I will publish a patch with the update

Read more comments on GitHub >

github_iconTop Results From Across the Web

Initial position · Issue #80 · daybrush/moveable - GitHub
I'm creating an editor, so I need to load my elements to the page dynamically. So the question is how properly to set...
Read more >
d3-drag with html elements initial position issue - Stack Overflow
In the snippet below I have div , when I first start draging the div around it jumps slightly to the right, making...
Read more >
position - CSS: Cascading Style Sheets - MDN Web Docs
The position CSS property sets how an element is positioned in a document. The top, right, bottom, and left properties determine the final ......
Read more >
CSS position: sticky scroll initial position into view
For the purposes of any operation targetting the scroll position of a sticky positioned element (or one of its descendants), the sticky ...
Read more >
Initial Position Definition | Law Insider
Initial Position means the amount of Registrable Securities owned by a Participating Shareholder as of the Effective Date, as set forth on Schedule...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found