📄 maptool.java
字号:
package mapcenter.maptools;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import mapcenter.service.*;
public class MapTool extends AbstractAction{
protected static Log log = LogFactory.getLog("WebGIS");
protected Icon originalIcon = null;
protected Icon selectedIcon = null;
protected Cursor cursor = null;
protected MapView mapView = null;
public MapTool(String origIcon,String seleIcon,String menuText,String toolTip,char acceKey) {
super();
this.originalIcon = new ImageIcon(getClass().getResource(origIcon));
this.selectedIcon = new ImageIcon(getClass().getResource(seleIcon));
this.putValue(NAME,menuText);
this.putValue(SMALL_ICON, originalIcon);
this.putValue(SHORT_DESCRIPTION, toolTip);
this.putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(acceKey,
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
this.cursor = new Cursor(Cursor.DEFAULT_CURSOR);
}
//============= MouseListener接口实现 =============
public void mouseEntered(MapMouse evt) {}
public void mouseExited(MapMouse evt) {}
public void mousePressed(MapMouse evt) {}
public void mouseReleased(MapMouse evt) {}
public void mouseDragged(MapMouse evt) {}
public void mouseMoved(MapMouse evt) {}
public void mouseClicked(MapMouse evt) {}
//============= MapPainter接口实现 ===============
public void paintOnMap(Graphics g) { }
public void actionPerformed(ActionEvent evt){
try{
String toolName = (String)this.getValue(NAME);
mapView.setCurrentTool(toolName);
}catch(Exception e){log.error(e);}
}
public void setMapView(MapView mapView){
this.mapView = mapView;
}
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 + -