×

First time here?

You are looking at the most recent posts. You may also want to check out older archives. Please leave a comment, ask a question and consider subscribing to the latest posts via RSS or email. Thank you for visiting!

as i continue to build on top of my virtual earth example that uses proximity searching, i found myself wanting to add more visualization to the mix.  i wanted the radius being searched to actually show a radius ring for the area...so the user could see the proximity being searched where the results are plotted.

so, i started digging -- how do you draw a circle using the polyline api?  hmmm...rounded corners with straight lines...seemed like a challenge.

well after a prod to some people i was pointed to a solution already doing this!

and thus the had the answer.  basically it is a javascript function like this:

1:  function addCircle(polyname, latin, lonin, radius, vecolor, linewidth)
2:  {
3:      var locs = new Array();
4:      var lat1 = latin * Math.PI/180.0;
5:      var lon1 = lonin * Math.PI/180.0;
6:      var d = radius/3956;
7:      var x;
8:      for (x = 0; x <= 360; x++)
9:      {
10:          var tc = (x / 90)* Math.PI / 2;
11:          var lat = Math.asin(Math.sin(lat1)*Math.cos(d)+Math.cos(lat1)*Math.sin(d)*Math.cos(tc));
12:          lat = 180.0 * lat / Math.PI;
13:          var lon;
14:           if (Math.cos(lat1)==0)
15:          {
16:              lon=lonin; // endpoint a pole
17:          }
18:          else
19:          {
20:              lon = ((lon1 - Math.asin(Math.sin(tc) * Math.sin(d)/Math.cos(lat1)) + Math.PI) % (2 * Math.PI)) - Math.PI;
21:          }
22:          lon = 180.0 * lon / Math.PI;
23:          var loc = new VELatLong(lat,lon);
24:          locs.push(loc);
25:      }
26:      var poly = new VEPolyline(polyname, locs, vecolor , linewidth);
27:      return poly;
28:  }

(note: the 3956 indicates this is miles...if you need km, then you'd have to adjust the earth radius setting to be km instead)

now that i add that to my code, i simply call:

and have a radius drawn around my resulted plot points. the beauty is that as with everything, this applies to the 3d views as well: very cool -- hope this helps others as well.

DISCLAIMER:

The opinions/content expressed on this blog are provided "ASIS" with no warranties and are my own personal opinions/content (unless otherwise noted) and do not represent my employer's view in any way.