Package chunmap.raster.gmap

Source Code of chunmap.raster.gmap.GMConnection

/**
* Copyright (c) 2009-2011, chunquedong(YangJiandong)
*
* This file is part of ChunMap project
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
*
* History:
*     2010-05-05  Jed Young  Creation
*/
package chunmap.raster.gmap;

import java.awt.Image;
import java.io.IOException;

import chunmap.raster.Tile;
import chunmap.util.image.ImageCache;
import chunmap.util.image.WebClientUtil;

public class GMConnection {
  protected ImageCache cache=new ImageCache();
  public String rootUrl="http://mt2.google.cn/vt/v=w2.116&hl=zh-CN&gl=cn";

    public Image getImage(GMTile tile_)
    {
        Tile tile = (tile_.proxy == null) ? tile_ : tile_.proxy;

        String name = tile.toString();
        Image image = cache.find(name);
        if (image != null) return image;

        String url=getString(tile.x, tile.y, tile.z);
        try
        {
            image = request(url);
        }
        catch(IOException exp)
        {
            //return Resources.chun;
          //TODO
          return null;
        }

        cache.save(image, name);
        return image;
    }

    private String getString(int x, int y, int z)
    {
        String url=  rootUrl
          +"&x="+ x + "&y=" + y + "&z=" + z + "&s=G";
        return url;
    }
    protected Image request(String url) throws IOException
    {
        return WebClientUtil.requestImage(url);
    }

    public void setBufferPath(String path)
    {
        cache.setBufferPath(path);
    }
}
TOP

Related Classes of chunmap.raster.gmap.GMConnection

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.