Merge remote-tracking branch 'origin/master'
	
		
		4 files added
	
		
		10 files modified
	
	
 
	
	
	
	
	
	
	
	
|  |  |  | 
|---|
|  |  |  | WebSocketServerNew.deviceService=deviceService; | 
|---|
|  |  |  | BSWebsocketServer.deviceService=deviceService; | 
|---|
|  |  |  | BSAQIWebSocketServer.deviceService=deviceService; | 
|---|
|  |  |  | BSAQIWebSocketServerTest.deviceService=deviceService; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | public void setMessageService(AccountService accountService){ | 
|---|
|  |  |  | 
|---|
|  |  |  | BSWebsocketServer.sensorService=sensorService; | 
|---|
|  |  |  | BSAQIWebSocketServer.sensorService=sensorService; | 
|---|
|  |  |  | ElectronicSWebSocketServer.sensorService=sensorService; | 
|---|
|  |  |  | BSAQIWebSocketServerTest.sensorService=sensorService; | 
|---|
|  |  |  | ElectronicSWebSocketServer.sensorService=sensorService; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | public void setSensorUnitService( SensorUnitService sensorUnitService){ | 
|---|
|  |  |  | 
|---|
|  |  |  | AlarmConfigService alarmConfigService; | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | AlarmService alarmService; | 
|---|
|  |  |  | @RequestMapping(value = "/count-by-times", method = RequestMethod.GET) | 
|---|
|  |  |  | /*    @RequestMapping(value = "/count-by-times", method = RequestMethod.GET) | 
|---|
|  |  |  | public ResultBean<List<Map>> countByTimes(Date start, Date end,@RequestParam(value = "timeUnits")Optional<TimeUnits> timeUnits) throws ParseException { | 
|---|
|  |  |  | return  new ResultBean<>(alarmService.countByTimes(start,end,timeUnits.isPresent()?timeUnits.get():null)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }*/ | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | public ResultBean<Integer> countByExample(PageBean pageBean){ | 
|---|
|  |  |  | return  new ResultBean<Integer>(deviceService.countByExample(pageBean)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @GetMapping("count-by-times") | 
|---|
|  |  |  | /*    @GetMapping("count-by-times") | 
|---|
|  |  |  | public ResultBean<List<Map>> countByTimes(Date start, Date end){ | 
|---|
|  |  |  | return  new ResultBean<List<Map>>(deviceService.countByTimes(start,end,"%Y-%m")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }*/ | 
|---|
|  |  |  | @GetMapping("page-list") | 
|---|
|  |  |  | public PageBean pageList(PageBean pageBean) { | 
|---|
|  |  |  | return deviceService.queryByPageBean(pageBean); | 
|---|
|  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private DeviceAdjustValueTimingService deviceAdjustValueTimingService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private PollutioSourcePointService pollutioSourcePointService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private HistoryFiveMinutelyService historyFiveMinutelyService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * Screen login. 大屏登录 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | 
|---|
|  |  |  | parameters.put("sensors", Arrays.asList(sensorKey)); | 
|---|
|  |  |  | // monitorPointService.isCompensateCalculation(parameters); | 
|---|
|  |  |  | list = historyMinutelyService.getMonitorPointOrDeviceAvgData(parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /* 0点的数据是昨天11点到今天0点的,界面显示1-24点的,所以不需要0点的数据,但需要单独查询24点的数据 | 
|---|
|  |  |  | 因为改动以前24点的数据是23-24,现在24点的数据是第二天0点的数据, | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | /*改动范围start-------------------------------------------------------------------------*/ | 
|---|
|  |  |  | list.remove(0); | 
|---|
|  |  |  | //if (list.size() == 23) { | 
|---|
|  |  |  | Iterator<Map<String, Object>> iterator = list.iterator(); | 
|---|
|  |  |  | while (iterator.hasNext()) { | 
|---|
|  |  |  | Map<String, Object> next = iterator.next(); | 
|---|
|  |  |  | String hour = next.get("time").toString().substring(11, 13); | 
|---|
|  |  |  | if ("00".equals(hour)) { | 
|---|
|  |  |  | iterator.remove(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 
|---|
|  |  |  | SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd"); | 
|---|
|  |  |  | //获取全格式时间yyyy-MM-dd HH:mm:ss | 
|---|
|  |  |  | 
|---|
|  |  |  | List<Map<String, Object>> nextDayList = historyMinutelyService.getMonitorPointOrDeviceAvgData(parameters); | 
|---|
|  |  |  | if(!ObjectUtils.isEmpty(nextDayList)){ | 
|---|
|  |  |  | time1=time1.replaceAll(" 00:00:00"," 24"); | 
|---|
|  |  |  | Map<String, Object> datas = nextDayList.get(0); | 
|---|
|  |  |  | datas.put("time",time1); | 
|---|
|  |  |  | list.add(datas); | 
|---|
|  |  |  | for (Map<String, Object> map : nextDayList) { | 
|---|
|  |  |  | String time = map.get("time").toString().substring(11, 13); | 
|---|
|  |  |  | if("00".equals(time)){ | 
|---|
|  |  |  | map.put("time", time1); | 
|---|
|  |  |  | list.add(map); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //} | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /*改动范围end-------------------------------------------------------------------------*/ | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | //System.out.println(paramsJson); | 
|---|
|  |  |  | model.addObject("carTrajectoryParams", paramsJson); | 
|---|
|  |  |  | model.setViewName("cartrajectory"); | 
|---|
|  |  |  | return model; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | StringBuilder msg = new StringBuilder(); | 
|---|
|  |  |  | msg.append(" param[0] mac:"); | 
|---|
|  |  |  | msg.append(mac); | 
|---|
|  |  |  | log.warn(msg); | 
|---|
|  |  |  | model.setViewName("403"); | 
|---|
|  |  |  | return model; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping("/carTrajectoryNew") | 
|---|
|  |  |  | @ApiOperation(value = "显示走航车轨迹", notes = "显示走航车轨迹") | 
|---|
|  |  |  | @ApiImplicitParams(value = { | 
|---|
|  |  |  | @ApiImplicitParam(name = "mac", value = "设备mac(格式:p5dnd7a0392081)", required = true, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "startTime", value = "开始时间(格式:2020-03-19-14)", required = true, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "endTime", value = "结束时间(格式:2020-03-19-17)", required = true, paramType = "query", dataType = "String") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | public ModelAndView carTrajectoryNew(ModelAndView model, HttpServletRequest request) throws Exception { | 
|---|
|  |  |  | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); | 
|---|
|  |  |  | String st = parameters.get("startTime").toString(); | 
|---|
|  |  |  | String startYearAndDay = st.substring(0, st.lastIndexOf("-")); | 
|---|
|  |  |  | String startHour = st.substring(st.lastIndexOf("-") + 1); | 
|---|
|  |  |  | String startTime = startYearAndDay + " " + startHour + ":00:00"; | 
|---|
|  |  |  | String et = parameters.get("endTime").toString(); | 
|---|
|  |  |  | String endYearAndDay = et.substring(0, st.lastIndexOf("-")); | 
|---|
|  |  |  | String endHour = et.substring(et.lastIndexOf("-") + 1); | 
|---|
|  |  |  | String endTime = endYearAndDay + " " + endHour + ":00:00"; | 
|---|
|  |  |  | parameters.put("startTime", startTime); | 
|---|
|  |  |  | parameters.put("endTime", endTime); | 
|---|
|  |  |  | String mac = parameters.get("mac").toString(); | 
|---|
|  |  |  | if (mac != null && mac.length() != 0) { | 
|---|
|  |  |  | List<List<Map<String, Object>>> sensorData = historyService.getCarSensorData(parameters); | 
|---|
|  |  |  | Map<String, String> sensorsMap = sensorService.getSensorsMap(parameters); | 
|---|
|  |  |  | List<Map<String, Object>> sensorList = new ArrayList<>(); | 
|---|
|  |  |  | if (sensorData.size() == 3) { | 
|---|
|  |  |  | sensorList = sensorData.get(0); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | JSONObject params = new JSONObject(); | 
|---|
|  |  |  | params.put("sensorInfo", sensorList); | 
|---|
|  |  |  | params.put("sensorsMap", sensorsMap); | 
|---|
|  |  |  | String paramsJson = params.toJSONString(); | 
|---|
|  |  |  | model.addObject("carTrajectoryParams", paramsJson); | 
|---|
|  |  |  | model.setViewName("cartrajectoryNew"); | 
|---|
|  |  |  | return model; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | StringBuilder msg = new StringBuilder(); | 
|---|
|  |  |  | 
|---|
|  |  |  | List<Device> devicesList = deviceService.getDevicesByAccountId(id); | 
|---|
|  |  |  | return devicesList; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping("/unorganizedEmissionsFiveMinute") | 
|---|
|  |  |  | @ApiOperation(value = "无组织排放五分钟", notes = "无组织排放五分钟") | 
|---|
|  |  |  | @ApiImplicitParams(value = { | 
|---|
|  |  |  | @ApiImplicitParam(name = "monitorPointId", value = "公司Id", required = true, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "sensorKey", value = "因子", required = true, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "realTime", value = "实时", required = true, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "accountId", value = "用户id", required = false, paramType = "query", dataType = "String")}) | 
|---|
|  |  |  | public ModelAndView unorganizedEmissionsBackupsV2(HttpServletRequest request, ModelAndView model) { | 
|---|
|  |  |  | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); | 
|---|
|  |  |  | String sensorKey = parameters.get("sensorKey").toString(); | 
|---|
|  |  |  | //第一步,获取污染源点 | 
|---|
|  |  |  | PollutionSourcePoint pollutionSourcePoint = pollutioSourcePointService.selectByMonitorPointId(539); | 
|---|
|  |  |  | //获取站点的所有设备 | 
|---|
|  |  |  | List<Device> deviceList = deviceService.getDevicesByMonitorPointId(539); | 
|---|
|  |  |  | //获取五分钟数据 | 
|---|
|  |  |  | Map<String,Object> pa = new HashMap<>(); | 
|---|
|  |  |  | //获取开始时间和结束时间 | 
|---|
|  |  |  | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 
|---|
|  |  |  | Calendar beforeTime = Calendar.getInstance(); | 
|---|
|  |  |  | Date newTime = beforeTime.getTime(); | 
|---|
|  |  |  | beforeTime.add(Calendar.MINUTE,-5); | 
|---|
|  |  |  | Date startTime = beforeTime.getTime(); | 
|---|
|  |  |  | beforeTime.add(Calendar.MINUTE,6); | 
|---|
|  |  |  | Date endTime = beforeTime.getTime(); | 
|---|
|  |  |  | //pa.put("sensorKey","e1"); | 
|---|
|  |  |  | pa.put("yearAndMonth",sdf.format(newTime).substring(0,7).replace("-","")); | 
|---|
|  |  |  | pa.put("startTime",startTime); | 
|---|
|  |  |  | pa.put("endTime",endTime); | 
|---|
|  |  |  | List<String> macs = new ArrayList<>(); | 
|---|
|  |  |  | List<String> sensorKeys = new ArrayList<>(); | 
|---|
|  |  |  | for (Device device:deviceList) { | 
|---|
|  |  |  | macs.add(device.getMac()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | sensorKeys.add(sensorKey); | 
|---|
|  |  |  | sensorKeys.add("e18"); | 
|---|
|  |  |  | sensorKeys.add("e23"); | 
|---|
|  |  |  | pa.put("macs",macs); | 
|---|
|  |  |  | pa.put("sensorKeys",sensorKeys); | 
|---|
|  |  |  | pa.put("macNumber",macs.size()); | 
|---|
|  |  |  | List<Map<String, Object>> fiveMinuteDataList = historyFiveMinutelyService.getFiveMinutesDataByMacsAndTimeSolt(pa); | 
|---|
|  |  |  | //声明数组,存放所有设备的数值 | 
|---|
|  |  |  | double[] allDeviceData = new double[fiveMinuteDataList.size()]; | 
|---|
|  |  |  | int i = 0; | 
|---|
|  |  |  | //计算风向 | 
|---|
|  |  |  | List<Map<String,Object>> windList = new ArrayList<>(); | 
|---|
|  |  |  | for (Map map:fiveMinuteDataList) { | 
|---|
|  |  |  | String[] wind_speed = map.get("e18").toString().split(","); | 
|---|
|  |  |  | if (!map.containsKey("e23")){ | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String[] wind_direction = map.get("e23").toString().split(","); | 
|---|
|  |  |  | Map<String,Object> windMap = new HashMap<>(); | 
|---|
|  |  |  | windMap.put("wind_speed",wind_speed[0].substring(1,wind_speed[0].length())); | 
|---|
|  |  |  | windMap.put("wind_direction",wind_direction[0].substring(1,wind_direction[0].length())); | 
|---|
|  |  |  | windList.add(windMap); | 
|---|
|  |  |  | String[] sensorArr = map.get(sensorKey).toString().split(","); | 
|---|
|  |  |  | double sensorData = Double.parseDouble(sensorArr[0].substring(1,sensorArr[0].length())); | 
|---|
|  |  |  | allDeviceData[i] = sensorData; | 
|---|
|  |  |  | i = i+1; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //计算平均风向和风速 | 
|---|
|  |  |  | Map<String,Double> res = WindUtils.getWind_direction_speed(windList); | 
|---|
|  |  |  | //计算该站点的点与污染源点的角度 | 
|---|
|  |  |  | Map<String,Double> angleMap = new HashMap(); | 
|---|
|  |  |  | MyLatLng pollutionSourcePoint_log_lat = new MyLatLng(pollutionSourcePoint.getLongitude(),pollutionSourcePoint.getLatitude()); | 
|---|
|  |  |  | for (Device device:deviceList) { | 
|---|
|  |  |  | MyLatLng device_log_lat = new MyLatLng(device.getLongitude(),device.getLatitude()); | 
|---|
|  |  |  | //以设备为坐标原点,与污染源连线的角度 | 
|---|
|  |  |  | double angle = mapUtils.getAngle(device_log_lat,pollutionSourcePoint_log_lat); | 
|---|
|  |  |  | angleMap.put(device.getMac(),angle); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Map<String,Double> disparityMap = new HashMap<>(); | 
|---|
|  |  |  | for (String key:angleMap.keySet()) { | 
|---|
|  |  |  | double angleDisparity = Math.abs(angleMap.get(key)-res.get("wind_direction")); | 
|---|
|  |  |  | if (angleDisparity>180){ | 
|---|
|  |  |  | angleDisparity = 360-angleDisparity; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | disparityMap.put(key,angleDisparity); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Optional<Map.Entry<String, Double>> minDisparity = disparityMap.entrySet() | 
|---|
|  |  |  | .stream() | 
|---|
|  |  |  | .min(Map.Entry.comparingByValue()); | 
|---|
|  |  |  | //留下的任务:循环disparityMap,查出与minDisparity相等的值的key,以防出现两个点的角度差一样 | 
|---|
|  |  |  | List<String> minAngleDisparityMacList = new ArrayList<>(); | 
|---|
|  |  |  | for (String key:disparityMap.keySet()) { | 
|---|
|  |  |  | if (disparityMap.get(key) == minDisparity.get().getValue()){ | 
|---|
|  |  |  | minAngleDisparityMacList.add(minDisparity.get().getKey()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //定义一个map,存放设备点 | 
|---|
|  |  |  | Map<String,Object> fiveMinuteDataMap = new HashMap(); | 
|---|
|  |  |  | if (minAngleDisparityMacList.size()<2){//只有一个点 | 
|---|
|  |  |  | for (Map fiveMinuteData:fiveMinuteDataList) { | 
|---|
|  |  |  | if (fiveMinuteData.get("mac").toString().equals(minAngleDisparityMacList.get(0))){ | 
|---|
|  |  |  | fiveMinuteDataMap.putAll(fiveMinuteData); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Device referenceDevice = new Device(); | 
|---|
|  |  |  | for (Device device:deviceList) { | 
|---|
|  |  |  | if (device.getMac().equals(fiveMinuteDataMap.get("mac"))){ | 
|---|
|  |  |  | referenceDevice = device; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //计算污染平均值 | 
|---|
|  |  |  | double sum = 0; | 
|---|
|  |  |  | for (int j=0;j<allDeviceData.length;j++) { | 
|---|
|  |  |  | sum = sum+allDeviceData[j]; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | double deviceDataAvg = sum/allDeviceData.length; | 
|---|
|  |  |  | //计算污染源点与设备点之间的距离 | 
|---|
|  |  |  | double distance = mapUtils.getDistance(pollutionSourcePoint.getLongitude(),pollutionSourcePoint.getLatitude(),referenceDevice.getLongitude(),referenceDevice.getLatitude()); | 
|---|
|  |  |  | //已知距离,角度,求x,y | 
|---|
|  |  |  | double x = Math.cos(Math.toRadians(minDisparity.get().getValue()))*distance; | 
|---|
|  |  |  | double y = Math.sin(Math.toRadians(minDisparity.get().getValue()))*distance; | 
|---|
|  |  |  | //获取设备的数值 | 
|---|
|  |  |  | String[] fiveMinuteData = fiveMinuteDataMap.get(sensorKey).toString().split(","); | 
|---|
|  |  |  | double c = Double.parseDouble(fiveMinuteData[0].substring(1,fiveMinuteData[0].length()))-deviceDataAvg; | 
|---|
|  |  |  | //计算源强 | 
|---|
|  |  |  | double pollutionSourceIntensity = EmissionDataUtil.getPollutionSourceIntensity(c,x,y,res.get("wind_speed")); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //存放地图中心点 | 
|---|
|  |  |  | Map<String,Object> center = new HashMap<>(); | 
|---|
|  |  |  | center.put("lng",120.997119); | 
|---|
|  |  |  | center.put("lat",31.451714); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //存放各个点位经纬度及数值 | 
|---|
|  |  |  | List<Map<String,Double>> numericalValueList = new ArrayList<>(); | 
|---|
|  |  |  | Map<String,Double> numericalValueMap = new HashMap<>(); | 
|---|
|  |  |  | numericalValueMap.put("lng",120.997119); | 
|---|
|  |  |  | numericalValueMap.put("lat",31.451714); | 
|---|
|  |  |  | numericalValueMap.put("count",0.027); | 
|---|
|  |  |  | numericalValueList.add(numericalValueMap); | 
|---|
|  |  |  | Map<String,Double> numericalValueMap2 = new HashMap<>(); | 
|---|
|  |  |  | numericalValueMap2.put("lng",120.99516); | 
|---|
|  |  |  | numericalValueMap2.put("lat",31.448664); | 
|---|
|  |  |  | numericalValueMap2.put("count",0.029); | 
|---|
|  |  |  | numericalValueList.add(numericalValueMap2); | 
|---|
|  |  |  | Map<String,Double> numericalValueMap3 = new HashMap<>(); | 
|---|
|  |  |  | numericalValueMap3.put("lng",120.998538); | 
|---|
|  |  |  | numericalValueMap3.put("lat",31.449289); | 
|---|
|  |  |  | numericalValueMap3.put("count",0.033); | 
|---|
|  |  |  | numericalValueList.add(numericalValueMap3); | 
|---|
|  |  |  | Map<String,Double> numericalValueMap4 = new HashMap<>(); | 
|---|
|  |  |  | numericalValueMap4.put("lng",120.998628); | 
|---|
|  |  |  | numericalValueMap4.put("lat",31.452027); | 
|---|
|  |  |  | numericalValueMap4.put("count",0.025); | 
|---|
|  |  |  | numericalValueList.add(numericalValueMap4); | 
|---|
|  |  |  | Map<String,Double> numericalValueMap5 = new HashMap<>(); | 
|---|
|  |  |  | numericalValueMap5.put("lng",121.000383); | 
|---|
|  |  |  | numericalValueMap5.put("lat",31.451469); | 
|---|
|  |  |  | numericalValueMap5.put("count",0.05); | 
|---|
|  |  |  | numericalValueList.add(numericalValueMap5); | 
|---|
|  |  |  | Map<String,Double> numericalValueMap6 = new HashMap<>(); | 
|---|
|  |  |  | numericalValueMap6.put("lng",120.999908); | 
|---|
|  |  |  | numericalValueMap6.put("lat",31.449389); | 
|---|
|  |  |  | numericalValueMap6.put("count",0.04); | 
|---|
|  |  |  | numericalValueList.add(numericalValueMap6); | 
|---|
|  |  |  | Map<String,Double> numericalValueMap7 = new HashMap<>(); | 
|---|
|  |  |  | numericalValueMap7.put("lng",120.998519); | 
|---|
|  |  |  | numericalValueMap7.put("lat",31.450588); | 
|---|
|  |  |  | numericalValueMap7.put("count",0.10); | 
|---|
|  |  |  | numericalValueList.add(numericalValueMap7); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | JSONObject params = new JSONObject(); | 
|---|
|  |  |  | params.put("accountId",190); | 
|---|
|  |  |  | params.put("level",17); | 
|---|
|  |  |  | params.put("center",center); | 
|---|
|  |  |  | params.put("points",numericalValueList); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取公司信息 | 
|---|
|  |  |  | //JSONObject params=monitorPointService.getMonitorPointById(monitPointId,Time,3,sensor); | 
|---|
|  |  |  | // model.addObject("params",params); | 
|---|
|  |  |  | model.addObject("params", params); | 
|---|
|  |  |  | model.setViewName("unorganizedMapV2"); | 
|---|
|  |  |  | return model; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | Map<String,Object> getFiveMinutesDataByMac(Map<String,Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Map<String,Object>> getFiveMinutesSersorDataByMacsAndTime(Map<String,Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Map<String,Object>> getFiveMinutesDataByMacsAndTimeSolt(Map<String,Object> parameters); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | Map<String,Object> getFiveMinutesDataByMac(Map<String, Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Map<String, Object>> getFiveMinutesSersorDataByMacsAndTime(Map<String,Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Map<String, Object>> getFiveMinutesDataByMacsAndTimeSolt(Map<String,Object> parameters); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | return historyFiveMinutelyMapper.getFiveMinutesSersorDataByMacsAndTime(parameters); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<Map<String, Object>> getFiveMinutesDataByMacsAndTimeSolt(Map<String, Object> parameters) { | 
|---|
|  |  |  | ValidateUtil.notNull(parameters,"查询五分钟数据参数为空"); | 
|---|
|  |  |  | return historyFiveMinutelyMapper.getFiveMinutesDataByMacsAndTimeSolt(parameters); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | String startTime = parameters.get("startTime").toString(); | 
|---|
|  |  |  | DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); | 
|---|
|  |  |  | LocalDateTime startTimeLocalDateTime = LocalDateTime.parse(startTime, dateTimeFormatter); | 
|---|
|  |  |  | LocalDateTime today = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS); | 
|---|
|  |  |  | LocalDateTime startTimeDay = startTimeLocalDateTime.truncatedTo(ChronoUnit.DAYS); | 
|---|
|  |  |  | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM"); | 
|---|
|  |  |  | int format = Integer.parseInt(sdf.format(new Date())); | 
|---|
|  |  |  | int year = startTimeLocalDateTime.getYear(); | 
|---|
|  |  |  | int month = startTimeLocalDateTime.getMonthValue(); | 
|---|
|  |  |  | String monthStr = month < 10 ? ("0" + month) : month + ""; | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | parameters.put("sensorKeys", sensorKeys); | 
|---|
|  |  |  | List<Map<String, Object>> listMap = null; | 
|---|
|  |  |  | /*if (today.compareTo(startTimeDay) == 0) { | 
|---|
|  |  |  | listMap = historyMapper.listGetSensorData(parameters); | 
|---|
|  |  |  | }*/ | 
|---|
|  |  |  | //if (CollectionUtils.isEmpty(listMap)) { | 
|---|
|  |  |  | listMap = historyMapper.getCarSensorData(parameters); | 
|---|
|  |  |  | if (CollectionUtils.isEmpty(listMap)) { | 
|---|
|  |  |  | if (year <= 2019) { | 
|---|
|  |  |  | listMap = historyMinutelyMapper.getSensorData(parameters); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | if (Integer.parseInt(yearAndMonth) <= format) { | 
|---|
|  |  |  | parameters.put("yearAndMonth", yearAndMonth); | 
|---|
|  |  |  | listMap = historyMinutelyMapper.getSensorData2020(parameters); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //} | 
|---|
|  |  |  | List<List<Map<String, Object>>> listMaps = new ArrayList<>(); | 
|---|
|  |  |  | List<Map<String, Object>> listMapAvg = new ArrayList<>(); | 
|---|
|  |  |  | 
|---|
|  |  |  | package com.moral.util; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | 
|---|
|  |  |  | u1 = 0; | 
|---|
|  |  |  | v1 = wind_speed*1; | 
|---|
|  |  |  | }else if (0<wind_direction&&wind_direction<90){ | 
|---|
|  |  |  | u1 = wind_speed*Math.sin(wind_direction); | 
|---|
|  |  |  | v1 = wind_speed*Math.cos(wind_direction); | 
|---|
|  |  |  | u1 = wind_speed*Math.sin(Math.toRadians(wind_direction)); | 
|---|
|  |  |  | v1 = wind_speed*Math.cos(Math.toRadians(wind_direction)); | 
|---|
|  |  |  | }else if (wind_direction == 90){ | 
|---|
|  |  |  | u1 = wind_speed*1; | 
|---|
|  |  |  | v1 = 0; | 
|---|
|  |  |  | }else if (90<wind_direction&&wind_direction<180){ | 
|---|
|  |  |  | u1 = wind_speed*Math.sin(180-wind_direction); | 
|---|
|  |  |  | v1 = -1*wind_speed*Math.cos(180-wind_direction); | 
|---|
|  |  |  | u1 = wind_speed*Math.sin(Math.toRadians(180-wind_direction)); | 
|---|
|  |  |  | v1 = -1*wind_speed*Math.cos(Math.toRadians(180-wind_direction)); | 
|---|
|  |  |  | }else if (wind_direction == 180){ | 
|---|
|  |  |  | u1 = 0; | 
|---|
|  |  |  | v1 = wind_speed*-1; | 
|---|
|  |  |  | }else if (180<wind_direction&&wind_direction<270){ | 
|---|
|  |  |  | u1 = -1*wind_speed*Math.sin(wind_direction-180); | 
|---|
|  |  |  | v1 = -1*wind_speed*Math.cos(wind_direction-180); | 
|---|
|  |  |  | u1 = -1*wind_speed*Math.sin(Math.toRadians(wind_direction-180)); | 
|---|
|  |  |  | v1 = -1*wind_speed*Math.cos(Math.toRadians(wind_direction-180)); | 
|---|
|  |  |  | }else if (wind_direction == 270){ | 
|---|
|  |  |  | u1 = wind_speed*-1; | 
|---|
|  |  |  | v1 = 0; | 
|---|
|  |  |  | }else if (270<wind_direction&&wind_direction<360){ | 
|---|
|  |  |  | u1 = wind_speed*Math.sin(360-wind_direction); | 
|---|
|  |  |  | v1 = -1*wind_speed*Math.cos(360-wind_direction); | 
|---|
|  |  |  | u1 = wind_speed*Math.sin(Math.toRadians(360-wind_direction)); | 
|---|
|  |  |  | v1 = -1*wind_speed*Math.cos(Math.toRadians(360-wind_direction)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | u = u+u1; | 
|---|
|  |  |  | v = v+v1; | 
|---|
|  |  |  | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",0.0); | 
|---|
|  |  |  | }else if (u==0&&v>0){ | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_direction",0.0); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",v); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",v/list.size()); | 
|---|
|  |  |  | }else if (u>0&&v>0){ | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_direction",Math.atan2(u,v)); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",Math.sqrt(u*u+v*v)); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_direction",Math.toDegrees(Math.atan2(u,v))); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",Math.sqrt(u*u+v*v)/list.size()); | 
|---|
|  |  |  | }else if (u>0&&v==0){ | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_direction",90.0); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",u); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",u/list.size()); | 
|---|
|  |  |  | }else if (u>0&&v<0){ | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_direction",Math.atan2(-v,u)+90); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",Math.sqrt(u*u+v*v)); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_direction",Math.toDegrees(Math.atan2(-v,u))+90); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",Math.sqrt(u*u+v*v)/list.size()); | 
|---|
|  |  |  | }else if (u==0&&v<0){ | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_direction",180.0); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",-v); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",Math.abs(v)/list.size()); | 
|---|
|  |  |  | }else if (u<0&&v<0){ | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_direction",Math.atan2(-u,-v)+180); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",Math.sqrt(u*u+v*v)); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_direction",Math.toDegrees(Math.atan2(-u,-v))+180); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",Math.sqrt(u*u+v*v)/list.size()); | 
|---|
|  |  |  | }else if (u<0&&v==0){ | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_direction",270.0); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",-u); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",Math.abs(u)/list.size()); | 
|---|
|  |  |  | }else if (u<0&&v>0){ | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_direction",Math.atan2(v,-u)+270); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",Math.sqrt(u*u+v*v)); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_direction",Math.toDegrees(Math.atan2(v,-u))+270); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",Math.sqrt(u*u+v*v)/list.size()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return windDirectionSpeedMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /*public static void main(String[] args) { | 
|---|
|  |  |  | List list = new ArrayList(); | 
|---|
|  |  |  | Map map = new HashMap(); | 
|---|
|  |  |  | Map map2 = new HashMap(); | 
|---|
|  |  |  | map.put("wind_direction",45); | 
|---|
|  |  |  | map.put("wind_speed",1); | 
|---|
|  |  |  | map2.put("wind_direction",45); | 
|---|
|  |  |  | map2.put("wind_speed",1); | 
|---|
|  |  |  | list.add(map); | 
|---|
|  |  |  | list.add(map2); | 
|---|
|  |  |  | Map<String, Double> re = getWind_direction_speed(list); | 
|---|
|  |  |  | System.out.println(re); | 
|---|
|  |  |  | System.out.println(Math.toRadians(45)); | 
|---|
|  |  |  | System.out.println(Math.sin(Math.toRadians(45))); | 
|---|
|  |  |  | System.out.println(Math.cos(Math.toRadians(45))); | 
|---|
|  |  |  | }*/ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
| New file | 
|  |  |  | 
|---|
|  |  |  | package com.moral.webSocketServer; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.moral.entity.Device; | 
|---|
|  |  |  | import com.moral.entity.Sensor; | 
|---|
|  |  |  | import com.moral.service.DeviceService; | 
|---|
|  |  |  | import com.moral.service.SensorService; | 
|---|
|  |  |  | import com.moral.util.RabbitMQUtils; | 
|---|
|  |  |  | import com.rabbitmq.client.*; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.springframework.stereotype.Component; | 
|---|
|  |  |  | import org.springframework.util.ObjectUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.PostConstruct; | 
|---|
|  |  |  | import javax.websocket.*; | 
|---|
|  |  |  | import javax.websocket.server.PathParam; | 
|---|
|  |  |  | import javax.websocket.server.ServerEndpoint; | 
|---|
|  |  |  | import java.io.IOException; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.LinkedHashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import java.util.concurrent.ConcurrentHashMap; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @ServerEndpoint("/web/AQIWebSocketTest/{param}") | 
|---|
|  |  |  | @Component | 
|---|
|  |  |  | public class BSAQIWebSocketServerTest { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static SensorService sensorService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static DeviceService deviceService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * concurrent包的线程安全Set,用来存放每个客户端对应的WebSocket对象。 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private static ConcurrentHashMap<String, BSAQIWebSocketServerTest> webSocketMap = new ConcurrentHashMap<>(); | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 与某个客户端的连接会话,需要通过它来给客户端发送数据 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Session session; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private String orgId; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private String accountId; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private String mac; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private final String exchange = "screens_data"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private static Map<String, Sensor> sensors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostConstruct | 
|---|
|  |  |  | public void init() { | 
|---|
|  |  |  | sensors = new HashMap<>(); | 
|---|
|  |  |  | List<Sensor> allSensors = sensorService.getAllSensors(); | 
|---|
|  |  |  | for (Sensor sensor : allSensors) { | 
|---|
|  |  |  | sensors.put(sensor.getSensorKey(), sensor); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @OnOpen | 
|---|
|  |  |  | public void onOpen(Session session, @PathParam("param") String param) { | 
|---|
|  |  |  | this.session = session; | 
|---|
|  |  |  | String[] params = param.split("&"); | 
|---|
|  |  |  | this.accountId = params[0]; | 
|---|
|  |  |  | this.orgId = params[1]; | 
|---|
|  |  |  | this.mac = params[2]; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (webSocketMap.containsKey(accountId)) { | 
|---|
|  |  |  | webSocketMap.remove(accountId); | 
|---|
|  |  |  | webSocketMap.put(accountId, this); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | webSocketMap.put(accountId, this); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | Connection connection = RabbitMQUtils.getConnection(); | 
|---|
|  |  |  | final Channel channel = connection.createChannel(); | 
|---|
|  |  |  | //生成临时队列 | 
|---|
|  |  |  | String queue = channel.queueDeclare().getQueue(); | 
|---|
|  |  |  | //交换机与队列通过routingKey进行绑定 | 
|---|
|  |  |  | String routingKey = ""; | 
|---|
|  |  |  | routingKey = this.orgId + "." + this.mac; | 
|---|
|  |  |  | channel.queueBind(queue, exchange, routingKey); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //消费消息,手动确认模式。 | 
|---|
|  |  |  | channel.basicQos(30);//预先读取数 | 
|---|
|  |  |  | channel.basicConsume(queue, false, new DefaultConsumer(channel) { | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { | 
|---|
|  |  |  | try{ | 
|---|
|  |  |  | //对从MQ中取出的数据做转换,并且发送风速到客户端 | 
|---|
|  |  |  | Map message = (Map) JSON.parse((String) JSON.parse(new String(body))); | 
|---|
|  |  |  | Device device = deviceService.getDeviceByMac(mac,false); | 
|---|
|  |  |  | sendDeviceInfo(message, device); | 
|---|
|  |  |  | //手动确认 | 
|---|
|  |  |  | channel.basicAck(envelope.getDeliveryTag(), true); | 
|---|
|  |  |  | //判断socket是否已经断开 | 
|---|
|  |  |  | if (!webSocketMap.containsKey(accountId)) { | 
|---|
|  |  |  | RabbitMQUtils.closeConnectionChannel(connection, channel); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | log.error(e.getMessage()); | 
|---|
|  |  |  | RabbitMQUtils.closeConnectionChannel(connection, channel); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } catch (IOException e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @OnClose | 
|---|
|  |  |  | public void onClose() { | 
|---|
|  |  |  | if (webSocketMap.containsKey(accountId)) { | 
|---|
|  |  |  | webSocketMap.remove(accountId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //接收到客户端消息操作 | 
|---|
|  |  |  | @OnMessage | 
|---|
|  |  |  | public void onMessage(String message, Session session) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @OnError | 
|---|
|  |  |  | public void onError(Session session, Throwable error) { | 
|---|
|  |  |  | log.error(error.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void sendMessage(String message) throws IOException { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | if (session.isOpen()) { | 
|---|
|  |  |  | this.session.getBasicRemote().sendText(message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (IOException e) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //log.error(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @Description: 接收前端mac以及accountid,传送前端指定mac号的设备信息 | 
|---|
|  |  |  | * @Param: [param] | 
|---|
|  |  |  | * @return: void | 
|---|
|  |  |  | * @Author: 陈凯裕 | 
|---|
|  |  |  | * @Date: 2020/9/30 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private void sendDeviceInfo(Map<String, Object> param, Device device) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | Map<String, Object> sortMap = new LinkedHashMap<>(); | 
|---|
|  |  |  | //先放名称地址,用于排序 | 
|---|
|  |  |  | sortMap.put("name", device.getName()); | 
|---|
|  |  |  | sortMap.put("address", device.getAddress()); | 
|---|
|  |  |  | //拼接单位 | 
|---|
|  |  |  | param.forEach((key, value) -> { | 
|---|
|  |  |  | Sensor sensor = sensors.get(key); | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(sensor)) { | 
|---|
|  |  |  | String unit = ObjectUtils.isEmpty(sensor.getUnit()) ? "" : (String) sensor.getUnit(); | 
|---|
|  |  |  | sortMap.put(sensor.getSensorKey(), value + unit); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | sendMessage(JSON.toJSONString(sortMap)); | 
|---|
|  |  |  | } catch (IOException e) { | 
|---|
|  |  |  | log.error("根据mac发送设备数据异常"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | #{mac} | 
|---|
|  |  |  | </foreach> | 
|---|
|  |  |  | </select> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <select id="getFiveMinutesDataByMacsAndTimeSolt" resultType="map"> | 
|---|
|  |  |  | select h.mac,h.time, | 
|---|
|  |  |  | <foreach collection="sensorKeys" separator="," item="sensorKey"> | 
|---|
|  |  |  | json->'$.${sensorKey}' AS '${sensorKey}' | 
|---|
|  |  |  | </foreach> | 
|---|
|  |  |  | FROM history_five_minutely_${yearAndMonth} h | 
|---|
|  |  |  | WHERE mac IN | 
|---|
|  |  |  | <foreach collection="macs" separator="," open="(" close=")" item="mac"> | 
|---|
|  |  |  | #{mac} | 
|---|
|  |  |  | </foreach> | 
|---|
|  |  |  | AND time BETWEEN #{startTime} AND #{endTime} | 
|---|
|  |  |  | ORDER BY h.time DESC | 
|---|
|  |  |  | LIMIT #{macNumber} | 
|---|
|  |  |  | </select> | 
|---|
|  |  |  | </mapper> | 
|---|
| New file | 
|  |  |  | 
|---|
|  |  |  | <%@ page contentType="text/html;charset=UTF-8" language="java" %> | 
|---|
|  |  |  | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> | 
|---|
|  |  |  | <!DOCTYPE html> | 
|---|
|  |  |  | <html> | 
|---|
|  |  |  | <head> | 
|---|
|  |  |  | <meta charset="utf-8"/> | 
|---|
|  |  |  | <title></title> | 
|---|
|  |  |  | <script type="text/javascript" | 
|---|
|  |  |  | src="http://api.map.baidu.com/api?v=2.0&ak=rER1sgBIcQxkfNSlm2wmBGZGgEERrooM"></script> | 
|---|
|  |  |  | <script type="text/javascript" src="/js/jquery.min.js"></script> | 
|---|
|  |  |  | </head> | 
|---|
|  |  |  | <style type="text/css"> | 
|---|
|  |  |  | body, | 
|---|
|  |  |  | html, | 
|---|
|  |  |  | #mapCanvas { | 
|---|
|  |  |  | width: 100%; | 
|---|
|  |  |  | height: 100%; | 
|---|
|  |  |  | overflow: hidden; | 
|---|
|  |  |  | margin: 0; | 
|---|
|  |  |  | z-index: 0; | 
|---|
|  |  |  | font-size: 14px; | 
|---|
|  |  |  | font-family: "微软雅黑"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | .main_body { | 
|---|
|  |  |  | border: 0; | 
|---|
|  |  |  | margin: 0; | 
|---|
|  |  |  | width: 100%; | 
|---|
|  |  |  | height: 100%; | 
|---|
|  |  |  | position: relative; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | * { | 
|---|
|  |  |  | margin: 0; | 
|---|
|  |  |  | padding: 0; | 
|---|
|  |  |  | list-style: none; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #cpm { | 
|---|
|  |  |  | width: 300px; | 
|---|
|  |  |  | height: 100px; | 
|---|
|  |  |  | position: absolute; | 
|---|
|  |  |  | background-color: #ffffff; | 
|---|
|  |  |  | display: none; | 
|---|
|  |  |  | left: 50%; | 
|---|
|  |  |  | top: 50%; | 
|---|
|  |  |  | margin-left: -150px; | 
|---|
|  |  |  | margin-top: -50px; | 
|---|
|  |  |  | z-index: 11; | 
|---|
|  |  |  | color: #000000; | 
|---|
|  |  |  | border: 2px solid #FF7F50; | 
|---|
|  |  |  | font-size: 28px; | 
|---|
|  |  |  | line-height: 100px; | 
|---|
|  |  |  | text-align: center; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | .BMap_pop > img { | 
|---|
|  |  |  | top: 42px !important; | 
|---|
|  |  |  | margin-left: -10px; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | .BMap_pop div:nth-child(1) div { | 
|---|
|  |  |  | display: none; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | .BMap_pop div:nth-child(3) { | 
|---|
|  |  |  | display: none; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | .BMap_pop div:nth-child(5) { | 
|---|
|  |  |  | display: none; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | .BMap_pop div:nth-child(7) { | 
|---|
|  |  |  | display: none; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | .BMap_pop div:nth-child(9) { | 
|---|
|  |  |  | top: 35px !important; | 
|---|
|  |  |  | border-radius: 5px; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #selectSenor { | 
|---|
|  |  |  | position: absolute; | 
|---|
|  |  |  | z-index: 1; | 
|---|
|  |  |  | left: 30px; | 
|---|
|  |  |  | top: 20px; | 
|---|
|  |  |  | font-size: 20px; | 
|---|
|  |  |  | background: lightgrey; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | button { | 
|---|
|  |  |  | font-size: 15px; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | .sensorLevel { | 
|---|
|  |  |  | position: absolute; | 
|---|
|  |  |  | z-index: 1; | 
|---|
|  |  |  | bottom: 20px; | 
|---|
|  |  |  | right: 10px; | 
|---|
|  |  |  | width: 100px; | 
|---|
|  |  |  | height: 200px; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | </style> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <body> | 
|---|
|  |  |  | <div class="main_body"> | 
|---|
|  |  |  | <div id="selectSenor"> | 
|---|
|  |  |  | <input type="radio" value="e1" name="sensor" checked>PM2.5 | 
|---|
|  |  |  | <input type="radio" value="e2" name="sensor">PM10 | 
|---|
|  |  |  | <input type="radio" value="e17" name="sensor">TVOC | 
|---|
|  |  |  | </div> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <img src="/img/sensorLevel.png" class="sensorLevel"> | 
|---|
|  |  |  | <div id="cpm">查无走航车轨迹</div> | 
|---|
|  |  |  | <div id="mapCanvas"></div> <!-- 百度地图 --> | 
|---|
|  |  |  | </div> | 
|---|
|  |  |  | </body> | 
|---|
|  |  |  | </html> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <script type="text/javascript"> | 
|---|
|  |  |  | var GPS = { | 
|---|
|  |  |  | PI: 3.14159265358979324, | 
|---|
|  |  |  | x_pi: 3.14159265358979324 * 3000.0 / 180.0, | 
|---|
|  |  |  | delta: function (lat, lon) { | 
|---|
|  |  |  | var a = 6378245.0; //  a: 卫星椭球坐标投影到平面地图坐标系的投影因子。 | 
|---|
|  |  |  | var ee = 0.00669342162296594323; //  ee: 椭球的偏心率。 | 
|---|
|  |  |  | var dLat = this.transformLat(lon - 105.0, lat - 35.0); | 
|---|
|  |  |  | var dLon = this.transformLon(lon - 105.0, lat - 35.0); | 
|---|
|  |  |  | var radLat = lat / 180.0 * this.PI; | 
|---|
|  |  |  | var magic = Math.sin(radLat); | 
|---|
|  |  |  | magic = 1 - ee * magic * magic; | 
|---|
|  |  |  | var sqrtMagic = Math.sqrt(magic); | 
|---|
|  |  |  | dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * this.PI); | 
|---|
|  |  |  | dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * this.PI); | 
|---|
|  |  |  | return {'lat': dLat, 'lon': dLon}; | 
|---|
|  |  |  | }, | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //WGS-84 to GCJ-02 | 
|---|
|  |  |  | gcj_encrypt: function (wgsLat, wgsLon) { | 
|---|
|  |  |  | if (this.outOfChina(wgsLat, wgsLon)) | 
|---|
|  |  |  | return {'lat': wgsLat, 'lon': wgsLon}; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var d = this.delta(wgsLat, wgsLon); | 
|---|
|  |  |  | return {'lat': wgsLat + d.lat, 'lon': wgsLon + d.lon}; | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | //GCJ-02 to WGS-84 | 
|---|
|  |  |  | gcj_decrypt: function (gcjLat, gcjLon) { | 
|---|
|  |  |  | if (this.outOfChina(gcjLat, gcjLon)) | 
|---|
|  |  |  | return {'lat': gcjLat, 'lon': gcjLon}; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var d = this.delta(gcjLat, gcjLon); | 
|---|
|  |  |  | return {'lat': gcjLat - d.lat, 'lon': gcjLon - d.lon}; | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | //GCJ-02 to WGS-84 exactly | 
|---|
|  |  |  | gcj_decrypt_exact: function (gcjLat, gcjLon) { | 
|---|
|  |  |  | var initDelta = 0.01; | 
|---|
|  |  |  | var threshold = 0.000000001; | 
|---|
|  |  |  | var dLat = initDelta, dLon = initDelta; | 
|---|
|  |  |  | var mLat = gcjLat - dLat, mLon = gcjLon - dLon; | 
|---|
|  |  |  | var pLat = gcjLat + dLat, pLon = gcjLon + dLon; | 
|---|
|  |  |  | var wgsLat, wgsLon, i = 0; | 
|---|
|  |  |  | while (1) { | 
|---|
|  |  |  | wgsLat = (mLat + pLat) / 2; | 
|---|
|  |  |  | wgsLon = (mLon + pLon) / 2; | 
|---|
|  |  |  | var tmp = this.gcj_encrypt(wgsLat, wgsLon) | 
|---|
|  |  |  | dLat = tmp.lat - gcjLat; | 
|---|
|  |  |  | dLon = tmp.lon - gcjLon; | 
|---|
|  |  |  | if ((Math.abs(dLat) < threshold) && (Math.abs(dLon) < threshold)) | 
|---|
|  |  |  | break; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (dLat > 0) pLat = wgsLat; else mLat = wgsLat; | 
|---|
|  |  |  | if (dLon > 0) pLon = wgsLon; else mLon = wgsLon; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (++i > 10000) break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return {'lat': wgsLat, 'lon': wgsLon}; | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | //GCJ-02 to BD-09 | 
|---|
|  |  |  | bd_encrypt: function (gcjLat, gcjLon) { | 
|---|
|  |  |  | var x = gcjLon, y = gcjLat; | 
|---|
|  |  |  | var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * this.x_pi); | 
|---|
|  |  |  | var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * this.x_pi); | 
|---|
|  |  |  | bdLon = z * Math.cos(theta) + 0.0065; | 
|---|
|  |  |  | bdLat = z * Math.sin(theta) + 0.006; | 
|---|
|  |  |  | return {'lat': bdLat, 'lon': bdLon}; | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | //BD-09 to GCJ-02 | 
|---|
|  |  |  | bd_decrypt: function (bdLat, bdLon) { | 
|---|
|  |  |  | var x = bdLon - 0.0065, y = bdLat - 0.006; | 
|---|
|  |  |  | var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * this.x_pi); | 
|---|
|  |  |  | var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * this.x_pi); | 
|---|
|  |  |  | var gcjLon = z * Math.cos(theta); | 
|---|
|  |  |  | var gcjLat = z * Math.sin(theta); | 
|---|
|  |  |  | return {'lat': gcjLat, 'lon': gcjLon}; | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | //WGS-84 to Web mercator | 
|---|
|  |  |  | //mercatorLat -> y mercatorLon -> x | 
|---|
|  |  |  | mercator_encrypt: function (wgsLat, wgsLon) { | 
|---|
|  |  |  | var x = wgsLon * 20037508.34 / 180.; | 
|---|
|  |  |  | var y = Math.log(Math.tan((90. + wgsLat) * this.PI / 360.)) / (this.PI / 180.); | 
|---|
|  |  |  | y = y * 20037508.34 / 180.; | 
|---|
|  |  |  | return {'lat': y, 'lon': x}; | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | // Web mercator to WGS-84 | 
|---|
|  |  |  | // mercatorLat -> y mercatorLon -> x | 
|---|
|  |  |  | mercator_decrypt: function (mercatorLat, mercatorLon) { | 
|---|
|  |  |  | var x = mercatorLon / 20037508.34 * 180.; | 
|---|
|  |  |  | var y = mercatorLat / 20037508.34 * 180.; | 
|---|
|  |  |  | y = 180 / this.PI * (2 * Math.atan(Math.exp(y * this.PI / 180.)) - this.PI / 2); | 
|---|
|  |  |  | return {'lat': y, 'lon': x}; | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | // two point's distance | 
|---|
|  |  |  | distance: function (latA, lonA, latB, lonB) { | 
|---|
|  |  |  | var earthR = 6371000.; | 
|---|
|  |  |  | var x = Math.cos(latA * this.PI / 180.) * Math.cos(latB * this.PI / 180.) * Math.cos((lonA - lonB) * this.PI / 180); | 
|---|
|  |  |  | var y = Math.sin(latA * this.PI / 180.) * Math.sin(latB * this.PI / 180.); | 
|---|
|  |  |  | var s = x + y; | 
|---|
|  |  |  | if (s > 1) s = 1; | 
|---|
|  |  |  | if (s < -1) s = -1; | 
|---|
|  |  |  | var alpha = Math.acos(s); | 
|---|
|  |  |  | var distance = alpha * earthR; | 
|---|
|  |  |  | return distance; | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | outOfChina: function (lat, lon) { | 
|---|
|  |  |  | if (lon < 72.004 || lon > 137.8347) | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | if (lat < 0.8293 || lat > 55.8271) | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | transformLat: function (x, y) { | 
|---|
|  |  |  | var ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x)); | 
|---|
|  |  |  | ret += (20.0 * Math.sin(6.0 * x * this.PI) + 20.0 * Math.sin(2.0 * x * this.PI)) * 2.0 / 3.0; | 
|---|
|  |  |  | ret += (20.0 * Math.sin(y * this.PI) + 40.0 * Math.sin(y / 3.0 * this.PI)) * 2.0 / 3.0; | 
|---|
|  |  |  | ret += (160.0 * Math.sin(y / 12.0 * this.PI) + 320 * Math.sin(y * this.PI / 30.0)) * 2.0 / 3.0; | 
|---|
|  |  |  | return ret; | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | transformLon: function (x, y) { | 
|---|
|  |  |  | var ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x)); | 
|---|
|  |  |  | ret += (20.0 * Math.sin(6.0 * x * this.PI) + 20.0 * Math.sin(2.0 * x * this.PI)) * 2.0 / 3.0; | 
|---|
|  |  |  | ret += (20.0 * Math.sin(x * this.PI) + 40.0 * Math.sin(x / 3.0 * this.PI)) * 2.0 / 3.0; | 
|---|
|  |  |  | ret += (150.0 * Math.sin(x / 12.0 * this.PI) + 300.0 * Math.sin(x / 30.0 * this.PI)) * 2.0 / 3.0; | 
|---|
|  |  |  | return ret; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var params = ${requestScope.carTrajectoryParams}; | 
|---|
|  |  |  | var sensorInfo = params["sensorInfo"]; | 
|---|
|  |  |  | var map = new BMap.Map("mapCanvas", {enableMapClick: false}); | 
|---|
|  |  |  | var mapStyle = { | 
|---|
|  |  |  | features: ["road", "building", "water", "land"], // 隐藏地图上的poi | 
|---|
|  |  |  | style: "normal" // 设置地图风格为高端黑 | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | map.setMapStyle(mapStyle); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //地图类型 | 
|---|
|  |  |  | var mapType = new BMap.MapTypeControl( | 
|---|
|  |  |  | { | 
|---|
|  |  |  | mapTypes: [BMAP_NORMAL_MAP, BMAP_SATELLITE_MAP], | 
|---|
|  |  |  | anchor: BMAP_ANCHOR_TOP_RIGHT | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | map.addControl(mapType); | 
|---|
|  |  |  | map.setMapType(BMAP_SATELLITE_MAP);//设置默认地图类型(卫星地图) | 
|---|
|  |  |  | var navigation = new BMap.NavigationControl({ | 
|---|
|  |  |  | anchor: BMAP_ANCHOR_BOTTOM_LEFT, | 
|---|
|  |  |  | type: BMAP_NAVIGATION_CONTROL_LARGE | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | map.addControl(navigation);//缩放控件 | 
|---|
|  |  |  | map.enableScrollWheelZoom(true); // 开启鼠标滚轮缩放 | 
|---|
|  |  |  | map.addControl(new BMap.ScaleControl()); | 
|---|
|  |  |  | if (sensorInfo.length === 0) { | 
|---|
|  |  |  | showNoFlightTrajectory(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | var trackPoints = [];//存放从后台获取到的所有历史轨迹点的数据 | 
|---|
|  |  |  | var points = []; | 
|---|
|  |  |  | //格子尺寸 | 
|---|
|  |  |  | var size = 50; | 
|---|
|  |  |  | var distance = size / 2 / Math.sin(1 * Math.PI / 4); | 
|---|
|  |  |  | //要显示的因子 | 
|---|
|  |  |  | var sensor = $("input[type='radio']:checked").val(); | 
|---|
|  |  |  | for (var i = 0; i < sensorInfo.length; i++) { | 
|---|
|  |  |  | if (typeof (sensorInfo[i]["e76"]) == "undefined") { | 
|---|
|  |  |  | sensorInfo.splice(i, 1); | 
|---|
|  |  |  | i--; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | var lon = parseFloat(sensorInfo[i].e76.substr(0, sensorInfo[i].e76.length - 1)); | 
|---|
|  |  |  | var lat = parseFloat(sensorInfo[i].e77.substr(0, sensorInfo[i].e77.length - 1)); | 
|---|
|  |  |  | if (lon > 150 || lon < 70 || lat <= 20 || lat > 60) { | 
|---|
|  |  |  | sensorInfo.splice(i, 1); | 
|---|
|  |  |  | i--; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (i > 1) { | 
|---|
|  |  |  | if (sensorInfo[i]["e76"] === sensorInfo[i - 1]["e76"] && sensorInfo[i]["e77"] === sensorInfo[i - 1]["e77"]) { | 
|---|
|  |  |  | sensorInfo.splice(i, 1); | 
|---|
|  |  |  | i--; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | points = getShowPoints(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | map.centerAndZoom(points, 13);// 根据经纬度显示地图的范围 | 
|---|
|  |  |  | map.setViewport(points);// 根据提供的地理区域或坐标设置地图视野 | 
|---|
|  |  |  | drawPolygon(sensor);//多边形 | 
|---|
|  |  |  | drawLine();//轨迹路线 | 
|---|
|  |  |  | drawStartAndEnd();//起点和终点标注 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //无数据时显示 | 
|---|
|  |  |  | function showNoFlightTrajectory() { | 
|---|
|  |  |  | var point = new BMap.Point(120.987287, 31.391562); | 
|---|
|  |  |  | map.centerAndZoom(point, 17); | 
|---|
|  |  |  | setTimeout(function () { | 
|---|
|  |  |  | document.getElementById("cpm").style.display = 'block'; | 
|---|
|  |  |  | }, 250); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //以一个为中心,一定角度,距离为distance找点 | 
|---|
|  |  |  | function getPoint(angle, lng, lat, distance) { | 
|---|
|  |  |  | var EARTH_RADIUS = 6378137; | 
|---|
|  |  |  | //将距离转换成经度的计算公式 | 
|---|
|  |  |  | var ra = distance / EARTH_RADIUS; | 
|---|
|  |  |  | // 转换为radian,否则结果会不正确 | 
|---|
|  |  |  | angle = angle / 180 * Math.PI; | 
|---|
|  |  |  | lng = lng / 180 * Math.PI; | 
|---|
|  |  |  | lat = lat / 180 * Math.PI; | 
|---|
|  |  |  | lng = lng + Math.atan2(Math.sin(angle) * Math.sin(ra) * Math.cos(lat), Math.cos(ra) - Math.sin(lat) * Math.sin(lat)); | 
|---|
|  |  |  | lat = Math.asin(Math.sin(lat) * Math.cos(ra) + Math.cos(lat) * Math.sin(ra) * Math.cos(angle)); | 
|---|
|  |  |  | // 转为正常的10进制经纬度 | 
|---|
|  |  |  | lng = lng * 180 / Math.PI; | 
|---|
|  |  |  | lat = lat * 180 / Math.PI; | 
|---|
|  |  |  | return new BMap.Point(lng, lat); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //多边形填充颜色 | 
|---|
|  |  |  | function getColor(senosor, data) { | 
|---|
|  |  |  | var color; | 
|---|
|  |  |  | switch (sensor) { | 
|---|
|  |  |  | case 'e1': | 
|---|
|  |  |  | if (data < 35) { | 
|---|
|  |  |  | color = '#0FB820'; | 
|---|
|  |  |  | } else if (data < 75) { | 
|---|
|  |  |  | color = '#B8B002'; | 
|---|
|  |  |  | } else if (data < 115) { | 
|---|
|  |  |  | color = '#E55F03'; | 
|---|
|  |  |  | } else if (data < 150) { | 
|---|
|  |  |  | color = '#C9031B'; | 
|---|
|  |  |  | } else if (data < 250) { | 
|---|
|  |  |  | color = '#C00160'; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | color = '#BC0238'; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 'e2': | 
|---|
|  |  |  | if (data < 50) { | 
|---|
|  |  |  | color = '#0FB820'; | 
|---|
|  |  |  | } else if (data < 150) { | 
|---|
|  |  |  | color = '#B8B002'; | 
|---|
|  |  |  | } else if (data < 250) { | 
|---|
|  |  |  | color = '#E55F03'; | 
|---|
|  |  |  | } else if (data < 350) { | 
|---|
|  |  |  | color = '#C9031B'; | 
|---|
|  |  |  | } else if (data < 420) { | 
|---|
|  |  |  | color = '#C00160'; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | color = '#BC0238'; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 'e17': | 
|---|
|  |  |  | if (data < 1.5) { | 
|---|
|  |  |  | color = '#0FB820'; | 
|---|
|  |  |  | } else if (data < 3) { | 
|---|
|  |  |  | color = '#B8B002'; | 
|---|
|  |  |  | } else if (data < 5) { | 
|---|
|  |  |  | color = '#E55F03'; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | color = '#BC0238'; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | default: | 
|---|
|  |  |  | color = '#0FB820'; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return color; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //画方块,上色,添加文字 | 
|---|
|  |  |  | function drawPolygon(sensor) { | 
|---|
|  |  |  | $.each(points, function (item, point) { | 
|---|
|  |  |  | var sw = getPoint(225, point.lng, point.lat, distance); | 
|---|
|  |  |  | var ne = getPoint(45, point.lng, point.lat, distance); | 
|---|
|  |  |  | var data = point[sensor]; | 
|---|
|  |  |  | //根据因子浓度变换方块颜色 | 
|---|
|  |  |  | color = getColor(sensor, data); | 
|---|
|  |  |  | var polygon = new BMap.Polygon([ | 
|---|
|  |  |  | new BMap.Point(sw.lng, sw.lat),//左下角 | 
|---|
|  |  |  | new BMap.Point(ne.lng, sw.lat),//左上角 | 
|---|
|  |  |  | new BMap.Point(ne.lng, ne.lat),//右上角 | 
|---|
|  |  |  | new BMap.Point(sw.lng, ne.lat)//右下角 | 
|---|
|  |  |  | ], {strokeWeight: 0.5, strokeOpacity: 0.5, fillColor: color}); | 
|---|
|  |  |  | map.addOverlay(polygon); | 
|---|
|  |  |  | //方块内添加label文本 | 
|---|
|  |  |  | setLabelStyle(data, point); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //绘制带箭头折线 | 
|---|
|  |  |  | function drawLine() { | 
|---|
|  |  |  | //绘制箭头及其样式 | 
|---|
|  |  |  | var sy = new BMap.Symbol(BMap_Symbol_SHAPE_BACKWARD_OPEN_ARROW, { | 
|---|
|  |  |  | scale: 0.6,//图标缩放大小 | 
|---|
|  |  |  | strokeColor: 'white',//设置矢量图标的线填充颜色 | 
|---|
|  |  |  | strokeWeight: 3,//设置线宽 | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | var icons = new BMap.IconSequence(sy, '100%', '4%', false);//设置为true,可以对轨迹进行编辑 | 
|---|
|  |  |  | //绘制折线以及样式 | 
|---|
|  |  |  | var trackLine = new BMap.Polyline(points, { | 
|---|
|  |  |  | strokeColor: "red",//设置颜色 | 
|---|
|  |  |  | strokeWeight: 4,//宽度 | 
|---|
|  |  |  | strokeOpacity: 0.3,//折线的透明度,取值范围0 - 1 | 
|---|
|  |  |  | enableEditing: false,//是否启用线编辑,默认为false | 
|---|
|  |  |  | enableClicking: false,//是否响应点击事件,默认为true | 
|---|
|  |  |  | icons: [icons], | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | map.addOverlay(trackLine); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //起点和终点标注 | 
|---|
|  |  |  | function drawStartAndEnd() { | 
|---|
|  |  |  | var startIcon = new BMap.Icon("/img/start.png", new BMap.Size(48, 48)); | 
|---|
|  |  |  | var startMark = new BMap.Marker(points[0], {icon: startIcon, offset: new BMap.Size(0, -20)}); | 
|---|
|  |  |  | map.addOverlay(startMark); | 
|---|
|  |  |  | var endIcon = new BMap.Icon("/img/end.png", new BMap.Size(48, 48)); | 
|---|
|  |  |  | var endMark = new BMap.Marker(points[points.length - 1], {icon: endIcon, offset: new BMap.Size(0, -20)}); | 
|---|
|  |  |  | map.addOverlay(endMark); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //格子间隔>=50m的放进points | 
|---|
|  |  |  | function getShowPoints() { | 
|---|
|  |  |  | points.push(convertPoint(0)); | 
|---|
|  |  |  | for (var i = 1; i < sensorInfo.length; i++) { | 
|---|
|  |  |  | var flag = true; | 
|---|
|  |  |  | var point1 = convertPoint(i); | 
|---|
|  |  |  | var sw1 = getPoint(225, point1.lng, point1.lat, distance); | 
|---|
|  |  |  | var ne1 = getPoint(45, point1.lng, point1.lat, distance); | 
|---|
|  |  |  | for (var j = 0; j < points.length; j++) { | 
|---|
|  |  |  | var point2 = points[j]; | 
|---|
|  |  |  | var dis = parseInt(map.getDistance(point1, point2)); | 
|---|
|  |  |  | if (dis < size) { | 
|---|
|  |  |  | flag = false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (flag) { | 
|---|
|  |  |  | points.push(point1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return points; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //point上添加label文本 | 
|---|
|  |  |  | function setLabelStyle(content, point) { | 
|---|
|  |  |  | var label = new BMap.Label("<span class='my-maptip'>" + content + "<br /><span>",//为lable填写内容 | 
|---|
|  |  |  | { | 
|---|
|  |  |  | offset: new BMap.Size(-8, -10),//label的偏移量,为了让label的中心显示在点上 | 
|---|
|  |  |  | position: point | 
|---|
|  |  |  | } | 
|---|
|  |  |  | );//label的位置 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var offsetSize = new BMap.Size(0, 0); | 
|---|
|  |  |  | var size = "10px"; | 
|---|
|  |  |  | if (map.getZoom() <= 16) { | 
|---|
|  |  |  | size = "0px"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | var labelStyle = { | 
|---|
|  |  |  | border: "0", | 
|---|
|  |  |  | fontSize: size, | 
|---|
|  |  |  | height: "20px", | 
|---|
|  |  |  | lineHeight: "20px", | 
|---|
|  |  |  | fontFamily: "微软雅黑", | 
|---|
|  |  |  | backgroundColor: "0.05", | 
|---|
|  |  |  | fontWeight: "bold" | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | label.setStyle(labelStyle); | 
|---|
|  |  |  | map.addOverlay(label); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //地图缩放级别监控 | 
|---|
|  |  |  | map.addEventListener("zoomend", function () { | 
|---|
|  |  |  | //这里根据缩放显示和隐藏文本 | 
|---|
|  |  |  | var zoom = this.getZoom(); | 
|---|
|  |  |  | $('span.my-maptip').parent()[zoom <= 16 ? 'hide' : 'show'](); | 
|---|
|  |  |  | $('span.my-maptip').parent().css("font-size", 30 - zoom); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | $("#selectSenor").change(function () { | 
|---|
|  |  |  | map.clearOverlays() | 
|---|
|  |  |  | sensor = $("input[type='radio']:checked").val(); | 
|---|
|  |  |  | drawPolygon(sensor); | 
|---|
|  |  |  | drawLine(); | 
|---|
|  |  |  | drawStartAndEnd(); | 
|---|
|  |  |  | }) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取经纬度点 | 
|---|
|  |  |  | function convertPoint(index) { | 
|---|
|  |  |  | var value = sensorInfo[index]; | 
|---|
|  |  |  | if (typeof (value.e76) == "undefined") { | 
|---|
|  |  |  | showNoFlightTrajectory(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | var lon = parseFloat(value.e76.substr(0, value.e76.length - 1)); | 
|---|
|  |  |  | var lat = parseFloat(value.e77.substr(0, value.e77.length - 1)); | 
|---|
|  |  |  | var m = GPS.gcj_encrypt(lat, lon).lon; | 
|---|
|  |  |  | var n = GPS.gcj_encrypt(lat, lon).lat; | 
|---|
|  |  |  | lon = GPS.bd_encrypt(n, m).lon; | 
|---|
|  |  |  | lat = GPS.bd_encrypt(n, m).lat; | 
|---|
|  |  |  | var point = new BMap.Point(lon, lat); | 
|---|
|  |  |  | point['e1'] = parseInt(sensorInfo[index]['e1']); | 
|---|
|  |  |  | point['e2'] = parseInt(sensorInfo[index]['e2']); | 
|---|
|  |  |  | point['e17'] = parseFloat(sensorInfo[index]['e17']).toFixed(2); | 
|---|
|  |  |  | return point; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获得角度的函数 | 
|---|
|  |  |  | function getAngle(n, next) { | 
|---|
|  |  |  | var ret | 
|---|
|  |  |  | var w1 = n.lat / 180 * Math.PI | 
|---|
|  |  |  | var j1 = n.lng / 180 * Math.PI | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var w2 = next.lat / 180 * Math.PI | 
|---|
|  |  |  | var j2 = next.lng / 180 * Math.PI | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ret = 4 * Math.pow(Math.sin((w1 - w2) / 2), 2) - Math.pow(Math.sin((j1 - j2) / 2) * (Math.cos(w1) - Math.cos(w2)), 2); | 
|---|
|  |  |  | ret = Math.sqrt(ret); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // var temp = Math.sin(Math.abs(j1 - j2) / 2) * (Math.cos(w1) + Math.cos(w2)); | 
|---|
|  |  |  | var temp = Math.sin((j1 - j2) / 2) * (Math.cos(w1) + Math.cos(w2)); | 
|---|
|  |  |  | ret = ret / temp; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ret = Math.atan(ret) / Math.PI * 180; | 
|---|
|  |  |  | ret += 90; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 这里用如此臃肿的if..else是为了判定追踪单个点的具体情况,从而调整ret的值 | 
|---|
|  |  |  | if (j1 - j2 < 0) { | 
|---|
|  |  |  | // console.log('j1<j2') | 
|---|
|  |  |  | if (w1 - w2 < 0) { | 
|---|
|  |  |  | // console.log('w1<w2') | 
|---|
|  |  |  | ret; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | // console.log('w1>w2') | 
|---|
|  |  |  | ret = -ret + 180; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | // console.log('j1>j2') | 
|---|
|  |  |  | if (w1 - w2 < 0) { | 
|---|
|  |  |  | // console.log('w1<w2') | 
|---|
|  |  |  | ret = 180 + ret; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | // console.log('w1>w2') | 
|---|
|  |  |  | ret = -ret; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return ret; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | </script> | 
|---|
| New file | 
|  |  |  | 
|---|
|  |  |  | <%@ page contentType="text/html;charset=UTF-8" language="java" %> | 
|---|
|  |  |  | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> | 
|---|
|  |  |  | <%@page isELIgnored="false" %> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <!DOCTYPE html> | 
|---|
|  |  |  | <html> | 
|---|
|  |  |  | <head> | 
|---|
|  |  |  | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | 
|---|
|  |  |  | <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> | 
|---|
|  |  |  | <script type="text/javascript" src="/js/jquery.min.js"></script> | 
|---|
|  |  |  | <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=rER1sgBIcQxkfNSlm2wmBGZGgEERrooM"></script> | 
|---|
|  |  |  | <script type="text/javascript" src="http://api.map.baidu.com/library/Heatmap/2.0/src/Heatmap_min.js"></script> | 
|---|
|  |  |  | <title>热力图功能示例</title> | 
|---|
|  |  |  | <style type="text/css"> | 
|---|
|  |  |  | ul,li{list-style: none;margin:0;padding:0;float:left;} | 
|---|
|  |  |  | html{height:100%} | 
|---|
|  |  |  | body{height:100%;margin:0px;padding:0px;font-family:"微软雅黑";} | 
|---|
|  |  |  | #container{height:100%;width:100%;} | 
|---|
|  |  |  | #r-result{width:100%;} | 
|---|
|  |  |  | </style> | 
|---|
|  |  |  | </head> | 
|---|
|  |  |  | <body> | 
|---|
|  |  |  | <div id="container"></div> | 
|---|
|  |  |  | <div id="r-result" style="display:none"> | 
|---|
|  |  |  | <input type="button"  οnclick="openHeatmap();" value="显示热力图"/><input type="button"  οnclick="closeHeatmap();" value="关闭热力图"/> | 
|---|
|  |  |  | </div> | 
|---|
|  |  |  | <div id="mapParams" style="display: none;"> | 
|---|
|  |  |  | ${requestScope.params} | 
|---|
|  |  |  | </div> | 
|---|
|  |  |  | </body> | 
|---|
|  |  |  | </html> | 
|---|
|  |  |  | <script type="text/javascript"> | 
|---|
|  |  |  | var map = new BMap.Map("container", {minZoom: 14, maxZoom: 19}); | 
|---|
|  |  |  | //var map = new BMap.Map("container");          // 创建地图实例 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var params = $.parseJSON($("#mapParams").html()); | 
|---|
|  |  |  | var accountId = params["accountId"]; | 
|---|
|  |  |  | var level = params["level"]; | 
|---|
|  |  |  | var center = params["center"]; | 
|---|
|  |  |  | var points2 = params["points"]; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var point = new BMap.Point(center['lng'],center['lat']); | 
|---|
|  |  |  | map.centerAndZoom(point, level);    // 初始化地图,设置中心点坐标和地图级别 | 
|---|
|  |  |  | //map.setCurrentCity("安阳");        //设置当前显示城市 | 
|---|
|  |  |  | map.enableScrollWheelZoom(); // 允许滚轮缩放 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var points = []; | 
|---|
|  |  |  | for (var i =0;i<points2.length;i++) { | 
|---|
|  |  |  | var json; | 
|---|
|  |  |  | var a = points2[i]; | 
|---|
|  |  |  | var b = a['']; | 
|---|
|  |  |  | json = { | 
|---|
|  |  |  | lng : a['lng'], | 
|---|
|  |  |  | lat : a['lat'], | 
|---|
|  |  |  | count : a['count'] | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | points[i] = json; | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /*var points =[ | 
|---|
|  |  |  | {"lng":"120.997119","lat":"31.451714","count":"0.027"}, | 
|---|
|  |  |  | {"lng":"120.99516","lat":"31.448664","count":"0.029"}, | 
|---|
|  |  |  | {"lng":"120.998538","lat":"31.449289","count":"0.033"}, | 
|---|
|  |  |  | {"lng":"120.998628","lat":"31.452027","count":"0.025"}, | 
|---|
|  |  |  | {"lng":"121.000383","lat":"31.451469","count":"0.05"}, | 
|---|
|  |  |  | {"lng":"120.999908","lat":"31.449389","count":"0.04"}, | 
|---|
|  |  |  | {"lng":"120.998519","lat":"31.450588","count":"0.10"}, | 
|---|
|  |  |  | ]; | 
|---|
|  |  |  | alert(points[1]);*/ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var points1 =[ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | {"lng":"114.363979","lat":"36.03773","count":"52"}, | 
|---|
|  |  |  | {"lng":"114.295894","lat":"36.231772","count":"7"}, | 
|---|
|  |  |  | {"lng":"114.504007","lat":"36.093311","count":"6"}, | 
|---|
|  |  |  | {"lng":"114.395983","lat":"36.201385","count":"19"}, | 
|---|
|  |  |  | {"lng":"114.718751","lat":"36.091966","count":"2"}, | 
|---|
|  |  |  | {"lng":"114.48261","lat":"36.146032","count":"4"}, | 
|---|
|  |  |  | {"lng":"114.037656","lat":"36.276956","count":"1"}, | 
|---|
|  |  |  | {"lng":"114.425989","lat":"36.157907","count":"5"}, | 
|---|
|  |  |  | {"lng":"114.309662","lat":"36.19489","count":"8"}, | 
|---|
|  |  |  | {"lng":"114.008762","lat":"36.162515","count":"11"}, | 
|---|
|  |  |  | {"lng":"114.149597","lat":"36.25203","count":"11"}, | 
|---|
|  |  |  | {"lng":"114.634489","lat":"36.09711","count":"3"}, | 
|---|
|  |  |  | {"lng":"114.035667","lat":"36.042826","count":"105"}, | 
|---|
|  |  |  | {"lng":"114.220135","lat":"36.116061","count":"38"}, | 
|---|
|  |  |  | {"lng":"114.137829","lat":"36.054525","count":"7"}, | 
|---|
|  |  |  | {"lng":"114.137348","lat":"36.136101","count":"55"}, | 
|---|
|  |  |  | {"lng":"114.078537","lat":"36.235848","count":"28"}, | 
|---|
|  |  |  | {"lng":"114.648979","lat":"36.043749","count":"111"}, | 
|---|
|  |  |  | {"lng":"114.104776","lat":"36.124067","count":"12"}, | 
|---|
|  |  |  | {"lng":"114.578275","lat":"36.095941","count":"3"}, | 
|---|
|  |  |  | {"lng":"114.578275","lat":"36.095941","count":"22"}, | 
|---|
|  |  |  | {"lng":"114.578275","lat":"36.095941","count":"4"}, | 
|---|
|  |  |  | {"lng":"113.913152","lat":"36.000907","count":"5"}, | 
|---|
|  |  |  | {"lng":"113.831853","lat":"35.836377","count":"4"}, | 
|---|
|  |  |  | {"lng":"113.825641","lat":"36.072186","count":"16"}, | 
|---|
|  |  |  | {"lng":"113.931695","lat":"36.262638","count":"9"}, | 
|---|
|  |  |  | {"lng":"113.965077","lat":"35.919748","count":"6"}, | 
|---|
|  |  |  | {"lng":"113.830067","lat":"35.932444","count":"1"}, | 
|---|
|  |  |  | {"lng":"113.830067","lat":"35.932444","count":"7"}, | 
|---|
|  |  |  | {"lng":"113.750022","lat":"35.976316","count":"10"}, | 
|---|
|  |  |  | {"lng":"113.934346","lat":"36.166723","count":"6"}, | 
|---|
|  |  |  | {"lng":"113.928979","lat":"36.059528","count":"14"}, | 
|---|
|  |  |  | {"lng":"113.898287","lat":"35.777936","count":"6"}, | 
|---|
|  |  |  | {"lng":"113.867283","lat":"36.134905","count":"29"}, | 
|---|
|  |  |  | {"lng":"113.81997","lat":"36.280506","count":"6"}, | 
|---|
|  |  |  | {"lng":"113.936795","lat":"35.768474","count":"3"}, | 
|---|
|  |  |  | {"lng":"113.818245","lat":"36.183143","count":"107"}, | 
|---|
|  |  |  | {"lng":"113.762547","lat":"35.916163","count":"12"}, | 
|---|
|  |  |  | {"lng":"113.762547","lat":"35.916163","count":"17"}, | 
|---|
|  |  |  | {"lng":"114.309528","lat":"36.098035","count":"12"}, | 
|---|
|  |  |  | {"lng":"114.184941","lat":"36.066066","count":"10"}, | 
|---|
|  |  |  | {"lng":"114.265651","lat":"36.016851","count":"10"}, | 
|---|
|  |  |  | {"lng":"114.794527","lat":"35.889239","count":"4"}, | 
|---|
|  |  |  | {"lng":"114.916588","lat":"35.953233","count":"33"}, | 
|---|
|  |  |  | {"lng":"114.862802","lat":"36.082315","count":"5"}, | 
|---|
|  |  |  | {"lng":"114.821994","lat":"35.940167","count":"7"}, | 
|---|
|  |  |  | {"lng":"114.732801","lat":"36.010095","count":"1"}, | 
|---|
|  |  |  | {"lng":"114.665014","lat":"35.827956","count":"5"}, | 
|---|
|  |  |  | {"lng":"114.687001","lat":"35.926633","count":"4"}, | 
|---|
|  |  |  | {"lng":"114.886604","lat":"35.823869","count":"17"}, | 
|---|
|  |  |  | {"lng":"114.714493","lat":"35.824384","count":"9"}, | 
|---|
|  |  |  | {"lng":"114.838951","lat":"35.714762","count":"8"}, | 
|---|
|  |  |  | {"lng":"114.768614","lat":"35.820543","count":"3"}, | 
|---|
|  |  |  | {"lng":"114.945903","lat":"36.001222","count":"10"}, | 
|---|
|  |  |  | {"lng":"114.814282","lat":"36.05379","count":"1"}, | 
|---|
|  |  |  | {"lng":"114.89458","lat":"36.128534","count":"2"}, | 
|---|
|  |  |  | {"lng":"114.768884","lat":"36.09376","count":"3"}, | 
|---|
|  |  |  | {"lng":"114.891728","lat":"35.996425","count":"9"}, | 
|---|
|  |  |  | {"lng":"114.899498","lat":"35.683682","count":"2"}, | 
|---|
|  |  |  | {"lng":"114.436397","lat":"35.942211","count":"13"}, | 
|---|
|  |  |  | {"lng":"114.537118","lat":"35.959195","count":"5"}, | 
|---|
|  |  |  | {"lng":"114.374189","lat":"35.92115","count":"21"}, | 
|---|
|  |  |  | {"lng":"114.435536","lat":"35.884432","count":"1"}, | 
|---|
|  |  |  | {"lng":"114.434839","lat":"35.885617","count":"23"}, | 
|---|
|  |  |  | {"lng":"114.468909","lat":"35.952258","count":"17"}, | 
|---|
|  |  |  | {"lng":"114.358104","lat":"35.944822","count":"27"}, | 
|---|
|  |  |  | {"lng":"114.647021","lat":"35.968271","count":"6"}, | 
|---|
|  |  |  | {"lng":"114.483172","lat":"35.862866","count":"3"}, | 
|---|
|  |  |  | {"lng":"114.589631","lat":"35.856694","count":"4"}, | 
|---|
|  |  |  | {"lng":"114.37365","lat":"35.930392","count":"1"}, | 
|---|
|  |  |  | {"lng":"114.322755","lat":"35.82315","count":"26"}, | 
|---|
|  |  |  | {"lng":"114.322755","lat":"35.82315","count":"6"}, | 
|---|
|  |  |  | {"lng":"114.376392","lat":"36.013433","count":"3"}, | 
|---|
|  |  |  | {"lng":"114.447681","lat":"36.052479","count":"6"}, | 
|---|
|  |  |  | {"lng":"114.447681","lat":"36.052479","count":"13"}, | 
|---|
|  |  |  | {"lng":"114.31517","lat":"36.117569","count":"5"} | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ];//这里面添加经纬度 | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(!isSupportCanvas()){ | 
|---|
|  |  |  | alert('热力图目前只支持有canvas支持的浏览器,您所使用的浏览器不能使用热力图功能~') | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //详细的参数,可以查看heatmap.js的文档 https://github.com/pa7/heatmap.js/blob/master/README.md | 
|---|
|  |  |  | //参数说明如下: | 
|---|
|  |  |  | /* visible 热力图是否显示,默认为true | 
|---|
|  |  |  | * opacity 热力的透明度,1-100 | 
|---|
|  |  |  | * radius 势力图的每个点的半径大小 | 
|---|
|  |  |  | * gradient  {JSON} 热力图的渐变区间 . gradient如下所示 | 
|---|
|  |  |  | *  { | 
|---|
|  |  |  | .2:'rgb(0, 255, 255)', | 
|---|
|  |  |  | .5:'rgb(0, 110, 255)', | 
|---|
|  |  |  | .8:'rgb(100, 0, 255)' | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 其中 key 表示插值的位置, 0~1. | 
|---|
|  |  |  | value 为颜色值. | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | heatmapOverlay = new BMapLib.HeatmapOverlay({"radius":100,"visible":true}); | 
|---|
|  |  |  | map.addOverlay(heatmapOverlay); | 
|---|
|  |  |  | heatmapOverlay.setDataSet({data:points,max:0.13}); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //closeHeatmap(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //判断浏览区是否支持canvas | 
|---|
|  |  |  | function isSupportCanvas(){ | 
|---|
|  |  |  | var elem = document.createElement('canvas'); | 
|---|
|  |  |  | return !!(elem.getContext && elem.getContext('2d')); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | function setGradient(){ | 
|---|
|  |  |  | /*格式如下所示: | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 0:'rgb(102, 255, 0)', | 
|---|
|  |  |  | .5:'rgb(255, 170, 0)', | 
|---|
|  |  |  | 1:'rgb(255, 0, 0)' | 
|---|
|  |  |  | }*/ | 
|---|
|  |  |  | var gradient = {}; | 
|---|
|  |  |  | var colors = document.querySelectorAll("input[type='color']"); | 
|---|
|  |  |  | colors = [].slice.call(colors,0); | 
|---|
|  |  |  | colors.forEach(function(ele){ | 
|---|
|  |  |  | gradient[ele.getAttribute("data-key")] = ele.value; | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | heatmapOverlay.setOptions({"gradient":gradient}); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | function openHeatmap(){ | 
|---|
|  |  |  | heatmapOverlay.show(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | function closeHeatmap(){ | 
|---|
|  |  |  | heatmapOverlay.hide(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | </script> | 
|---|
|  |  |  |  | 
|---|