From ac5067aa35b242013a820a0447c9d46d466219d7 Mon Sep 17 00:00:00 2001 From: Martin Gotink Date: Tue, 23 Jul 2019 09:26:44 +0200 Subject: [PATCH] Fix google maps circle to polygon conversion 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. --- wicket-gmap3.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wicket-gmap3.js b/wicket-gmap3.js index 1c9ee2c..ef5e2ae 100644 --- a/wicket-gmap3.js +++ b/wicket-gmap3.js @@ -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) @@ -412,6 +412,7 @@ y: lat }); } + verts.push(verts[0]); response = { type: 'polygon',