博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

overlayItems 全部显示

Posted on 2011-10-25 05:38  linFen  阅读(499)  评论(0编辑  收藏  举报

如果有时间加了很多overlayItem,由于缩放问题 有些不能显示为了全部显示

Java代码 复制代码 收藏代码
  1. public void centerOverlays() {    
  2.     int minLat = 81 * MapStoresController.MAP_SCALE;    
  3.     int maxLat = -81 * MapStoresController.MAP_SCALE;    
  4.     int minLon = 181 * MapStoresController.MAP_SCALE;    
  5.     int maxLon = -181 * MapStoresController.MAP_SCALE;    
  6.     
  7.     for (int i = 0; i < overlayItems.size(); i++) {    
  8.         Store s = overlayItems.getItem(i).getStore();    
  9.         minLat = (int) ((minLat > (s.getLocation().getLatitude() * MapStoresController.MAP_SCALE)) ? s.getLocation().getLatitude() * MapStoresController.MAP_SCALE :    minLat);    
  10.         maxLat = (int) ((maxLat < (s.getLocation().getLatitude() * MapStoresController.MAP_SCALE)) ? s.getLocation().getLatitude() * MapStoresController.MAP_SCALE : maxLat);    
  11.         minLon = (int) ((minLon > (s.getLocation().getLongitude() * MapStoresController.MAP_SCALE)) ? s.getLocation().getLongitude() * MapStoresController.MAP_SCALE : minLon);    
  12.         maxLon = (int) ((maxLon < (s.getLocation().getLongitude() * MapStoresController.MAP_SCALE)) ? .getLocation().getLongitude() * MapStoresController.MAP_SCALE : maxLon);    
  13.     }    
  14.     
  15.     GeoPoint gp = controller.getUserLocation();    
  16.     
  17.     minLat = (minLat > gp.getLatitudeE6()) ? gp.getLatitudeE6() : minLat;    
  18.     maxLat = (maxLat < gp.getLatitudeE6()) ? gp.getLatitudeE6() : maxLat;    
  19.     minLon = (minLon > gp.getLongitudeE6()) ? gp.getLongitudeE6() : minLon;    
  20.     maxLon = (maxLon < gp.getLongitudeE6()) ? gp.getLongitudeE6() : maxLon;    
  21.     
  22.     mapView.getController().zoomToSpan((maxLat - minLat), (maxLon - minLon));    
  23.     mapView.getController().animateTo(new GeoPoint((maxLat + minLat) / 2, (maxLon + minLon) / 2));    
  24. }   
public void centerOverlays() { 
    int minLat = 81 * MapStoresController.MAP_SCALE; 
    int maxLat = -81 * MapStoresController.MAP_SCALE; 
    int minLon = 181 * MapStoresController.MAP_SCALE; 
    int maxLon = -181 * MapStoresController.MAP_SCALE; 
 
    for (int i = 0; i < overlayItems.size(); i++) { 
        Store s = overlayItems.getItem(i).getStore(); 
        minLat = (int) ((minLat > (s.getLocation().getLatitude() * MapStoresController.MAP_SCALE)) ? s.getLocation().getLatitude() * MapStoresController.MAP_SCALE :    minLat); 
        maxLat = (int) ((maxLat < (s.getLocation().getLatitude() * MapStoresController.MAP_SCALE)) ? s.getLocation().getLatitude() * MapStoresController.MAP_SCALE : maxLat); 
        minLon = (int) ((minLon > (s.getLocation().getLongitude() * MapStoresController.MAP_SCALE)) ? s.getLocation().getLongitude() * MapStoresController.MAP_SCALE : minLon); 
        maxLon = (int) ((maxLon < (s.getLocation().getLongitude() * MapStoresController.MAP_SCALE)) ? .getLocation().getLongitude() * MapStoresController.MAP_SCALE : maxLon); 
    } 
 
    GeoPoint gp = controller.getUserLocation(); 
 
    minLat = (minLat > gp.getLatitudeE6()) ? gp.getLatitudeE6() : minLat; 
    maxLat = (maxLat < gp.getLatitudeE6()) ? gp.getLatitudeE6() : maxLat; 
    minLon = (minLon > gp.getLongitudeE6()) ? gp.getLongitudeE6() : minLon; 
    maxLon = (maxLon < gp.getLongitudeE6()) ? gp.getLongitudeE6() : maxLon; 
 
    mapView.getController().zoomToSpan((maxLat - minLat), (maxLon - minLon)); 
    mapView.getController().animateTo(new GeoPoint((maxLat + minLat) / 2, (maxLon + minLon) / 2)); 
} 

 

2.

Java代码 复制代码 收藏代码
  1. /**  
  2.  * Fits the map with the passed in points so all points are visible.  
  3.  * @param mapController MapView controller  
  4.  * @param points list of points you want the map to contain  
  5.  */  
  6. private static void fitPoints(MapController mapController, List points) {   
  7.     // set min and max for two points   
  8.     int nwLat = -90 * 1000000;   
  9.     int nwLng = 180 * 1000000;   
  10.     int seLat = 90 * 1000000;   
  11.     int seLng = -180 * 1000000;   
  12.     // find bounding lats and lngs   
  13.     for (GeoPoint point : points) {   
  14.     nwLat = Math.max(nwLat, point.getLatitudeE6());    
  15.     nwLng = Math.min(nwLng, point.getLongitudeE6());   
  16.     seLat = Math.min(seLat, point.getLatitudeE6());   
  17.         seLng = Math.max(seLng, point.getLongitudeE6());   
  18.     }   
  19.     GeoPoint center = new GeoPoint((nwLat + seLat) / 2, (nwLng + seLng) / 2);   
  20.     // add padding in each direction   
  21.     int spanLatDelta = (int) (Math.abs(nwLat - seLat) * 1.1);   
  22.     int spanLngDelta = (int) (Math.abs(seLng - nwLng) * 1.1);   
  23.     
  24.     // fit map to points   
  25.     mapController.animateTo(center);   
  26.     mapController.zoomToSpan(spanLatDelta, spanLngDelta);   
  27. }