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

📄 zoomouttool.java~134~

📁 一个很有特点的地图平台,可以以动画方试展现电子地图,有拉近,拉远,滑动功能,最主要的是它是一个地图维护台,处理地图到数据库的数据导入
💻 JAVA~134~
字号:
package mapcenter.maptools;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ZoomOutTool extends MapTool{
  private int x1,y1,x2,y2;
  private boolean DraggFlag = false;

  public ZoomOutTool() {
    super("/image/zoomout1.gif","/image/zoomout2.gif","缩小","缩小工具",'O');
    ImageIcon icon = new ImageIcon(getClass().getResource("/image/zoomout.gif"));
    Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor(icon.getImage(),new Point(0,0),"缩小");
    super.cursor = cursor;
  }

  public void actionPerformed(ActionEvent evt) {
    super.actionPerformed(evt);
  }
  //============= MouseListener接口实现 =============
  public void mouseEntered(MapMouse evt) {}
  public void mouseExited(MapMouse evt) {}
  public void mouseClicked(MapMouse evt) {}
  public void mouseMoved(MapMouse evt) {}

  public void mousePressed(MapMouse evt) {
    x1 = evt.getX();
    y1 = evt.getY();
  }

  public void mouseDragged(MapMouse evt) {
    //======= 绘制轨迹线 ======
    Graphics g = mapView.getGraphics();
    Color c = g.getColor();
    g.setColor(Color.black);
    g.setXORMode(Color.white);
    if(x2 != 0 && y2 != 0){
      g.drawRect(Math.min(x1,x2),Math.min(y1,y2),Math.abs(x1-x2),Math.abs(y1-y2));
    }
    x2 = evt.getX();
    y2 = evt.getY();
    g.drawRect(Math.min(x1,x2),Math.min(y1,y2),Math.abs(x1-x2),Math.abs(y1-y2));
    g.setColor(c);
    g.setPaintMode();
    DraggFlag = true;
  }

  public void mouseReleased(MapMouse evt) {
    double centerX=0,centerY=0,zoompen=0;

    try{
      Image image = mapView.getMapHandle().getImg();
      int marginH = (image.getWidth(null) - mapView.getWidth())/2;
      int marginV = (image.getHeight(null) - mapView.getHeight())/2;
      if(DraggFlag == true){
        centerX = x1 + (x2-x1)/2 + marginH;
        centerY = y1 + (y2-y1)/2 + marginV;
        double distance = Math.abs(x2-x1);
        if(distance > 10)zoompen = distance/mapView.getWidth();
      }else{
        centerX = x1 + marginH;
        centerY = y1 + marginV;
        Image buffimg = mapView.getBuffImg();
        Graphics buffg = buffimg.getGraphics();
        int w = mapView.getWidth();
        int h = mapView.getHeight();
        int k = 0;
        for(int i=0; i<100; i++){
          k = k - 10;
          int v = k*marginV/marginH;
          buffg.clearRect(0, 0, w, h);
          buffg.drawImage(image, -marginH-k/2, -marginV-v/2, marginH*3+k, marginV*3+v, null);
          mapView.getGraphics().drawImage(buffimg, 0, 0, null);
        }
      }
      mapView.getMapHandle().zoomoutMap(centerX,centerY,zoompen);
      mapView.renderMap();
      x1=x2=y1=y2=0;
      DraggFlag = false;
    }catch(Exception e){log.error(e);}
  }

  //============= KeyListener接口实现 =============
  public void keyTyped(KeyEvent evt) {}
  public void keyPressed(KeyEvent evt) {}
  public void keyReleased(KeyEvent evt) { }

  //============= MapPainter接口实现 ===============
  public void paintOnMap(Graphics g) {
  }
  //============= ToolTipTextSetter接口实现 ========
  public String getToolTipText(MapMouse evt) {return "缩小";}

  public void zoomMoveing(double pointX,double pointY,double zoompen)throws Exception{
    Image renderImage = mapView.getMapHandle().getImg();
    Image bufferImage = mapView.getBuffImg();
    Graphics bufferGrap = bufferImage.getGraphics();
    double mapWidth = renderImage.getWidth(null);
    double mapHeight = renderImage.getHeight(null);
    double containW = mapView.getWidth();
    double containH = mapView.getHeight();
    double marginHor = (mapWidth - containW) / 2;
    double marginVer = (mapHeight - containH) / 2;
    int moveCount = 20;
    int interval = 30;
    double WidthStep = (mapWidth / zoompen - mapWidth) / moveCount;
    double HeightStep = (mapHeight / zoompen - mapHeight) / moveCount;
    double ScreenX = pointX - marginHor;
    double ScreenY = pointY - marginVer;
    double HorStep = (mapWidth / 2 - pointX) / moveCount;
    double VerStep = (mapHeight / 2 - pointY) / moveCount;
    for (int i = 0; i < moveCount; i++) {
      Thread.sleep(interval);
      ScreenX += HorStep;
      ScreenY += VerStep;
      mapWidth += WidthStep;
      mapHeight += HeightStep;
      double left = pointX * (mapWidth/renderImage.getWidth(null)) - ScreenX;
      double top = pointY * (mapHeight/renderImage.getHeight(null)) - ScreenY;
      bufferGrap.clearRect(0, 0, (int)containW, (int)containH);
      bufferGrap.drawImage(renderImage, -(int)left, -(int)top, (int)mapWidth, (int)mapHeight, null);
      mapView.getGraphics().drawImage(bufferImage, 0, 0, null);
    }
  }
}

⌨️ 快捷键说明

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