最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - react-leaflet too many markers causes page to freeze - Stack Overflow

programmeradmin3浏览0评论

I'm using react-leftlet to display markers in many counties. As you can see I'm mapping about 53K markers. The problem is that after I render these markers the webpage is practically unusable and it often freezes. Is there a way around this leaflet limitation? Is there a better way to display this many markers? Im using GeoJson as a data source. This is how I'm rendering these points:

<GeoJSON
   key={_.uniqueId()}
   data= {this.props.countrySelected.geojson}
   pointToLayer={this.pointToLayer.bind(this)}
></GeoJSON>

Here is the pointToLayer Function:

  pointToLayer = (feature, latlng) => {
// console.log(feature.properties);
return L.circleMarker(latlng, {
  color: this.getStyle(feature.properties.speed_connectivity, feature.properties.type_connectivity),
  fillColor: this.getStyle(feature.properties.speed_connectivity),
  fillOpacity: .6,
  radius: 1
}).bindPopup(popUpString(feature.properties)); // Change marker to circle

}

Update using heat map:

<HeatmapLayer
            fitBoundsOnLoad
            fitBoundsOnUpdate
            points={this.props.countrySelected.geojson}
            longitudeExtractor={m => m.geometry.coordinates[1]}
            latitudeExtractor={m => m.geometry.coordinates[1]}
            intensityExtractor={m => parseFloat(m.properties.speed_connectivity)}
          />

I'm using react-leftlet to display markers in many counties. As you can see I'm mapping about 53K markers. The problem is that after I render these markers the webpage is practically unusable and it often freezes. Is there a way around this leaflet limitation? Is there a better way to display this many markers? Im using GeoJson as a data source. This is how I'm rendering these points:

<GeoJSON
   key={_.uniqueId()}
   data= {this.props.countrySelected.geojson}
   pointToLayer={this.pointToLayer.bind(this)}
></GeoJSON>

Here is the pointToLayer Function:

  pointToLayer = (feature, latlng) => {
// console.log(feature.properties);
return L.circleMarker(latlng, {
  color: this.getStyle(feature.properties.speed_connectivity, feature.properties.type_connectivity),
  fillColor: this.getStyle(feature.properties.speed_connectivity),
  fillOpacity: .6,
  radius: 1
}).bindPopup(popUpString(feature.properties)); // Change marker to circle

}

Update using heat map:

<HeatmapLayer
            fitBoundsOnLoad
            fitBoundsOnUpdate
            points={this.props.countrySelected.geojson}
            longitudeExtractor={m => m.geometry.coordinates[1]}
            latitudeExtractor={m => m.geometry.coordinates[1]}
            intensityExtractor={m => parseFloat(m.properties.speed_connectivity)}
          />
Share Improve this question edited Oct 17, 2017 at 18:30 Fredy asked Oct 16, 2017 at 18:39 FredyFredy 2,0632 gold badges24 silver badges43 bronze badges 2
  • I do not exactly know react-leaflet, but if you can use the map preferCanvas option and display your points as Circle Markers, this should help you: stackoverflow./questions/43015854/… – ghybs Commented Oct 16, 2017 at 18:47
  • Thanks for you reply, I am actually doing that. I have edited my post to reflect that. Take a look at the code above! Thanks!! – Fredy Commented Oct 16, 2017 at 18:53
Add a ment  | 

2 Answers 2

Reset to default 4

Yeah, the performance is going to be terrible with that many markers. I'd remend using either react-leaflet-markercluster or react-leaflet-heatmap-layer.

If you want to keep points on the map you can use a WebGL canvas overlay, there's an example implementation of it here

发布评论

评论列表(0)

  1. 暂无评论