본문 바로가기

개발자공부/Openlayers

[openlayers]오픈레이어스 두 점사이 거리 계산, 해당 반경지점 만큼 원 그리기


var wgs84Sphere= new ol.Sphere(6378137); //http://openlayers.org/en/latest/apidoc/ol.Sphere.html 참고

var distance = wgs84Sphere.haversineDistance(ol.proj.transform(coor1, "EPSG:900913",'EPSG:4326'),ol.proj.transform(coor2, "EPSG:900913",'EPSG:4326'))



 new ol.Sphere(6378137);
WGS84 의 Sphere 객체 생성인것 같다...
해당 좌표계를 EPSG:4326 형태로 변경해서 계산해야지 거리 계산이 제대로 나오는것 같다.

127.21427295387993,36.824764450213365 과 127.27195117653619,36.82388502496384의 거리계산

거리값 = 5140.563071054223  M 단위..



반경 원 그리기

https://stackoverflow.com/questions/23264721/how-to-draw-circle-with-radius-in-openlayers


검색하다가 찾음....

 

반지름 계산

맵 객체 , 반지름 지정값 (m), 좌표값

     

var drawMeter = function(map, radius, cood) {

                         var view = map.getView(); // 맴객체의

                         var projection = view.getProjection(); // 프로젝션 정보를 가지고옴 EPGS:3857

                         var resolutionAtEquator = view.getResolution(); //해상도

                         //var pointResolution = projection.getPointResolution(resolutionAtEquator, cood); //점포인트의 해상도 Openlayers 3버전??

                         var pointResolution = ol.proj.getPointResolution(projection,resolutionAtEquator, cood); //점포인트의 해상도 Openlayers 4버전??

                        

                        

                         var resolutionFactor = resolutionAtEquator/pointResolution; //

                         var radius = (radius / ol.proj.METERS_PER_UNIT.m) * resolutionFactor;

                         return radius;

 }