[OpenLayers-Users] Greater circle

adityakumar529 adityakumar529 at gmail.com
Thu Jan 15 06:07:49 PST 2015


Hi Users,
   I am working on greater circle algorithm.
Following the code I used.
 var lonlat = map.getLonLatFromPixel(e.xy);
////alert("You clicked near " + lonlat.lat + " N, " +
                                          //    + lonlat.lon + " E");
											  x1=lonlat.lat;
				//alert(x1);
				y1= lonlat.lon;
				//alert(y1);
				 
 x1 = x1 * DEG2RAD
  y1 = y1 * DEG2RAD
  x2 = x2 * DEG2RAD
  y2 = y2 * DEG2RAD
  
  a = (Math.cos(y2) * Math.sin(x2 - x1));
  b = (Math.cos(y1) * Math.sin(y2) - Math.sin(y1) * Math.cos(y2) *
Math.cos(x2 - x1));
  var adjust = 0
    
  if((a == 0) && (b == 0)) {
      bearing = 0
  } else if( b == 0) {
      if( a < 0)  
          bearing = (3 * PI / 2)
      else
          bearing = (PI / 2)
  } else if( b < 0) 
      adjust = PI
  else {
      if( a < 0) 
          adjust = (2 * PI)
      else
          adjust = 0
  }
  bearing = ((a*Math.tan(a/b) + adjust) * RAD2DEG);

////alert(bearing);

  x1 = x1 * DEG2RAD;
  y1 = y1 * DEG2RAD;
  bearing = bearing * DEG2RAD;
////alert(bearing);
  // Convert arc distance to radians
  c = 0.149129 / EARTH_RADIUS;
  

  y2 = a*Math.sin( Math.sin(y1) * Math.cos(c) + Math.cos(y1) * Math.sin(c) *
Math.cos(bearing)) * RAD2DEG


  a = (Math.sin(c) * Math.sin(bearing));
  b = (Math.cos(y1) * Math.cos(c) - Math.sin(y1) * Math.sin(c) *
Math.cos(bearing));

 
      x2 = x1 + a*Math.tan(a/b) * RAD2DEG;

x2= x2+lonlat.lat;
y2 = y2+lonlat.lon;


Here x2 and y2 are two new points I am getting after every click.
But I want to bring it in loop such that in first click then x2,y2 comes it
should automatically consider the x2,y2 and the new point for click and move
further in the loop.

Thanks
Aditya Kumar



-----
GIS Developer

--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Greater-circle-tp5181682.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.


More information about the Users mailing list