package org.walkgis.learngis.lesson20.controller;
import de.felixroske.jfxsupport.AbstractFxmlView;
import de.felixroske.jfxsupport.FXMLController;
import de.felixroske.jfxsupport.GUIState;
import javafx.embed.swing.SwingFXUtils;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Cursor;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.control.*;
import javafx.scene.control.Label;
import javafx.scene.control.MenuItem;
import javafx.scene.image.ImageView;
import javafx.scene.image.WritableImage;
import javafx.scene.input.ContextMenuEvent;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.scene.shape.Rectangle;
import javafx.stage.FileChooser;
import javafx.stage.Modality;
import javafx.stage.Stage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.util.StringUtils;
import org.walkgis.learngis.lesson20.Lesson20Application;
import org.walkgis.learngis.lesson20.basicclasses.*;
import org.walkgis.learngis.lesson20.basicclasses.network.GISNetwork;
import org.walkgis.learngis.lesson20.view.DataTableView;
import org.walkgis.learngis.lesson20.view.LayerView;
import org.walkgis.learngis.lesson20.view.MainView;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import java.util.UUID;
@FXMLController
public class MainController implements Initializable {
@Value(value = "${data.dir}")
private String dataDir;
@FXML
private Pane canvasContainer;
@FXML
private Canvas mainCanvas;
@FXML
private ImageView btnOpenDocument, btnLayerControl, btnFullScreen, btnZoomIn, btnZoomOut, btnMoveUp, btnMoveDown, btnMoveLeft, btnMoveRight, btnClear, btnNetwork;
@FXML
private ImageView btnBuildGrid, btnReadRouteGrid, btnWriteRouteGrid, btnLoadPoint, btnClearPoint, btnShowRoute;
@FXML
private CheckBox chbAddPoint;
@FXML
private ComboBox cmbRouteFields;
@FXML
private Label lblPosition, lblTotals, lblSelectCount;
@FXML
private TreeView toolContent;
@Autowired
private DataTableController dataTableController;
@Autowired
private MainView mainView;
private ContextMenu contextMenu;
private MenuItem menuDocument, select, selectElement, zoomIn, zoomOut, pan, fullScreen, menuLayerControl;
@Autowired
private ApplicationContext applicationContext;
private BufferedImage backgroundWindow;
private MouseCommand mouseCommand = MouseCommand.Unused;
private int mouseStartX = 0, mouseStartY = 0, mouseMovingX = 0, mouseMovingY = 0;
private boolean mouseOnMap = false;
private GISView view;
private Rectangle clientRectangle;
public GISDocument document = new GISDocument();
private GISNetwork network;
private GISVectorLayer stopsLayer;
private GISVectorLayer lineLayer;
private List<GISVertex> netPoints = new ArrayList<>();
@Override
public void initialize(URL location, ResourceBundle resources) {
document = new GISDocument();
initCanvasContextMenu();
clientRectangle = new Rectangle(0, 0, mainCanvas.getWidth(), mainCanvas.getHeight());
view = new GISView(new GISExtent(new GISVertex(0, 0), new GISVertex(1, 1)), clientRectangle);
mainCanvas.setOnMouseClicked(this::canvasClick);
mainCanvas.setOnMouseMoved(this::canvasMouseMoved);
mainCanvas.setOnMousePressed(this::canvasMousePressed);
mainCanvas.setOnMouseReleased(this::canvasMouseReleased);
mainCanvas.setOnContextMenuRequested(this::canvasContextMenu);
btnOpenDocument.setOnMouseClicked(this::btnOpenDocumentClick);
btnLayerControl.setOnMouseClicked(this::btnLayerControlClick);
btnZoomIn.setOnMouseClicked(this::mapActionClick);
btnZoomOut.setOnMouseClicked(this::mapActionClick);
btnMoveUp.setOnMouseClicked(this::mapActionClick);
btnMoveDown.setOnMouseClicked(this::mapActionClick);
btnMoveLeft.setOnMouseClicked(this::mapActionClick);
btnMoveRight.setOnMouseClicked(this::mapActionClick);
btnFullScreen.setOnMouseClicked(this::btnFullScreen);
btnClear.setOnMouseClicked(this::btnClearClick);
btnNetwork.setOnMouseClicked(this::btnNetworkClick);
mainCanvas.widthProperty().bind(canvasContainer.widthProperty());
mainCanvas.heightProperty().bind(canvasContainer.heightProperty());
List<GISField> fields = new ArrayList<>();
fields.add(new GISField(Integer.class, "index"));
stopsLayer = new GISVectorLayer("stops" + UUID.randomUUID().toString(), SHAPETYPE.point, null, fields);
stopsLayer.labelIndex = 0;
stopsLayer.drawAttributeOrNot = true;
chbAddPoint.setTooltip(new Tooltip("添加起止点"));
Tooltip.install(btnBuildGrid, new Tooltip("构建网络结构"));
Tooltip.install(btnReadRouteGrid, new Tooltip("读取网络结构"));
Tooltip.install(btnWriteRouteGrid, new Tooltip("导出网络结构"));
Tooltip.install(btnLoadPoint, new Tooltip("加载起止点"));
Tooltip.install(btnClearPoint, new Tooltip("清空起止点"));
Tooltip.install(btnShowRoute, new Tooltip("显示最短路径"));
chbAddPoint.setSelected(false);
cmbRouteFields.setOnMouseClicked(this::cmbRouteFieldsClick);
btnBuildGrid.setOnMouseClicked(this::btnBuildGridClick);
btnReadRouteGrid.setOnMouseClicked(this::btnReadRouteGridClicck);
btnWriteRouteGrid.setOnMouseClicked(this::btnWriteRouteGridClicck);
btnLoadPoint.setOnMouseClicked(this::btnLoadPointClicck);
btnClearPoint.setOnMouseClicked(this::btnClearPointClicck);
btnShowRoute.setOnMouseClicked(this::btnShowRouteClicck);
}
@FXML
private void btnShowRouteClicck(MouseEvent mouseEvent) {
if (stopsLayer.features.size() < 2) return;
checkLayers();
lineLayer.clearSelection();
for (int i = 1; i < stopsLayer.features.size(); i++) {
GISVertex vFrom = stopsLayer.features.get(i - 1).spatial.center;
GISVertex vTo = stopsLayer.features.get(i).spatial.center;
List<GISFeature> fs = network.findRoute(vFrom, vTo);
lineLayer.select(fs);
}
updateMap();
}
@FXML
private void btnClearPointClicck(MouseEvent mouseEvent) {
initGrid();
}
@FXML
private void btnLoadPointClicck(MouseEvent mouseEvent) {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("选择数据");
Stage selectFile = new Stage();
if (StringUtils.isEmpty(dataDir) || !new File(dataDir).exists())
dataDir = System.getProperty("user.home");
fileChooser.setInitialDirectory(new File(dataDir));
fileChooser.getExtensionFilters().addAll(
new FileChooser.ExtensionFilter("所有文件类型", "*." + GISConst.SHP),
new FileChooser.ExtensionFilter("Shapefile", "*." + GISConst.SHP)
);
File file = fileChooser.showOpenDialog(selectFile);
if (file != null) {
GISLayer layer = GISTools.getLayer(file.getAbsolutePath());
if (layer.layerType != LAYERTYPE.VectorLayer) return;
if (((GISVectorLayer) layer).shapeType != SHAPETYPE.point) return;
initGrid();
GISVectorLayer pointLayer = (GISVectorLayer) layer;
for (int i = 0; i < pointLayer.features.size(); i++) {
GISVertex vertex = pointLayer.features.get(i).spatial.center;
//展示出来
netPoints.add(vertex);
GISAttribute attribute = new GISAttrib
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
地理信息系统:使用Java实现,利用JavaFx.zip (856个子文件)
point.cpg 5B
roads_point.cpg 5B
linet.cpg 5B
area3.cpg 5B
linet.dbf 25KB
point.dbf 21KB
area3.dbf 21KB
roads.dbf 11KB
states.dbf 4KB
cities.dbf 3KB
roads_point.dbf 968B
MainView.fxml 7KB
MainView.fxml 7KB
MainView.fxml 7KB
MainView.fxml 5KB
MainView.fxml 5KB
MainView.fxml 5KB
MainView.fxml 5KB
MainView.fxml 5KB
MainView.fxml 5KB
MainView.fxml 4KB
LayerView.fxml 4KB
LayerView.fxml 4KB
LayerView.fxml 4KB
LayerView.fxml 4KB
LayerView.fxml 4KB
LayerView.fxml 3KB
LayerView.fxml 3KB
LayerView.fxml 3KB
LayerView.fxml 3KB
MainView.fxml 2KB
MainView.fxml 2KB
MainView.fxml 2KB
MainView.fxml 2KB
MainView.fxml 2KB
MainView.fxml 1KB
MainView.fxml 1KB
MainView.fxml 1KB
MainView.fxml 1KB
MainView.fxml 1KB
MainView.fxml 859B
MainView.fxml 859B
DataTableView.fxml 615B
DataTableView.fxml 615B
DataTableView.fxml 615B
DataTableView.fxml 615B
DataTableView.fxml 615B
DataTableView.fxml 615B
DataTableView.fxml 615B
DataTableView.fxml 615B
DataTableView.fxml 615B
DataTableView.fxml 603B
DataTableView.fxml 603B
DataTableView.fxml 603B
DataTableView.fxml 603B
DataTableView.fxml 602B
DataTableView.fxml 602B
DataTableView.fxml 602B
lesson15MapWindow.iml 3KB
MainController.java 24KB
MainController.java 24KB
MainController.java 24KB
GISShapefile.java 17KB
GISShapefile.java 17KB
GISShapefile.java 17KB
MainController.java 16KB
MainController.java 16KB
MainController.java 16KB
MainController.java 16KB
MainController.java 16KB
MainController.java 15KB
LayerController.java 15KB
MainController.java 15KB
LayerController.java 14KB
LayerController.java 13KB
LayerController.java 12KB
LayerController.java 12KB
GISMyFile.java 12KB
RTree.java 12KB
GISMyFile.java 11KB
GISMyFile.java 11KB
GISNetwork.java 11KB
GISNetwork.java 11KB
GISNetwork.java 11KB
GISVectorLayer.java 11KB
GISShapefile.java 10KB
GISShapefile.java 10KB
GISShapefile.java 10KB
GISShapefile.java 10KB
GISShapefile.java 10KB
GISShapefile.java 10KB
GISShapefile.java 10KB
GISShapefile.java 10KB
GISShapefile.java 10KB
GISShapefile.java 10KB
GISShapefile.java 10KB
GISShapefile.java 10KB
LayerController.java 10KB
GISShapefile.java 9KB
GISVectorLayer.java 9KB
共 856 条
- 1
- 2
- 3
- 4
- 5
- 6
- 9
资源评论
博士僧小星
- 粉丝: 1913
- 资源: 5876
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功