Skip to content

fix: remove polygons with fewer than 3 points after simplification#2204

Closed
rekire wants to merge 1 commit into
fleaflet:masterfrom
rekire:remove_tiny_polygons
Closed

fix: remove polygons with fewer than 3 points after simplification#2204
rekire wants to merge 1 commit into
fleaflet:masterfrom
rekire:remove_tiny_polygons

Conversation

@rekire

@rekire rekire commented Apr 26, 2026

Copy link
Copy Markdown

When you have a (multi) polygon with lots of tiny polygons the simplification can shrink a polygon to e.g. two points, this will cause a this assertion error:

The following assertion was thrown while handling a pointer data packet: not a polygon 'package:flutter_map/src/misc/point_in_polygon.dart': Failed assertion: line 10 pos 10: 'len >= 3'
When the exception was thrown, this was the stack:
#2 isPointInPolygon (package:flutter_map/src/misc/point_in_polygon.dart:10:10)
#3 _PolygonPainter.elementHitTest.<anonymous> (package:flutter_map/src/layer/polygon_layer/painter.dart:85:17)
#4 _PolygonPainter.elementHitTest (package:flutter_map/src/layer/polygon_layer/painter.dart:90:10)
#5 HitDetectablePainter.hitTest (package:flutter_map/src/layer/shared/layer_interactivity/internal_hit_detectable.dart:75:11)
#6 HitTestRequiresCameraOrigin.hitTest (package:flutter_map/src/layer/shared/layer_interactivity/internal_hit_detectable.dart:112:18)
#7 RenderCustomPaint.hitTestSelf (package:flutter/src/rendering/custom_paint.dart:569:43)
#8 RenderBox.hitTest (package:flutter/src/rendering/box.dart:2953:58)</anonymous>

My fix simply removes those polygons entirely. That happens when you hover a PolygonLayer as workaround you can use simplificationTolerance: 0 but that is based on the geometry quite bad for the performance.

This change fixes this assertion error:

The following assertion was thrown while handling a pointer data packet: not a polygon 'package:flutter_map/src/misc/point_in_polygon.dart': Failed assertion: line 10 pos 10: 'len >= 3' When the exception was thrown, this was the stack: fleaflet#2 isPointInPolygon (package:flutter_map/src/misc/point_in_polygon.dart:10:10) fleaflet#3 _PolygonPainter.elementHitTest.<anonymous> (package:flutter_map/src/layer/polygon_layer/painter.dart:85:17) fleaflet#4 _PolygonPainter.elementHitTest (package:flutter_map/src/layer/polygon_layer/painter.dart:90:10) fleaflet#5 HitDetectablePainter.hitTest (package:flutter_map/src/layer/shared/layer_interactivity/internal_hit_detectable.dart:75:11) fleaflet#6 HitTestRequiresCameraOrigin.hitTest (package:flutter_map/src/layer/shared/layer_interactivity/internal_hit_detectable.dart:112:18) fleaflet#7 RenderCustomPaint.hitTestSelf (package:flutter/src/rendering/custom_paint.dart:569:43) fleaflet#8 RenderBox.hitTest (package:flutter/src/rendering/box.dart:2953:58)</anonymous>
@JaffaKetchup JaffaKetchup requested a review from a team June 30, 2026 15:39
@JaffaKetchup JaffaKetchup changed the title Remove polygons with less then 3 points after simplification fix: remove polygons with fewer than 3 points after simplification Jul 1, 2026
@JaffaKetchup

Copy link
Copy Markdown
Member

Hi @rekire,
This was already reported a while ago by #1933 and fixed by #1964, released in v8. Could you please confirm that you are seeing this issue in the latest version, and if so, please open a new bug report.
I think it was decided that it's better just to exclude these from hit-testing rather than remove them visually altogether (as if they have a border stroke, for example, they may still be visible?).

@JaffaKetchup JaffaKetchup removed the request for review from a team July 1, 2026 17:41
@rekire

rekire commented Jul 1, 2026

Copy link
Copy Markdown
Author

I'm using my fork right now to avoid this issue. In my pubspec.yaml is flutter_map: ^7.0.2... I am some major versions behind and I cannot remember right now why. Maybe some incompatible dependencies. I'll try to find it out. I will inform you with the results with a new comment.

@rekire

rekire commented Jul 1, 2026

Copy link
Copy Markdown
Author

Okay I found it out: I am using vector_map_tiles which requires that old version and the latest beta does not compile at the moment. So the real issue is that I am using a very old version.

@JaffaKetchup

Copy link
Copy Markdown
Member

Ah no worries :) Thanks for contributing anyway, and please feel free to again in future!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants