| | |
| | | @Component |
| | | public class NavigateMapData { |
| | | |
| | | private Integer lev;//地图楼层 |
| | | // private Integer lev;//地图楼层 |
| | | // |
| | | // public Integer getLev() { |
| | | // return lev; |
| | | // } |
| | | // |
| | | // public void setLev(Integer lev) { |
| | | // this.lev = lev; |
| | | // } |
| | | |
| | | public Integer getLev() { |
| | | return lev; |
| | | } |
| | | |
| | | public void setLev(Integer lev) { |
| | | this.lev = lev; |
| | | } |
| | | |
| | | public int[][] getData() { |
| | | return getData(NavigationMapType.NONE.id, null, null);//默认读取无过滤的全部地图数据 |
| | | } |
| | | |
| | | public int[][] getData(Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) { |
| | | public int[][] getData(Integer lev, Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) { |
| | | try { |
| | | // RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class); |
| | | // Object object = redisUtil.get(RedisKeyType.BASIC_MAP.key + lev); |
| | |
| | | InputStream inputStream = classPathResource.getInputStream(); |
| | | byte[] buffer = new byte[inputStream.available()]; |
| | | inputStream.read(buffer); |
| | | File file = File.createTempFile("prefix","suffix"); |
| | | File file = File.createTempFile("prefix", "suffix"); |
| | | try (OutputStream outStream = new FileOutputStream(file)) { |
| | | outStream.write(buffer); |
| | | } |
| | |
| | | /** |
| | | * 尝试从redis获取数据 |
| | | */ |
| | | public int[][] getDataFromRedis(Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) { |
| | | public int[][] getDataFromRedis(Integer lev, Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) { |
| | | RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class); |
| | | Object o = redisUtil.get(RedisKeyType.MAP.key + lev); |
| | | if (o == null) { |
| | |
| | | } |
| | | |
| | | BasMap basMap = JSON.parseObject(o.toString(), BasMap.class); |
| | | return this.getDataFormString(basMap.getData(), mapType, whitePoints, shuttlePoints); |
| | | return this.getDataFormString(lev, basMap.getData(), mapType, whitePoints, shuttlePoints); |
| | | } |
| | | |
| | | /** |
| | | * 从List数据中获取地图 |
| | | */ |
| | | public int[][] getDataFormString(String data, Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) { |
| | | public int[][] getDataFormString(Integer lev, String data, Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) { |
| | | ArrayList arrayList = JSON.parseObject(data, ArrayList.class); |
| | | List<List<MapNode>> lists = filterMap(mapType, arrayList, lev, whitePoints, shuttlePoints);//过滤地图数据 |
| | | int[][] map = new int[lists.size()][]; |
| | |
| | | return map; |
| | | } |
| | | |
| | | //获取JSON格式数据 |
| | | public List<List<MapNode>> getJsonData(Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) { |
| | | try { |
| | | // RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class); |
| | | // Object object = redisUtil.get(RedisKeyType.BASIC_MAP.key + lev); |
| | | // if (object == null) { |
| | | // return null; |
| | | // //获取JSON格式数据 |
| | | // public List<List<MapNode>> getJsonData(Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) { |
| | | // try { |
| | | //// RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class); |
| | | //// Object object = redisUtil.get(RedisKeyType.BASIC_MAP.key + lev); |
| | | //// if (object == null) { |
| | | //// return null; |
| | | //// } |
| | | //// |
| | | //// //解析json地图数据 |
| | | //// ArrayList arrayList = JSON.parseObject(object.toString(), ArrayList.class); |
| | | //// List<List<MapNode>> lists = filterMap(mapType, arrayList, lev, whitePoints, shuttlePoints);//过滤地图数据 |
| | | //// return lists; |
| | | // |
| | | // |
| | | // String mapFilename = "map_" + lev + ".json"; |
| | | // ClassPathResource classPathResource = new ClassPathResource(mapFilename); |
| | | // InputStream inputStream = classPathResource.getInputStream(); |
| | | // byte[] buffer = new byte[inputStream.available()]; |
| | | // inputStream.read(buffer); |
| | | // File file = File.createTempFile("prefix","suffix"); |
| | | // try (OutputStream outStream = new FileOutputStream(file)) { |
| | | // outStream.write(buffer); |
| | | // } |
| | | // |
| | | // //解析json地图数据 |
| | | // ArrayList arrayList = JSON.parseObject(object.toString(), ArrayList.class); |
| | | // List<List<MapNode>> lists = filterMap(mapType, arrayList, lev, whitePoints, shuttlePoints);//过滤地图数据 |
| | | // return lists; |
| | | |
| | | |
| | | String mapFilename = "map_" + lev + ".json"; |
| | | ClassPathResource classPathResource = new ClassPathResource(mapFilename); |
| | | InputStream inputStream = classPathResource.getInputStream(); |
| | | byte[] buffer = new byte[inputStream.available()]; |
| | | inputStream.read(buffer); |
| | | File file = File.createTempFile("prefix","suffix"); |
| | | try (OutputStream outStream = new FileOutputStream(file)) { |
| | | outStream.write(buffer); |
| | | } |
| | | |
| | | StringBuffer stringBuffer = new StringBuffer(); |
| | | if (file.isFile() && file.exists()) { |
| | | InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "GBK"); |
| | | BufferedReader br = new BufferedReader(isr); |
| | | String lineTxt = null; |
| | | while ((lineTxt = br.readLine()) != null) { |
| | | stringBuffer.append(lineTxt); |
| | | } |
| | | br.close(); |
| | | |
| | | //解析json地图数据 |
| | | ArrayList arrayList = JSON.parseObject(stringBuffer.toString(), ArrayList.class); |
| | | List<List<MapNode>> lists = filterMap(mapType, arrayList, lev, whitePoints, shuttlePoints);//过滤地图数据 |
| | | |
| | | if (!file.delete()) { |
| | | System.out.println("临时文件删除失败"); |
| | | } |
| | | |
| | | return lists; |
| | | } else { |
| | | System.out.println("文件不存在!"); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | // StringBuffer stringBuffer = new StringBuffer(); |
| | | // if (file.isFile() && file.exists()) { |
| | | // InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "GBK"); |
| | | // BufferedReader br = new BufferedReader(isr); |
| | | // String lineTxt = null; |
| | | // while ((lineTxt = br.readLine()) != null) { |
| | | // stringBuffer.append(lineTxt); |
| | | // } |
| | | // br.close(); |
| | | // |
| | | // //解析json地图数据 |
| | | // ArrayList arrayList = JSON.parseObject(stringBuffer.toString(), ArrayList.class); |
| | | // List<List<MapNode>> lists = filterMap(mapType, arrayList, lev, whitePoints, shuttlePoints);//过滤地图数据 |
| | | // |
| | | // if (!file.delete()) { |
| | | // System.out.println("临时文件删除失败"); |
| | | // } |
| | | // |
| | | // return lists; |
| | | // } else { |
| | | // System.out.println("文件不存在!"); |
| | | // } |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // return null; |
| | | // } |
| | | |
| | | //获取JSON格式数据 |
| | | public List<List<MapNode>> getJsonData(Integer lev, Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) { |