So I'm trying to implement box selection in Leaflet. Currently I'm using turf's intersects function to detect if the box intersects with any of my GeoJSON polygon features.

However, this is very slow; with 180 polygons (about 500KB for GeoJSON data), it would take 3 seconds to iterate over every polygons.

I see that OpenLayers 3 has a box-selection feature which uses ol.source.Vector.prototype.forEachFeatureIntersectingExtent which in turns uses ol.geom.flat.intersectsextent.linearRing and so on.

The example that OpenLayers 3 gives has a GeoJSON source of 250KB, and it takes no time to iterate and highlight selected polygons.

Does anyone what algorithm OpenLayers uses? or is there any fast algorithm out there?

  • I suspect turf.js is the answer - see gis.stackexchange.com/a/147904/79 – Ian Turton Jul 26 '16 at 8:52
  • That's what I'm using now, but it's still not as fast as I would expect. – LoveProgramming Jul 26 '16 at 17:09
  • Use the profiling features of your web browser's developer console. Which part of the code takes more time to run? – IvanSanchez Aug 4 '16 at 11:30
  • I got everything figured out. Its actually a different part which handles data pre processing that takes a long time – LoveProgramming Aug 10 '16 at 23:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.