Leaflet.glify
Leaflet.glify copied to clipboard
Fix hole to non-hole vertex border draw bug
Discussion
Polygons with holes draw a border between the last and first vertices of consequent holes. This is because lines are getting drawn between every vertex in a polygon. This makes polygons with many holes have many border lines connecting all the holes. This addition uses the earcut flat.holes
array to skip drawing a border between the last outer polygon vertex and the first hole vertex, as well as the last vertex of any hole and the first vertex of the next hole.
Example
The simple polygon with a hole below can be used an as example. Without this PR, there is a line between one of the corners of the polygon to one of the corners of the hole. With the PR that line is not drawn.
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
6.767578125,
46.619261036171515
],
[
13.447265624999998,
46.619261036171515
],
[
13.447265624999998,
51.12421275782688
],
[
6.767578125,
51.12421275782688
],
[
6.767578125,
46.619261036171515
]
],
[[
7.998046875,
47.45780853075031
],
[
12.392578125,
47.45780853075031
],
[
12.392578125,
50.14874640066278
],
[
7.998046875,
50.14874640066278
],
[
7.998046875,
47.45780853075031
]]
]
}
}
]
}
maybe just judge the vertex index, should fix this bug. As below: add to shapes.ts after line 239 if (flat.holes.includes((i + 1) / 2)) continue;
both solutions seem to work!
It seems like it would be much slower to call .includes
every iteration of the for loop when you know which element you are checking for each time, that's why I used holeIndex
. @YHLpuyu 's ((i + 1) / 2)
formulation is great so maybe changing line 242 of my commit to if(((i + 1) / 2) !== flat.holes[holeIndex]) {
would be fastest?