⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imagelayer.java

📁 geotools的源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// $Header: /cvsroot/geotools/geotools/src/uk/ac/leeds/ccg/raster/ImageLayer.java,v 1.34.4.1 2002/01/15 17:10:15 ianturton Exp $

package uk.ac.leeds.ccg.raster;

import uk.ac.leeds.ccg.geotools.*;
import java.net.*;
import java.io.*;
import java.awt.image.*;
import com.sun.jimi.core.*;

import java.awt.*;

/**
 * Class <code>ImageLayer</code> will read an image from a URL, assign
 * geographic coordinates to it, and then allow that image to be mapped as
 * a layer within <code>geotools</code>.<br>
 * You can also change the image and exent for the layer.
 *
 * @see WMSLayer
 *
 * @author <a href="http://www.geog.leeds.ac.uk/staff/i.turton/i.turton.html">
 * Ian Turton</a> Centre for
 * Computaional Geography, University of Leeds, LS2 9JT, 1998.<br>
 * <a href="mailto:ian@geog.leeds.ac.uk">i.turton@geog.leeds.ac.uk</a>
 * @author <a href="mailto:cameron@shorter.net">Cameron Shorter</a>
 * @author <a href="mailto:kobit@users.sourceforge.net">Artur Hefczyc</a>
 */
public class ImageLayer extends uk.ac.leeds.ccg.geotools.SimpleLayer implements Runnable
{
  /* Stores all informatation about an image and it's geographic reference */
  private Image image = null;
  private GeoRectangle bbox = null;
  private int myID = 1;
  private final static boolean DEBUG=true;
  private Canvas obs = new Canvas();
  private MediaTracker tracker=new MediaTracker(obs);
  private Toolkit tk;
  private URL src = null;
  protected java.io.InputStream src_stream = null;
  private Thread thread;
  private MemoryImageSource source;
	private int [] imdata;
	private int imwidth;

  public ImageLayer(URL source,GeoRectangle bounds){
		if(DEBUG)System.out.println("IL-("+this+") constructor - source bounds");
    if(DEBUG)System.out.println("---->uk.ac.leeds.ccg.raster.ImageLayer constructed. Will identify itself as IL-->");
    changeImage(source,bounds);
  }

  public ImageLayer(java.io.InputStream in, GeoRectangle bounds)
  {
    changeImage(in, bounds);
  }
    
  public ImageLayer(Image image,GeoRectangle bounds){
		if(DEBUG)System.out.println("IL-("+this+") constructor - Image bounds");
    bbox = bounds;
    this.image = image;
    thread = new Thread(this);
    thread.setPriority(Thread.MIN_PRIORITY);
    thread.start();
  }

  /** Change the image and extent for the layer. */
  public void changeImage(URL source,GeoRectangle bounds){
		if(DEBUG)System.out.println("IL-("+this+") changeImage(source,bounds)");
    this.src = source;
    this.src_stream = null;
    if (DEBUG) System.out.println("ImageLayer.changeImage= "+src);
    changeImage(bounds);
  }

  public void changeImage(java.io.InputStream in, GeoRectangle bounds)
  {
    this.src_stream = in;
    this.src = null;
    changeImage(bounds);
  }

  public void changeImage(GeoRectangle bounds)
  {
		if(DEBUG)System.out.println("IL-("+this+") changeImage(Bounds)");
    this.bbox=bounds;
    setStatus(Layer.LOADING);
    thread = new Thread(this);
    thread.setPriority(Thread.MIN_PRIORITY);
    thread.start();
  }

  /** Change the image and but not the extent. */
  public void changeImage(URL source){
		if(DEBUG)System.out.println("IL-("+this+") changeImage(source)");
    changeImage(source, this.bbox);
  }

  /** Change the extent of the image */
  public void changeExtent(GeoRectangle bounds){
    this.bbox = bounds;
    this.notifyLayerChangedListeners(LayerChangedEvent.GEOGRAPHY);
  }

  public GeoRectangle getBounds()
  {
    // This method is derived from interface uk.ac.leeds.ccg.geotools.Layer
    // to do: code goes here
    return this.bbox;
  }

  public GeoRectangle getBoundsOf(int id[])
  {
    // This method is derived from interface uk.ac.leeds.ccg.geotools.Layer
    // to do: code goes here
    return null;
  }

