📄 mapviewui.java
字号:
return "EPSG:4326";
// return srs;
}
public String getVersion() {
return "1.0.0";
}
/**
* @return Returns the getMapURL.
* @uml.property name="getMapURL"
*/
public String getGetMapURL() {
return getMapURL;
}
public int getPixelWidth() {
// int pw;
// // pw = getHeight() * getBoxWidth() / getBoxHeight();
// pw =
// (int)(((getBoxWidth().Mul(getHeight())).Div(getBoxHeight())).toLong())
// ;
// if (pw > getWidth()) {
// return getWidth();
// }
// return pw;
return getWidth();
}
public int getPixelHeight() {
// int ph;
// // ph = getWidth() * getBoxHeight() / getBoxWidth();
// ph =
// (int)(((getBoxHeight().Mul(getWidth())).Div(getBoxWidth())).toLong());
// if (ph > getHeight()) {
// return getHeight();
// }
// return ph;
return getHeight();
}
public boolean isInside(Float[] point, Float[] box) {
if (box[0].Less(point[0]) && point[0].Less(box[2])
&& box[1].Less(point[1]) && point[1].Less(box[3])) {
return true;
}
return false;
}
// Transform from cursor coordinate to world coordinate
private Float[] transformFromView(int[] source) {
if (2 != source.length) {
return null;
}
Float[] dest = new Float[2];
// dest[0] = boundingBox[0] + source[0]/getCurrentScale();
dest[0] = boundingBox[0].Add(new Float(source[0])
.Div(getCurrentScale()));
// dest[3] = boundingBox[3] - source[1]/getCurrentScale();
dest[1] = boundingBox[1].Add(new Float(getHeight() - source[1])
.Div(getCurrentScale()));
return dest;
}
// Transform from world coordinate to cursor coordinate
private int[] transformFromReal(Float[] source) {
if (2 != source.length || null == source[0] || null == source[1]) {
return null;
}
int[] dest = new int[2];
dest[0] = (int) (((source[0].Sub(boundingBox[0]))
.Mul(getCurrentScale())).toLong());
dest[1] = getHeight()
- (int) (((source[1].Sub(boundingBox[1]))
.Mul(getCurrentScale())).toLong());
return dest;
}
public Float getCurrentScale() {
// return (getPixelWidth() / getBoxWidth());
return new Float(getPixelWidth()).Div(getBoxWidth());
}
// Center at the cursor
private void reCenter(int[] curPoint) {
if (curPoint.length == 2) {
Float[] point;
point = transformFromView(curPoint);
reCenter(point);
}
}
// Center at the specific point
private void reCenter(Float[] point) {
if (point.length == 2) {
Float boxWidth = getBoxWidth();
Float boxHeight = getBoxHeight();
// boundingBox[0] = point[0] - (Float)(bboxWidth / 2);
boundingBox[0] = point[0].Sub(boxWidth.Div(2));
// boundingBox[1] = point[1] - (Float)(bboxHeight / 2);
boundingBox[1] = point[1].Sub(boxHeight.Div(2));
// boundingBox[2] = point[0] + (Float)(bboxWidth / 2);
boundingBox[2] = point[0].Add(boxWidth.Div(2));
// boundingBox[3] = point[1] + (Float)(bboxHeight / 2);
boundingBox[3] = point[1].Add(boxHeight.Div(2));
cursorX = getWidth() / 2;
cursorY = getHeight() / 2;
}
}
// Center at the specific point
public void reCenterAtFeature(MapFeature feature) {
previousAction = NO_ACTION;
// zoom to best scale first
zoomToScale(UIConstants.BEST_SCALE);
// Recenter to feature
Float boxWidth = getBoxWidth();
Float boxHeight = getBoxHeight();
boundingBox[0] = feature.getX().Sub(boxWidth.Div(2));
boundingBox[1] = feature.getY().Sub(boxHeight.Div(2));
boundingBox[2] = feature.getX().Add(boxWidth.Div(2));
boundingBox[3] = feature.getY().Add(boxHeight.Div(2));
cursorX = getWidth() / 2;
cursorY = getHeight() / 2;
}
public void updateMyNMEALocation(String latitude, String longitude) {
previousAction = NO_ACTION;
isLocated = true;
// Soom to best scale first
zoomToScale(UIConstants.BEST_SCALE);
// Set location to new lat/lon
myLocation[1] = nmeaToDecimal(Float.parse(latitude, 10));
myLocation[0] = nmeaToDecimal(Float.parse(longitude, 10));
// Re-center to my location
reCenter(myLocation);
uiController.updateMapRequested();
}
public Float nmeaToDecimal(Float pos) {
Float deg, decPos;
deg = Float.floor(pos.Div(100));
decPos = Float.round(deg.Add((pos.Sub(deg.Mul(100))).Div(60)), 8);
return decPos;
}
private void zoomIn() {
if (previousAction == ZOOM_OUT) {
restorePreviousAction(ZOOM_IN);
} else {
saveCurrentAction(ZOOM_IN);
// Recenter at cursor first
int[] cursors = { getCursorX(), getCursorY() };
reCenter(cursors);
// then zoom in
Float oldScale = getBoxWidth().Div(getBoxHeight());
Float oldWidth = getBoxWidth();
Float oldHeight = getBoxHeight();
boundingBox[0] = boundingBox[0]
.Add(UIConstants.SCALE.Mul(oldWidth));
boundingBox[1] = boundingBox[1].Add(UIConstants.SCALE
.Mul(oldHeight));
boundingBox[2] = boundingBox[2]
.Sub(UIConstants.SCALE.Mul(oldWidth));
boundingBox[3] = boundingBox[1].Add(getBoxWidth().Div(oldScale));
}
}
private void zoomOut() {
if (previousAction == ZOOM_IN) {
restorePreviousAction(ZOOM_OUT);
} else {
saveCurrentAction(ZOOM_OUT);
// Recenter at cursor first
int[] cursors = { getCursorX(), getCursorY() };
reCenter(cursors);
// then zoom out
Float oldScale = getBoxWidth().Div(getBoxHeight());
Float oldWidth = getBoxWidth();
Float oldHeight = getBoxHeight();
boundingBox[0] = boundingBox[0]
.Sub(UIConstants.SCALE.Mul(oldWidth));
boundingBox[1] = boundingBox[1].Sub(UIConstants.SCALE
.Mul(oldHeight));
boundingBox[2] = boundingBox[2]
.Add(UIConstants.SCALE.Mul(oldWidth));
boundingBox[3] = boundingBox[1].Add(getBoxWidth().Div(oldScale));
}
}
private void zoomToScale(Float scale) {
previousAction = NO_ACTION;
Float oldWidth = getBoxWidth();
Float oldHeight = getBoxHeight();
Float newWidth = (new Float(getPixelWidth())).Div(scale);
Float newHeight = (new Float(getPixelHeight())).Div(scale);
boundingBox[0] = boundingBox[0].Sub((newWidth.Sub(oldWidth)).Div(2));
boundingBox[1] = boundingBox[1].Sub((newHeight.Sub(oldHeight)).Div(2));
boundingBox[2] = boundingBox[2].Add((newWidth.Sub(oldWidth)).Div(2));
boundingBox[3] = boundingBox[3].Add((newHeight.Sub(oldHeight)).Div(2));
}
private void restorePreviousAction(int currentAction) {
Float[] tmp = new Float[4];
System.arraycopy(previousBoundingBox, 0, tmp, 0, 4);
System.arraycopy(boundingBox, 0, previousBoundingBox, 0, 4);
System.arraycopy(tmp, 0, boundingBox, 0, 4);
previousAction = currentAction;
}
private void saveCurrentAction(int currentAction) {
System.arraycopy(boundingBox, 0, previousBoundingBox, 0, 4);
previousAction = currentAction;
}
private void moveUp() {
if (previousAction == MOVE_DOWN) {
restorePreviousAction(MOVE_UP);
} else {
saveCurrentAction(MOVE_UP);
Float oldHeight = getBoxHeight();
boundingBox[1] = boundingBox[1].Add(UIConstants.SCALE
.Mul(oldHeight));
boundingBox[3] = boundingBox[3].Add(UIConstants.SCALE
.Mul(oldHeight));
}
}
private void moveDown() {
if (previousAction == MOVE_UP) {
restorePreviousAction(MOVE_DOWN);
} else {
saveCurrentAction(MOVE_DOWN);
Float oldHeight = getBoxHeight();
boundingBox[1] = boundingBox[1].Sub(UIConstants.SCALE
.Mul(oldHeight));
boundingBox[3] = boundingBox[3].Sub(UIConstants.SCALE
.Mul(oldHeight));
}
}
private void moveLeft() {
if (previousAction == MOVE_RIGHT) {
restorePreviousAction(MOVE_LEFT);
} else {
saveCurrentAction(MOVE_LEFT);
Float oldWidth = getBoxWidth();
boundingBox[0] = boundingBox[0]
.Sub(UIConstants.SCALE.Mul(oldWidth));
boundingBox[2] = boundingBox[2]
.Sub(UIConstants.SCALE.Mul(oldWidth));
}
}
private void moveRight() {
if (previousAction == MOVE_LEFT) {
restorePreviousAction(MOVE_RIGHT);
} else {
saveCurrentAction(MOVE_RIGHT);
Float oldWidth = getBoxWidth();
boundingBox[0] = boundingBox[0]
.Add(UIConstants.SCALE.Mul(oldWidth));
boundingBox[2] = boundingBox[2]
.Add(UIConstants.SCALE.Mul(oldWidth));
}
}
private void repaintCursor() {
repaint(cursorX - (2 * cursorSize), cursorY - (2 * cursorSize),
4 * cursorSize, 4 * cursorSize);
}
private void repaintCursor(int x, int y) {
repaint(x - (2 * cursorSize), y - (2 * cursorSize), 4 * cursorSize,
4 * cursorSize);
}
private void repaintStatus() {
repaint(0, getHeight() - (2 * cursorSize), getWidth(), 2 * cursorSize);
}
private void moveCursorLeft() {
if (cursorX - UIConstants.CURSOR_MOVEMENT > 0) {
cursorX -= UIConstants.CURSOR_MOVEMENT;
repaintCursor();
repaintStatus();
}
}
private void moveCursorRight() {
if (cursorX + UIConstants.CURSOR_MOVEMENT < getWidth()) {
cursorX += UIConstants.CURSOR_MOVEMENT;
repaintCursor();
repaintStatus();
}
}
private void moveCursorUp() {
if (cursorY - UIConstants.CURSOR_MOVEMENT > 0) {
cursorY -= UIConstants.CURSOR_MOVEMENT;
repaintCursor();
repaintStatus();
}
}
private void moveCursorDown() {
if (cursorY + UIConstants.CURSOR_MOVEMENT < getHeight()) {
cursorY += UIConstants.CURSOR_MOVEMENT;
repaintCursor();
repaintStatus();
}
}
/*
* private void setStartPoint() { int[] cursors = {getCursorX(),
* getCursorY()}; int[] oldCursors = transformFromReal(startPoint);
* startPoint = transformFromView(cursors); startPointSelected = true; //
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -