2010-09-20 13 views

Répondre

0

Oui, il est possible de tracer un cercle sur la carte. Vous pouvez le faire en calculant les points qui composent les points. Le code suivant prend un VELatLong pour le point central et un rayon en kilomètres. Il renvoie un objet VEShapeType.Polygon. Vous pouvez ensuite ajouter cette forme à la carte en utilisant map.AddShape().

Code Snippet:

function AddCircle(latlong, radius) 
{ 
    var R = 6371; // earth's mean radius in km 
    var lat = (latlong.Latitude * Math.PI)/180; //rad 
    var lon = (latlong.Longitude * Math.PI)/180; //rad 
    var d = parseFloat(radius)/R; // d = angular distance covered on earth's surface 
    var points= new Array(); 
    for (x = 0; x <= 360; x++) 
    { 
     var p2 = new VELatLong(0,0)   
     brng = x * Math.PI/180; //rad 
     p2.Latitude = Math.asin(Math.sin(lat)*Math.cos(d) + Math.cos(lat)*Math.sin(d)*Math.cos(brng)); 
     p2.Longitude = ((lon + Math.atan2(Math.sin(brng)*Math.sin(d)*Math.cos(lat), Math.cos(d)-Math.sin(lat)*Math.sin(p2.Latitude))) * 180)/Math.PI; 
     p2.Latitude = (p2.Latitude * 180)/Math.PI; 
     points.push(p2); 
    } 
    var poly = new VEShape(VEShapeType.Polyline, points); 
    return poly; 
} 
Questions connexes