Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
How can I find all the coordinates in a Mapbox Draw circle using center and radius?

I have a Mapbox map and would like to get all the coordinates in an array of a circle that I custom drew using MapboxDraw.

This function takes the center of the circle, then by calculating the coordinates of the circle edges it decides which coordinates are in the circle and fills the array and then displayed via console log.

 <script>
           function CircleCoordinate(shape,shapeId)  {
            var Circlecoords = '';
            var standard = 0.00001;
            var center = shape.layer._latlng;
            var centerPointlng = center.lng;
            var centerPointlat = center.lat;
            var latPoint = centerPointlat;
            var lngPoint = centerPointlng;
            var radius = shape.layer._mRadius;
            
            for(var a = 0; a <= 360; a++)
            {
            
            var radiusPointlat = radius* Math.cos(a)+centerPointlat;
            var radiusPointlng = radius* Math.sin(a)+centerPointlng;
    
            for(var j = centerPointlng; j < radiusPointlng; j += standard)
              {
                //  console.log("radiusPointlat?????       ", radiusPointlat);
                 for(var i = centerPointlat;i < radiusPointlat; i += standard)
                {
                  // console.log("IS ITTTTT?????       ", isInside(centerPointlng, centerPointlat, radius, lngPoint, latPoint));
                if (isInside(centerPointlng, centerPointlat, radius, lngPoint, latPoint))
                {
                   Circlecoords +=  '('+latPoint + ',' + lngPoint + '),';
                }
                latPoint += standard;
              }
              lngPoint += standard;
              }
            }
    </script>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Also take a look at the functions provided by http://turfjs.org/, which might be helpful, particularly http://turfjs.org/docs/#circle http://turfjs.org/docs/#pointGrid and http://turfjs.org/docs/#pointsWithinPolygon

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!