Skip to content

Commit

Permalink
Fix google maps circle to polygon conversion
Browse files Browse the repository at this point in the history
When converting a large google maps circle (e.g. a circle covering Africa) to a WKT polygon the first and last coordinate of the output are not exactly the same, this causes issues when using it in other libraries. In my case JSTS complains that the linestring is not closed. This is an example of such a converted circle: POLYGON((71.69991307132003 0.9262704706813841,...,71.69991307132003 0.9262704706813717)).
To ensure the calculated polygon is closed the last vertex will no longer be calculated but copied over from the first vertex.
  • Loading branch information
Martin Gotink committed Jul 23, 2019
1 parent cfef6b6 commit ac5067a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion wicket-gmap3.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@
var rlat = (radius / earthsradius) * r2d;
var rlng = rlat / Math.cos(point.lat() * d2r);

for (var n = 0; n <= num_seg; n++) {
for (var n = 0; n < num_seg; n++) {
var theta = Math.PI * (n / (num_seg / 2));
lng = point.lng() + (rlng * Math.cos(theta)); // center a + radius x * cos(theta)
lat = point.lat() + (rlat * Math.sin(theta)); // center b + radius y * sin(theta)
Expand All @@ -412,6 +412,7 @@
y: lat
});
}
verts.push(verts[0]);

response = {
type: 'polygon',
Expand Down

0 comments on commit ac5067a

Please sign in to comment.