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!
1: function addCircle(polyname, latin, lonin, radius, vecolor, linewidth)
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++)
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)
16: lon=lonin; // endpoint a pole
20: lon = ((lon1 - Math.asin(Math.sin(tc) * Math.sin(d)/Math.cos(lat1)) + Math.PI) % (2 * Math.PI)) - Math.PI;
22: lon = 180.0 * lon / Math.PI;
23: var loc = new VELatLong(lat,lon);
26: var poly = new VEPolyline(polyname, locs, vecolor , linewidth);
27: return poly;
(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:
1: map.AddPolyline(addCircle("SearchRadius", center.Latitude, center.Longitude, $get("MilesRadius").value, new VEColor(255,0,0,1), 4));
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.