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.

Is it possible to draw features on top of other features without re-rendering the original features?

See original GitHub issue

Hi, I understand that the topic question might be a bit confusing. Here is a clarification of what I am now doing:

  1. I draw 10,000 features (circles) on a map.
  2. I draw another 10,000 circles on a map and it erases the original 10k circles.

I know that I can keep an array and continuously push to it, e.g.

  1. Draw the original 10k circles on the map from an array points.
  2. Push the next 10k circles into points and draw all 20k circles.

This isn’t my goal because I don’t want to redraw the original points on the map. My reason for drawing the circles 10k at a time is due to performance optimizations and other constraints.

So here’s my question: Can I draw the new 10k circles on the map without erasing/redrawing the original 10k points?

Also if anyone has other ideas for the issue title then I’ll gladly change it. Just couldn’t think of a better one!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
mklopetscommented, Jul 8, 2019

I might have initially misunderstood your problem a bit.

What you can do is have two separate layers on the map, one for each of your network fetches.

{
  this.state.pointsA && (
    <Layer id="points-a" type="circle" paint={{ 'circle-color': 'red', 'circle-radius': 5 }}>
      {this.state.pointsA.map((point) => (
        <Feature coordinates={[point.coordinates]} />
      ))}
    </Layer>
  )
}
{
  this.state.pointsB && (
    <Layer id="points-b" type="circle" paint={{ 'circle-color': 'red', 'circle-radius': 5 }}>
      {this.state.pointsB.map((point) => (
        <Feature coordinates={[point.coordinates]} />
      ))}
    </Layer>
  )
}

Now, if pointsB appears in the state (after a network request), react-mapbox-gl will only create that layer, keeping the points-a layer as-is.

0reactions
mklopetscommented, Jul 9, 2019

The reason for suggesting the two layers was that it should be slightly more performant, because mapbox doesn’t have to initialize the first set of points twice. In general yes, just pushing to an array in the component state is definitely the easiest way to add data from two network requests.

Mapbox itself has some docs on optimizing for large data sets: https://docs.mapbox.com/help/troubleshooting/working-with-large-geojson-data/

Read more comments on GitHub >

github_iconTop Results From Across the Web

5 Ways to Avoid React Component Re-Renderings
It is commonly used with Redux stores and has amazing features to reduce unnecessary re-renderings. Reselect selectors are capable of computing derived data ......
Read more >
Just Say No to Excessive Re-Rendering in React - GrapeCity
In this article, we will address instances of excessive re-rendering in React applications and demonstrate how to avoid them.
Read more >
Update search params without re-rendering everything · Issue ...
In short, the app updates query-string parameters (e.g., selected object id in a table) so if the user reloads the browser, or copies...
Read more >
When does React re-render components? - Felix Gerschau
This process of comparing the old VDOM with the new one is called diffing. Real DOM updates are slow because they cause an...
Read more >
Feature Toggles (aka Feature Flags) - Martin Fowler
Feature Toggles (often also refered to as Feature Flags) are a powerful technique, allowing teams to modify system behavior without changing code.
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