2011-05-11 14 views
5

Worldwind java kullanarak bir katman kurmaya çalışıyorum ve simgeleri haritada kendi coğrafi konumlarında oluşturmak istiyorum. Çalışıyorum ama tüm simgelerin olduğu yere yakınlaşmak istiyorum. Bunu yapmanın kolay bir yolu var mı? Nereden başlayacağınıza emin değilim .. Bir grup noktaya yakınlaştırma için mevcut yöntemler var mı?Worldwind haritasının yakınlaştırma düzeyini ayarlama

cevap

9

İlk önce, tüm puanlarınızı içeren Sektörü hesaplamanız gerekir. Örneğin.

Sector boundingSector = Sector.boundingSector(points); 
//public static Sector boundingSector(Iterable<? extends LatLon> itrbl) 

Şimdi burada ekranda tüm sektörü sığdırmak için gereken zoom hesaplamak için ScankortDenmark örnek alınan bazı kod:

// From ScankortDenmark example 
public static double computeZoomForExtent(Sector sector) 
{ 
    Angle delta = sector.getDeltaLat(); 
    if (sector.getDeltaLon().compareTo(delta) > 0) 
     delta = sector.getDeltaLon(); 
    double arcLength = delta.radians * Earth.WGS84_EQUATORIAL_RADIUS; 
    double fieldOfView = Configuration.getDoubleValue(AVKey.FOV, 45.0); 
    return arcLength/(2 * Math.tan(fieldOfView/2.0)); 
} 
+0

Bunu haritada nasıl kullanırım? konuma gitmek ve yükseltmeleri almak için computeZoomForExtent kullanmak için getView(). goTo() yöntemlerini kullanmak için? – MBU

+0

anladı. Teşekkürler!! – MBU

1

182Much cevabı bazı koşullarda altında çalışır. Bununla birlikte, daha iyi bir çözüm, Yatay FOV'un (Görüş Alanı) her zaman 45.0 derecelerde sabitlenmediğini dikkate almalıdır. Ayrıca Dikey FOV'u da hesaba katmalı. Kümelenme pozisyonlarının nasıl dikkate alındığı bile. Anlamı, pozisyonları Doğudan Batıya, Kuzey ve Güney'e yayılıyor. Kullanıcıların dünya görüşü (WorldWindow) aslında daha sonra cildi daha sonra cildi. Tüm konumları görmek için gerekli olan yakınlaştırma seviyesini hesaplarken bu faktörlerin hepsi hesaba katılır. Yukarıdaki tüm listelenen konumları hesaba katmak için bu statik yöntemi yarattım. Bir yan not olarak, yeryüzünüzün gerçek dünya çapını hesaplarsanız, konumlarınızın alındığı yer olan Earth.WGS84_EQUATORIAL_RADIUS yerine kümelenme eğiliminde olmanız durumunda biraz daha hassas olabilirsiniz. Ama bu neredeyse göz ardı edilebilir, ben de bu kısmı burada bırakıyorum.

/** 
* Calculates the altitude in meters needed to view all of the given points. 
* This method is safe for any window sizing configurations. If the 
* WorldWindor arg is null then a static max altitude value of 1,0667,999 
* meters is returned. if the WorldWindow is good but the list of Positions 
* is null or empty then the current zoom level of the WorldWindow is 
* returned. If the list of positions cannot all be seen on the globe 
* because some positions are on the other side of the globe then a static 
* max altitude value of 1,0667,999 meters is returned. 
* 
* @param positions 
*   - a list of positions wanted to view 
* @return the altitude in meters needed to view all of the given points. 
*/ 
public static double getZoomAltitude(List<Position> positions, WorldWindow wwd) { 
    double zoom = 10667999; 
    if (wwd != null) { 
     // Gets the current zoom as a fail safe to return 
     BasicOrbitView orbitView = (BasicOrbitView) wwd.getView(); 
     zoom = orbitView.getZoom(); 

     // zoom is in meters and and is limited the max zoom out to 10,667,999 meters 
     int MAX_ZOOM = 10667999; 

     if (positions != null && !positions.isEmpty()) { 
      Sector sector = Sector.boundingSector(positions); 
      if (sector != null) { 

       // This calculation takes into account the window sizing configuration of the map in order to accurately 
       // display the list of positions. 
       double meanRadius = Earth.WGS84_EQUATORIAL_RADIUS; 

       // Next we must calculate the zoom levels for both delta latitude viewing and delta longitude viewing. 
       // generally, a group of positions that spread out more Longitudenal viewing (wider viewing width) 
       // holds a constant 45.0 degree field of view (FOV). The horizontal FOV can be changed so this input 
       // must handle dynamically as well. The latitudenal (positon group runs more East to West then North and South) 
       // position group have a dynamic FOV that changes depending on the users sizing of the map. These have 
       // to be handled any time the group of positions has a greater delta latitude than delta longitude. 
       // Also if the user has a skinny map this will effect the output calculation and must be handled. 
       // Here we take all the dynamic variables into account for both types of possibilities and choose 
       // the larger zoom level of them. 
       int deltaLon = new BigDecimal(sector.getDeltaLon().radians * meanRadius).intValue(); 
       int deltaLat = new BigDecimal(sector.getDeltaLat().radians * meanRadius).intValue(); 
       System.out.println("deltaLonAL Wider: " + deltaLon + "\tdeltaLatAL Taller: " + deltaLat); 

       double horizontalFOV = orbitView.getFieldOfView().getDegrees(); 
       double verticalFOV = ViewUtil.computeVerticalFieldOfView(orbitView.getFieldOfView(), 
         orbitView.getViewport()).getDegrees(); 

       double lonZoomLevel = new BigDecimal((deltaLon/2.0)/(Math.tan(horizontalFOV/2.0))).intValue(); 
       double latZoomLevel = new BigDecimal((deltaLat/2.0) 
         /(Math.tan(Math.toRadians(verticalFOV)/2.0))).intValue(); 
       System.out 
         .println("LonZoomLevel Wider: " + lonZoomLevel + "\tLatZoomLevel Taller: " + latZoomLevel); 

       double zoomLevel = Math.max(lonZoomLevel, latZoomLevel); 
       System.out.println("zoomLevel meters: " + zoomLevel + "\tfeet: " 
         + new BigDecimal(zoomLevel * 3.2808)); 

       // zoom is the altitude measured in meters to view a given area calculated to fit the viewing 
       // window edge to edge. A buffer is needed around the area for visual appeal. The bufferedZoom 
       // is a calculated linear equation (y = 1.0338x + 96177 where R² = 1) It gives the same buffer 
       // boundary around a group of position depending on the calculated zoom altitude. 
       double bufferedZoom = 1.0338 * zoomLevel + 96177; 
       zoom = new BigDecimal(bufferedZoom).intValue(); 

       if (zoom > MAX_ZOOM) { 
        zoom = MAX_ZOOM; 
        System.out.println("MAX_ZOOM applied"); 
       } 
      } 
     } else { 
      System.out.println("getZoomAltitude method cannot calculate the zoom because the points passed in was null and the current zoom was returned."); 
     } 
    } 
    return zoom; 
} 
İlgili konular