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

📄 pantool.java~173~

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

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

public class PanTool extends MapTool{
  private static final Log log = LogFactory.getLog("WebGIS");
  private int x1,y1,x2,y2;
  private boolean draggFlag = false;

  public PanTool() {
    super("/image/pan1.gif","/image/pan2.gif","平移","平移工具",'O');
    ImageIcon icon = new ImageIcon(getClass().getResource("/image/pan.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 mousePressed(MapMouse evt) {
    x1 = evt.getX();
    y1 = evt.getY();
  }

  public void mouseDragged(MapMouse evt) {
    x2 = evt.getX();
    y2 = evt.getY();
    Image image = mapView.getMapHandle().getImg();
    Image buffimg = mapView.getBuffImg();
    Graphics buffg = buffimg.getGraphics();
    int w = mapView.getWidth();
    int h = mapView.getHeight();
    int marginH = (image.getWidth(null) - w)/2;
    int marginV = (image.getHeight(null) - h)/2;
    buffg.clearRect(0, 0, w, h);
    buffg.drawImage(image, x2-x1-marginH, y2-y1-marginV, null);
    mapView.getGraphics().drawImage(buffimg, 0, 0, null);
    draggFlag = true;
  }

  public void mouseReleased(MapMouse evt) {
    try{
      Image renderImage = mapView.getMapHandle().getImg();
      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;

      if(draggFlag == true){
        mapView.getMapHandle().panMap(x2-x1,y2-y1);
      }else{
        mapView.getMapHandle().panMap(containW/2,0);
        zoomMoveing(marginHor,mapHeight/2,0);
      }
      mapView.renderMap();
      draggFlag = false;
    }catch(Exception ee){log.error(ee);}
  }

  public void mouseMoved(MapMouse evt) {}
  public void mouseClicked(MapMouse evt) {}
  //============= 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 + -