/**
   * @param placeNameServiceSet the set of PlaceNameService objects that PlaceNameLayer will render.
   * @throws IllegalArgumentException if {@link
   *     gov.nasa.worldwind.layers.placename.PlaceNameServiceSet} is null
   */
  public PlaceNameLayer(PlaceNameServiceSet placeNameServiceSet) {
    if (placeNameServiceSet == null) {
      String message = Logging.getMessage("nullValue.PlaceNameServiceSetIsNull");
      Logging.logger().fine(message);
      throw new IllegalArgumentException(message);
    }

    //
    this.placeNameServiceSet = placeNameServiceSet.deepCopy();
    for (int i = 0; i < this.placeNameServiceSet.getServiceCount(); i++) {
      // todo do this for long as well and pick min
      int calc1 =
          (int)
              (PlaceNameService.TILING_SECTOR.getDeltaLatDegrees()
                  / this.placeNameServiceSet
                      .getService(i)
                      .getTileDelta()
                      .getLatitude()
                      .getDegrees());
      int numLevels = (int) Math.log(calc1);
      navTiles.add(
          new NavigationTile(
              this.placeNameServiceSet.getService(i),
              PlaceNameService.TILING_SECTOR,
              numLevels,
              "top"));
    }

    if (!WorldWind.getMemoryCacheSet().containsCache(Tile.class.getName())) {
      long size = Configuration.getLongValue(AVKey.PLACENAME_LAYER_CACHE_SIZE, 2000000L);
      MemoryCache cache = new BasicMemoryCache((long) (0.85 * size), size);
      cache.setName("Placename Tiles");
      WorldWind.getMemoryCacheSet().addCache(Tile.class.getName(), cache);
    }
  }
Пример #2
0
  /**
   * 最主要的方法
   *
   * @param url
   * @param imageView
   * @param requiredSize 裁剪图片大小尺寸(一直裁剪到图片宽或高 至少有一个小与requiredSize的时候)
   * @param listener
   * @param defaultPicResId
   */
  public void displayImage(
      String url,
      ImageView imageView,
      int requiredSize,
      OnImageLoaderListener listener,
      int defaultPicResId) {
    imageViews.put(imageView, url);
    // 先从内存缓存中查找
    Bitmap bitmap = memoryCache.get(url);
    if (bitmap != null) {
      imageView.setImageBitmap(bitmap);
      if (null != listener) {
        listener.onFinishedImageLoader(imageView, bitmap); // 通知完成加载
      }
    } else {
      // 如果defaultPicResId小于0,则不设置默认图片
      if (defaultPicResId < 0) {
        queuePhoto(url, imageView, requiredSize, listener);
        return;
      }
      /**
       * 如果defaultPicResId等于0,则设置默认图片为config中的默认图片,并开启新线程加载真实需要的图片
       * 如果defaultPicResId大于0,则设置默认图片为指定的默认图片,并开启新线程加载真实需要的图片
       */
      if (defaultPicResId == 0) {
        defaultPicResId = config.getDefaultResId();
      }
      imageView.setImageResource(defaultPicResId);

      queuePhoto(url, imageView, requiredSize, listener);
    }
  }
Пример #3
0
  public void DisplayImage(String url, int loader, ImageView imageView) {
    defaultResId = loader;
    imageViews.put(imageView, url);
    Bitmap bitmap = memoryCache.get(url);
    if (bitmap != null) imageView.setImageBitmap(bitmap);
    else {
      PhotoToLoad photoToLoad = new PhotoToLoad(url, imageView);
      photoToLoad.imageView.setImageResource(loader);
      new AsyncTask<PhotoToLoad, Void, Bitmap>() {
        private PhotoToLoad pt;

        @Override
        protected Bitmap doInBackground(PhotoToLoad... params) {
          pt = params[0];

          if (imageViewReused(pt)) return null;

          Bitmap bitmap = null;

          // from SD cache
          File f = fileCache.getFile(pt.url);
          try {
            bitmap = BitmapFactory.decodeStream(new FileInputStream(f));
          } catch (FileNotFoundException e) {
            e.printStackTrace();
          }
          if (bitmap != null) return bitmap;

          // from web
          try {
            URL imageUrl = new URL(pt.url);
            HttpURLConnection conn = (HttpURLConnection) imageUrl.openConnection();
            conn.setConnectTimeout(30000);
            conn.setReadTimeout(30000);
            conn.setInstanceFollowRedirects(true);
            InputStream is = conn.getInputStream();
            OutputStream os = new FileOutputStream(f);
            Utils.CopyStream(is, os);
            os.close();
            bitmap = BitmapFactory.decodeStream(new FileInputStream(f));
            return bitmap;
          } catch (Exception ex) {
            ex.printStackTrace();
            return null;
          }
        }

        @Override
        protected void onPostExecute(Bitmap bitmap) {
          memoryCache.put(pt.url, bitmap);
          if (imageViewReused(pt)) return;
          BitmapDisplayer bd = new BitmapDisplayer(bitmap, pt);
          Activity a = (Activity) pt.imageView.getContext();
          a.runOnUiThread(bd);
        }
      }.execute(photoToLoad);
    }
  }
Пример #4
0
 public void DisplayImage(String url, int loader, ImageView imageView) {
   stub_id = loader;
   imageViews.put(imageView, url);
   Bitmap bitmap = memoryCache.get(url);
   if (bitmap != null) imageView.setImageBitmap(bitmap);
   else {
     queuePhoto(url, imageView);
     imageView.setImageResource(loader);
   }
 }
Пример #5
0
 public void clearMemoryCache() {
   memoryCache.clear();
 }
Пример #6
0
 /** 清空文件缓存或内存缓存 */
 public void clearCache() {
   memoryCache.clear();
   fileCache.clear();
 }