package dell_map;
|
import databases.DBConnector;
|
import publicsWay.CoordinateTranslator;
|
import targets.Csxy;
|
import targets.Mapdata;
|
|
import java.io.File;
|
import java.io.FileInputStream;
|
import java.io.IOException;
|
import java.io.InputStream;
|
import java.sql.ResultSet;
|
import java.sql.SQLException;
|
import java.util.ArrayList;
|
import java.util.Collections;
|
import java.util.List;
|
import java.util.Locale;
|
import java.util.Map;
|
import java.util.MissingResourceException;
|
import java.util.PropertyResourceBundle;
|
import java.util.ResourceBundle;
|
import java.util.Vector;
|
import java.util.concurrent.ConcurrentHashMap;
|
import javax.swing.JOptionPane;
|
|
public class Dell_Map {
|
static List<Mapdata> maps = null;
|
public static Vector<Csxy> csxyvc = new Vector<>();
|
private static volatile Map<String, double[]> FLOOR_XYCS = Collections.emptyMap();
|
|
public static List<Mapdata> getAllMaps() {
|
maps = new ArrayList<>();
|
ResultSet rs = DBConnector.queryTableData("map");
|
|
try {
|
while (rs.next()) {
|
Mapdata map = new Mapdata();
|
map.setId(Integer.parseInt(rs.getString("id")));
|
map.setMapType(rs.getString("map_type"));
|
map.setDetailDisplay(rs.getString("detail_display"));
|
map.setOfflineDisappear(rs.getString("offline_disappear"));
|
map.setVoiceEnabled(rs.getString("voice_enabled"));
|
map.setFenceDisplay(rs.getString("fence_display"));
|
map.setBaseStationDisplay(rs.getString("base_station_display"));
|
map.setGatewayDisplay(rs.getString("gateway_display"));
|
map.setVideoDisplay(rs.getString("video_display"));
|
map.setInitialViewPosition(rs.getString("initial_view_position"));
|
map.setViewHeight(rs.getString("view_height"));
|
map.setMapHeadingAngle(rs.getString("map_heading_angle"));
|
map.setMapTiltAngle(rs.getString("map_tilt_angle"));
|
map.setTerrainDisabled(rs.getString("terrain_disabled"));
|
map.setTileMapLoading(rs.getString("tile_map_loading"));
|
map.setLocalImageLoading(rs.getString("local_image_loading"));
|
map.setBasemapDisabled(rs.getString("basemap_disabled"));
|
map.setThreeDModel(rs.getString("three_d_model"));
|
map.setLocatedLayer(rs.getString("located_layer"));
|
map.setMapName(rs.getString("map_name"));
|
map.setMapNameDetaile(rs.getString("map_name_detaile"));
|
map.setActualXLength(rs.getString("actual_x_length"));
|
map.setActualYLength(rs.getString("actual_y_length"));
|
map.setX0Coordinate(rs.getString("x0_coordinate"));
|
map.setY0Coordinate(rs.getString("y0_coordinate"));
|
map.setXPixels(rs.getString("x_pixels"));
|
map.setYPixels(rs.getString("y_pixels"));
|
map.setPointALatlngXyCoordinate(rs.getString("point_a_latlng_xy_coordinate"));
|
map.setPointBLatlngXyCoordinate(rs.getString("point_b_latlng_xy_coordinate"));
|
map.setCompany(rs.getString("company"));
|
map.setAddedBy(rs.getString("added_by"));
|
map.setAddedTime(rs.getString("added_time"));
|
map.setReserved1(rs.getString("reserved1"));
|
maps.add(map);
|
}
|
} catch (NumberFormatException | SQLException e) {
|
e.printStackTrace();
|
}
|
return maps;
|
}
|
|
public static Mapdata getMapByName(String mapName) {
|
if (maps == null || mapName == null) {
|
return null;
|
}
|
for (Mapdata m : maps) {
|
if (mapName.equals(m.getMapName())) {
|
return m;
|
}
|
}
|
return null;
|
}
|
|
public static void insertMap(Mapdata map) throws SQLException {
|
String sql = "INSERT INTO map ("
|
+ "map_type, detail_display, offline_disappear, voice_enabled, fence_display, "
|
+ "base_station_display, gateway_display, video_display, initial_view_position, "
|
+ "view_height, map_heading_angle, map_tilt_angle, terrain_disabled, tile_map_loading, "
|
+ "local_image_loading, basemap_disabled, three_d_model, located_layer, map_name,map_name_detaile, "
|
+ "actual_x_length, actual_y_length, x0_coordinate, y0_coordinate, x_pixels, y_pixels, "
|
+ "point_a_latlng_xy_coordinate, point_b_latlng_xy_coordinate, company, added_by, added_time"
|
+ ") VALUES ("
|
+ "?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?, "
|
+ "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "
|
+ "?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
|
DBConnector.executeUpdate(sql,
|
map.getMapType(),
|
map.getDetailDisplay(),
|
map.getOfflineDisappear(),
|
map.getVoiceEnabled(),
|
map.getFenceDisplay(),
|
map.getBaseStationDisplay(),
|
map.getGatewayDisplay(),
|
map.getVideoDisplay(),
|
map.getInitialViewPosition(),
|
map.getViewHeight(),
|
map.getMapHeadingAngle(),
|
map.getMapTiltAngle(),
|
map.getTerrainDisabled(),
|
map.getTileMapLoading(),
|
map.getLocalImageLoading(),
|
map.getBasemapDisabled(),
|
map.getThreeDModel(),
|
map.getLocatedLayer(),
|
map.getMapName(),
|
map.getMapNameDetaile(),
|
map.getActualXLength(),
|
map.getActualYLength(),
|
map.getX0Coordinate(),
|
map.getY0Coordinate(),
|
map.getXPixels(),
|
map.getYPixels(),
|
map.getPointALatlngXyCoordinate(),
|
map.getPointBLatlngXyCoordinate(),
|
map.getCompany(),
|
map.getAddedBy(),
|
map.getAddedTime()
|
);
|
}
|
|
public static void updateMap(Mapdata map) throws SQLException {
|
String sql = "UPDATE map SET "
|
+ "map_type = ?, detail_display = ?, offline_disappear = ?, voice_enabled = ?, "
|
+ "fence_display = ?, base_station_display = ?, gateway_display = ?, video_display = ?, "
|
+ "initial_view_position = ?, view_height = ?, map_heading_angle = ?, map_tilt_angle = ?, "
|
+ "terrain_disabled = ?, tile_map_loading = ?, local_image_loading = ?, basemap_disabled = ?, "
|
+ "three_d_model = ?, located_layer = ?, map_name = ?, map_name_detaile = ?,actual_x_length = ?, "
|
+ "actual_y_length = ?, x0_coordinate = ?, y0_coordinate = ?, x_pixels = ?, y_pixels = ?, "
|
+ "point_a_latlng_xy_coordinate = ?, point_b_latlng_xy_coordinate = ?, company = ?, "
|
+ "added_by = ?, added_time = ? "
|
+ "WHERE id = ?";
|
|
DBConnector.executeUpdate(sql,
|
map.getMapType(),
|
map.getDetailDisplay(),
|
map.getOfflineDisappear(),
|
map.getVoiceEnabled(),
|
map.getFenceDisplay(),
|
map.getBaseStationDisplay(),
|
map.getGatewayDisplay(),
|
map.getVideoDisplay(),
|
map.getInitialViewPosition(),
|
map.getViewHeight(),
|
map.getMapHeadingAngle(),
|
map.getMapTiltAngle(),
|
map.getTerrainDisabled(),
|
map.getTileMapLoading(),
|
map.getLocalImageLoading(),
|
map.getBasemapDisabled(),
|
map.getThreeDModel(),
|
map.getLocatedLayer(),
|
map.getMapName(),
|
map.getMapNameDetaile(),
|
map.getActualXLength(),
|
map.getActualYLength(),
|
map.getX0Coordinate(),
|
map.getY0Coordinate(),
|
map.getXPixels(),
|
map.getYPixels(),
|
map.getPointALatlngXyCoordinate(),
|
map.getPointBLatlngXyCoordinate(),
|
map.getCompany(),
|
map.getAddedBy(),
|
map.getAddedTime(),
|
map.getId()
|
);
|
}
|
|
public static void deleteMap(int mapId) throws SQLException {
|
String sql = "DELETE FROM map WHERE id = ?";
|
DBConnector.executeUpdate(sql, mapId);
|
}
|
|
public static String[] getAllMapNames() {
|
if (maps == null || maps.isEmpty()) {
|
return new String[0];
|
}
|
String[] mapNames = new String[maps.size()];
|
for (int i = 0; i < maps.size(); i++) {
|
mapNames[i] = maps.get(i).getMapName();
|
}
|
return mapNames;
|
}
|
|
public static boolean isMapNameExist(String mapName) {
|
if (maps == null || maps.isEmpty() || mapName == null) {
|
return false;
|
}
|
for (Mapdata map : maps) {
|
if (mapName.equals(map.getMapName())) {
|
return true;
|
}
|
}
|
return false;
|
}
|
|
public static Mapdata getMapById(int mapId) throws SQLException {
|
String sql = "SELECT * FROM map WHERE id = ?";
|
try (ResultSet rs = DBConnector.executeQuery(sql, mapId)) {
|
if (rs.next()) {
|
Mapdata map = new Mapdata();
|
map.setId(Integer.parseInt(rs.getString("id")));
|
map.setMapType(rs.getString("map_type"));
|
map.setDetailDisplay(rs.getString("detail_display"));
|
map.setOfflineDisappear(rs.getString("offline_disappear"));
|
map.setVoiceEnabled(rs.getString("voice_enabled"));
|
map.setFenceDisplay(rs.getString("fence_display"));
|
map.setBaseStationDisplay(rs.getString("base_station_display"));
|
map.setGatewayDisplay(rs.getString("gateway_display"));
|
map.setVideoDisplay(rs.getString("video_display"));
|
map.setInitialViewPosition(rs.getString("initial_view_position"));
|
map.setViewHeight(rs.getString("view_height"));
|
map.setMapHeadingAngle(rs.getString("map_heading_angle"));
|
map.setMapTiltAngle(rs.getString("map_tilt_angle"));
|
map.setTerrainDisabled(rs.getString("terrain_disabled"));
|
map.setTileMapLoading(rs.getString("tile_map_loading"));
|
map.setLocalImageLoading(rs.getString("local_image_loading"));
|
map.setBasemapDisabled(rs.getString("basemap_disabled"));
|
map.setThreeDModel(rs.getString("three_d_model"));
|
map.setLocatedLayer(rs.getString("located_layer"));
|
map.setMapName(rs.getString("map_name"));
|
map.setMapNameDetaile(rs.getString("map_name_detaile"));
|
map.setActualXLength(rs.getString("actual_x_length"));
|
map.setActualYLength(rs.getString("actual_y_length"));
|
map.setX0Coordinate(rs.getString("x0_coordinate"));
|
map.setY0Coordinate(rs.getString("y0_coordinate"));
|
map.setXPixels(rs.getString("x_pixels"));
|
map.setYPixels(rs.getString("y_pixels"));
|
map.setPointALatlngXyCoordinate(rs.getString("point_a_latlng_xy_coordinate"));
|
map.setPointBLatlngXyCoordinate(rs.getString("point_b_latlng_xy_coordinate"));
|
map.setCompany(rs.getString("company"));
|
map.setAddedBy(rs.getString("added_by"));
|
map.setAddedTime(rs.getString("added_time"));
|
map.setReserved1(rs.getString("reserved1"));
|
return map;
|
}
|
}
|
return null;
|
}
|
|
public static Vector<Csxy> get_foor_xycs() {
|
ResourceBundle bundle = loadResourceBundle(); // ʹÓÃеļÓÔØ·½·¨
|
int size = maps.size();
|
Vector<Csxy> result = new Vector<>(size);
|
|
for (int i = 0; i < size; i++) {
|
Mapdata map = maps.get(i);
|
String floor = map.getLocatedLayer();
|
String ajw = map.getPointALatlngXyCoordinate();
|
String bjw = map.getPointBLatlngXyCoordinate();
|
String[] A = ajw.split(";", -1);
|
String[] B = bjw.split(";", -1);
|
if (A.length < 4 || B.length < 4) {
|
String errorMsg = String.format(
|
bundle.getString("INVALID_POINT_FORMAT"),
|
map.getMapName()
|
);
|
JOptionPane.showMessageDialog(
|
null,
|
errorMsg,
|
bundle.getString("ERROR"),
|
JOptionPane.ERROR_MESSAGE
|
);
|
continue;
|
}
|
|
try {
|
double lon_a = Double.parseDouble(A[0]);
|
double lat_a = Double.parseDouble(A[1]);
|
double xa = Double.parseDouble(A[2]);
|
double ya = Double.parseDouble(A[3]);
|
double lon_b = Double.parseDouble(B[0]);
|
double lat_b = Double.parseDouble(B[1]);
|
double xb = Double.parseDouble(B[2]);
|
double yb = Double.parseDouble(B[3]);
|
|
if (lon_a == 0 || lon_b == 0 || lat_a == 0 || lat_b == 0) {
|
String errorMsg = String.format(
|
bundle.getString("ZERO_LATLON"),
|
map.getMapName()
|
);
|
JOptionPane.showMessageDialog(
|
null,
|
errorMsg,
|
bundle.getString("ERROR"),
|
JOptionPane.ERROR_MESSAGE
|
);
|
continue;
|
}
|
|
double[] xycs = CoordinateTranslator.computeTransformParamsWithTwoPoints(
|
lat_a, lon_a, lat_b, lon_b, xa, ya, xb, yb
|
);
|
|
Csxy csxy = new Csxy();
|
csxy.setXycs(xycs);
|
csxy.setFloor(floor);
|
csxy.setAj(lon_a);
|
csxy.setAw(lat_a);
|
|
// Ô¤ÏȼÆËã²¢´æ´¢UTM×ø±ê
|
double[] originUtm = CoordinateTranslator.ubloxraw2xy(lat_a, lon_a);
|
csxy.setOriginUtmX(originUtm[0]);
|
csxy.setOriginUtmY(originUtm[1]);
|
|
// ת»»Â¥²ãΪÕûÊý
|
try {
|
csxy.setFloorInt(Integer.parseInt(floor));
|
} catch (NumberFormatException e) {
|
csxy.setFloorInt(0);
|
}
|
|
result.add(csxy);
|
} catch (NumberFormatException e) {
|
String errorMsg = String.format(
|
bundle.getString("INVALID_COORD_NUMBER"),
|
map.getMapName()
|
);
|
JOptionPane.showMessageDialog(
|
null,
|
errorMsg,
|
bundle.getString("ERROR"),
|
JOptionPane.ERROR_MESSAGE
|
);
|
}
|
}
|
|
// ¸üÐÂÈ«¾ÖÏòÁ¿
|
csxyvc = result;
|
|
// ¹¹½¨Â¥²ãת»»»º´æ
|
Map<String, double[]> floorCache = new ConcurrentHashMap<>();
|
for (Csxy cs : csxyvc) {
|
floorCache.put(cs.getFloor(), cs.getXycs());
|
}
|
FLOOR_XYCS = Collections.unmodifiableMap(floorCache);
|
|
return csxyvc;
|
}
|
|
public static double[] getXycs(String floor) {
|
return FLOOR_XYCS.get(floor);
|
}
|
|
private static ResourceBundle loadResourceBundle() {
|
// ʹÓÃϵͳĬÈÏÓïÑÔ»·¾³
|
Locale locale = Locale.getDefault();
|
String fileName = locale.equals(Locale.ENGLISH) ?
|
"Messages_en.properties" : "Messages_zh.properties";
|
|
File langFile = new File("systemfile/" + fileName);
|
|
if (!langFile.exists()) {
|
System.err.println("ĬÈÏ×ÊÔ´ÎļþδÕÒµ½: " + langFile.getAbsolutePath());
|
try {
|
// ³¢ÊÔ´ÓÀà·¾¶¼ÓÔØ
|
return ResourceBundle.getBundle("systemfile.Messages");
|
} catch (MissingResourceException e) {
|
throw new RuntimeException("ÎÞ·¨¼ÓÔØ×ÊÔ´Îļþ", e);
|
}
|
}
|
|
try (InputStream inputStream = new FileInputStream(langFile)) {
|
return new PropertyResourceBundle(inputStream);
|
} catch (IOException e) {
|
System.err.println("ÎÞ·¨¼ÓÔØ×ÊÔ´Îļþ: " + e.getMessage());
|
throw new RuntimeException(e);
|
}
|
}
|
}
|