  public GeoRectangle getBoundsOf(int id)
  {
    // This method is derived from interface uk.ac.leeds.ccg.geotools.Layer
    // to do: code goes here
    return null;
  }

  public int getID(GeoPoint p)
  {
    // This method is derived from interface uk.ac.leeds.ccg.geotools.Layer
    // to do: code goes here
    return 0;
  }

  public int getID(double x, double y)
  {
    // This method is derived from interface uk.ac.leeds.ccg.geotools.Layer
    // to do: code goes here
    return 0;
  }

  public void paintHighlight(Graphics g, Scaler scale, int id, ShadeStyle style)
  {
    // This method is derived from interface uk.ac.leeds.ccg.geotools.Layer
    // to do: code goes here
  }

  public void paintScaled(GeoGraphics gg)
  {
		if(DEBUG)System.out.println("Painting imagelayer");
    double cellSizeX = 0;
    double cellSizeY = 0;
    boolean drawn;
    Graphics g= gg.getGraphics();
    Scaler scale = gg.getScale();
    GeoRectangle gr = scale.getMapExtent();
    //if(DEBUG)System.out.println("IL-->gr "+gr);
    GeoRectangle me = getBounds();
    //if(DEBUG)System.out.println("IL-->me "+me);

    GeoRectangle out = gr.createIntersect(me);
    if(DEBUG)System.out.println("IL-->getStatus="+this.getStatus());
    int gh,gw;
    if(DEBUG)System.out.println("IL ("+this+") -->0");
    if(out!=null){
      if(DEBUG)System.out.println("IL ("+this+") -->1");

      if(out.equals(me)){
        //if(DEBUG)System.out.println("IL ("+this+") -->2 ");
        if(DEBUG)System.out.println("IL-->No clip ("+this+")");
        //GeoRectangle out = bbox;
        int origin[]=scale.toGraphics(out.x,out.y);
        gh=scale.toGraphics(out.height);
        gw=scale.toGraphics(out.width);
				if(getStatus()!=Layer.COMPLETED){
					if(DEBUG)System.out.println("Not ready returning");
					g.setColor(Color.red);
					g.drawRect(origin[0]+1,origin[1]-gh-1,gw-1,gh-1);
					return;
				}
        if(this.image!=null){
          drawn = g.drawImage(
                              this.image,
                              origin[0],
                              origin[1]-gh,
                              gw,
                              gh,
                              null);
          if(DEBUG)System.out.println("IL ("+this+") -->3 drawn="+drawn+" "+this.image);
        }
      } else{ // clipping required
        if(DEBUG)System.out.println("IL ("+this+") -->5 ");
        if((this.getStatus()&Layer.COMPLETED)!=Layer.COMPLETED) {
          if(DEBUG)System.out.println("IL ("
                                      +this+") -->Layer not loaded");
          return;
        }
        //complex clip case
        cellSizeX = me.width/this.image.getWidth(obs);
        cellSizeY = me.height/this.image.getHeight(obs);
        int x,y,width,height;
        if(out.y%cellSizeY>0){
          out.y=out.y+cellSizeY-(out.y%cellSizeY);
          out.height+=cellSizeY; 
        }
        x=(int)Math.floor(((out.x-me.x)/cellSizeX));
        y=(int)Math.ceil(((me.y-out.y+me.height-out.height)/cellSizeY));
        width=(int)Math.ceil((out.width/cellSizeX));
        height=(int)Math.ceil(((out.height)/cellSizeY));
        x=(int)Math.floor(((out.x-me.x)/cellSizeX));
        y=(int)Math.ceil(((me.y-out.y+me.height-out.height)/cellSizeY));
        if(DEBUG)System.out.println("IL-->start "+x+" "+y);
        width=(int)Math.ceil((out.width/cellSizeX));
        height=(int)Math.ceil(((out.height)/cellSizeY));
        if(DEBUG)System.out.println("IL-->w/h "+width+" "+height);
        y=Math.max(y,0);
        int origin[]=scale.toGraphics(out.x,out.y);
        gh=scale.toGraphics(out.height);
        gw=scale.toGraphics(out.width);
        if((this.getStatus()&Layer.COMPLETED)!=Layer.COMPLETED){
          if(DEBUG)System.out.println("IL ("+this+") -->6 ");
          g.setColor(Color.red);
          g.drawRect(origin[0],origin[1]-gh,gw,gh);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -