826220679@qq.com
2025-08-07 4d6cd980c5c69e4d9d150669c89734642297e0cd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
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);
        }
    }
}