Merge remote-tracking branch 'origin/master'
# Conflicts:
#	src/main/java/com/moral/config/WebSocketConfig.java
	
		
		2 files added
	
		
		6 files modified
	
	
 
	
	
	
	
	
	
	
	
|  |  |  | 
|---|
|  |  |  | package com.moral.config; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.service.AccountService; | 
|---|
|  |  |  | import com.moral.service.DeviceService; | 
|---|
|  |  |  | import com.moral.service.SensorService; | 
|---|
|  |  |  | import com.moral.webSocketServer.*; | 
|---|
|  |  |  | 
|---|
|  |  |  | BSAQIWebSocketServerTest.deviceService=deviceService; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | public void setMessageService(AccountService accountService){ | 
|---|
|  |  |  | ElectronicSWebSocketServer.accountService=accountService; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | public void setSensorService( SensorService sensorService){ | 
|---|
|  |  |  | BSWebsocketServer.sensorService=sensorService; | 
|---|
|  |  |  | BSAQIWebSocketServer.sensorService=sensorService; | 
|---|
|  |  |  | ElectronicSWebSocketServer.sensorService=sensorService; | 
|---|
|  |  |  | BSAQIWebSocketServerTest.sensorService=sensorService; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return new ResultBean<List<Map<String,Object>>>(rList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("byAccountGetDevices") | 
|---|
|  |  |  | public List<Device> byAccountGetDevices(@RequestBody Map<String, Object> parameters) { | 
|---|
|  |  |  | String id =parameters.get("id").toString(); | 
|---|
|  |  |  | List<Device> devicesList = deviceService.getDevicesByAccountId(id); | 
|---|
|  |  |  | return devicesList; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Device> getDeviceByCityCode(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Device> getDevicesByAccountId(String id); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | List<Device> getDevice(String macOrName); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Device> getDeviceByCode(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Device> getDevicesByAccountId(String id); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | return deviceMapper.getDeviceByCityCode(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<Device> getDevicesByAccountId(String id) { | 
|---|
|  |  |  | return deviceMapper.getDevicesByAccountId(id); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
| New file | 
|  |  |  | 
|---|
|  |  |  | package com.moral.webSocketServer; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.moral.entity.Account; | 
|---|
|  |  |  | import com.moral.entity.Device; | 
|---|
|  |  |  | import com.moral.entity.Sensor; | 
|---|
|  |  |  | import com.moral.service.AccountService; | 
|---|
|  |  |  | 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 org.springframework.web.bind.annotation.CrossOrigin; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.PostConstruct; | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | import javax.websocket.*; | 
|---|
|  |  |  | import javax.websocket.server.PathParam; | 
|---|
|  |  |  | import javax.websocket.server.ServerEndpoint; | 
|---|
|  |  |  | import java.io.IOException; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.concurrent.ConcurrentHashMap; | 
|---|
|  |  |  | import java.util.concurrent.CopyOnWriteArraySet; | 
|---|
|  |  |  | import java.util.concurrent.TimeoutException; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @ServerEndpoint("/web/ESWebSocket/{param}") | 
|---|
|  |  |  | @Component | 
|---|
|  |  |  | public class ElectronicSWebSocketServer { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static AccountService accountService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static SensorService sensorService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * concurrent包的线程安全Set,用来存放每个客户端对应的WebSocket对象。 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public static CopyOnWriteArraySet<ElectronicSWebSocketServer> webSocketSet = new CopyOnWriteArraySet<ElectronicSWebSocketServer>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 与某个客户端的连接会话,需要通过它来给客户端发送数据 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Session session; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private String orgId; | 
|---|
|  |  |  | private String accountId; | 
|---|
|  |  |  | private String mac; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private final String exchange = "screens_data"; | 
|---|
|  |  |  | Connection connection; | 
|---|
|  |  |  | Channel channel; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @OnOpen | 
|---|
|  |  |  | public void onOpen(Session session, @PathParam("param") String param) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | this.session = session; | 
|---|
|  |  |  | webSocketSet.add(this); | 
|---|
|  |  |  | String[] params = param.split("&"); | 
|---|
|  |  |  | this.accountId = params[0]; | 
|---|
|  |  |  | Map<String, Object> organizationIdByAccountId = accountService.getOrganizationIdByAccountId(this.accountId); | 
|---|
|  |  |  | this.mac = params[1]; | 
|---|
|  |  |  | this.orgId = organizationIdByAccountId.get("organization_id").toString(); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | connection = RabbitMQUtils.getConnection(); | 
|---|
|  |  |  | 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 { | 
|---|
|  |  |  | //对从MQ中取出的数据做转换,并且发送风速到客户端 | 
|---|
|  |  |  | Map<String,Object> message = (Map) JSON.parse((String) JSON.parse(new String(body))); | 
|---|
|  |  |  | Map<Integer,Object> sortMap = new HashMap<>(); | 
|---|
|  |  |  | message.forEach((key,value)->{ | 
|---|
|  |  |  | SensorSortEnum sensorSortEnum = SensorSortEnum.valueOf(key); | 
|---|
|  |  |  | Map newMap = new HashMap(); | 
|---|
|  |  |  | newMap.put(key,value); | 
|---|
|  |  |  | sortMap.put(sensorSortEnum.getSensorSort(),newMap); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Set<Map.Entry<Integer, Object>> entries = sortMap.entrySet(); | 
|---|
|  |  |  | List<Map.Entry<Integer, Object>> list = new ArrayList<>(); | 
|---|
|  |  |  | list.addAll(entries); | 
|---|
|  |  |  | Collections.sort(list, new Comparator<Map.Entry<Integer, Object>>() { | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public int compare(Map.Entry<Integer, Object> o1, Map.Entry<Integer, Object> o2) { | 
|---|
|  |  |  | return o1.getKey()-o2.getKey(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<String,Object> resultMap = new LinkedHashMap<>(); | 
|---|
|  |  |  | for (Map.Entry<Integer, Object> entry : list) { | 
|---|
|  |  |  | Map<String,Object> linkedMap = (Map<String, Object>) entry.getValue(); | 
|---|
|  |  |  | linkedMap.forEach((key,value)->{ | 
|---|
|  |  |  | resultMap.put(SensorSortEnum.valueOf(key).getSensorName(),value); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Map<String,Object> reMap = new LinkedHashMap<>(); | 
|---|
|  |  |  | List<Sensor> allSensors = sensorService.getAllSensors(); | 
|---|
|  |  |  | for (int i = 0; i <resultMap.keySet().size() ; i++) { | 
|---|
|  |  |  | for (Sensor sensor : allSensors) { | 
|---|
|  |  |  | if (Arrays.asList(resultMap.keySet().toArray(new String[resultMap.keySet().size()])).get(i).equals(sensor.getSensorKey())){ | 
|---|
|  |  |  | String value = resultMap.get(Arrays.asList(resultMap.keySet().toArray(new String[resultMap.keySet().size()])).get(i)).toString(); | 
|---|
|  |  |  | /* String e = Arrays.asList(resultMap.keySet().toArray(new String[resultMap.keySet().size()])).get(i); | 
|---|
|  |  |  | resultMap.remove(e);*/ | 
|---|
|  |  |  | reMap.put(sensor.getName(), value+sensor.getUnit()); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | reMap.put("time",resultMap.get("time")); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | sendMessage(JSON.toJSONString(reMap)); | 
|---|
|  |  |  | //手动确认 | 
|---|
|  |  |  | channel.basicAck(envelope.getDeliveryTag(), true); | 
|---|
|  |  |  | //判断socket是否已经断开 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } catch (IOException e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @OnClose | 
|---|
|  |  |  | public void onClose() { | 
|---|
|  |  |  | webSocketSet.remove(this); // 从set中删除 | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | channel.close(); | 
|---|
|  |  |  | connection.close(); | 
|---|
|  |  |  | } catch (IOException e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } catch ( | 
|---|
|  |  |  | TimeoutException e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //接收到客户端消息操作 | 
|---|
|  |  |  | @OnMessage | 
|---|
|  |  |  | public void onMessage(String message, Session session) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //枚举类,用于按特定规则排序 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | enum SensorSortEnum { | 
|---|
|  |  |  | e1(1,"e1"), | 
|---|
|  |  |  | e20(2,"e20"), | 
|---|
|  |  |  | e7(3,"e7"), | 
|---|
|  |  |  | e2(4,"e2"), | 
|---|
|  |  |  | e17(5,"e17"), | 
|---|
|  |  |  | e6(6,"e6"), | 
|---|
|  |  |  | e15(7,"e15"), | 
|---|
|  |  |  | e27(8,"e27"), | 
|---|
|  |  |  | e18(9,"e18"), | 
|---|
|  |  |  | e11(10,"e11"), | 
|---|
|  |  |  | e21(11,"e21"), | 
|---|
|  |  |  | e23(12,"e23"), | 
|---|
|  |  |  | e10(13,"e10"), | 
|---|
|  |  |  | e25(14,"e25"), | 
|---|
|  |  |  | e28(15,"e28"), | 
|---|
|  |  |  | e16(16,"e16"), | 
|---|
|  |  |  | e26(17,"e26"), | 
|---|
|  |  |  | e12(18,"e12"), | 
|---|
|  |  |  | e5(19,"e5"), | 
|---|
|  |  |  | e3(20,"e3"), | 
|---|
|  |  |  | e13(21,"e13"), | 
|---|
|  |  |  | e9(22,"e9"), | 
|---|
|  |  |  | e4(23,"e4"), | 
|---|
|  |  |  | e51(24,"e51"), | 
|---|
|  |  |  | mac(100,"mac"), | 
|---|
|  |  |  | ver(101,"ver"), | 
|---|
|  |  |  | time(102,"time"), | 
|---|
|  |  |  | e8(14,"e8"), | 
|---|
|  |  |  | e94(94,"e94"), | 
|---|
|  |  |  | e92(92,"e92"), | 
|---|
|  |  |  | e40(40,"e40"), | 
|---|
|  |  |  | e93(93,"e93"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private final Integer sensorSort; | 
|---|
|  |  |  | private final String sensorName; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | SensorSortEnum(Integer sensorSort, String sensorName) { | 
|---|
|  |  |  | this.sensorSort = sensorSort; | 
|---|
|  |  |  | this.sensorName = sensorName; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public Integer getSensorSort() { | 
|---|
|  |  |  | return sensorSort; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getSensorName() { | 
|---|
|  |  |  | return sensorName; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | <select id="getDeviceByCityCode" resultType="com.moral.entity.Device"> | 
|---|
|  |  |  | SELECT d.* FROM `monitor_point` mt,device d where d.monitor_point_id=mt.id and d.state!=4 and mt.city_code=130900 | 
|---|
|  |  |  | </select> | 
|---|
|  |  |  | <select id="getDevicesByAccountId" resultType="com.moral.entity.Device"> | 
|---|
|  |  |  | select d.* from monitor_point as m,device as d | 
|---|
|  |  |  | where d.monitor_point_id=m.id and  d.monitor_point_id in | 
|---|
|  |  |  | (select m.id from organization as o,monitor_point as m where o.id = m.organization_id and o.id = | 
|---|
|  |  |  | (select o.id FROM  account as a,organization as o where a.organization_id = o.id and a.id = #{id})) and d.is_delete !=1 | 
|---|
|  |  |  | </select> | 
|---|
|  |  |  | </mapper> | 
|---|
| 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 point = new BMap.Point(120.997119,31.451714); | 
|---|
|  |  |  | map.centerAndZoom(point, 17);    // 初始化地图,设置中心点坐标和地图级别 | 
|---|
|  |  |  | //map.setCurrentCity("安阳");        //设置当前显示城市 | 
|---|
|  |  |  | map.enableScrollWheelZoom(); // 允许滚轮缩放 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var params = $.parseJSON($("#mapParams").html()); | 
|---|
|  |  |  | var accountId = params["accountId"]; | 
|---|
|  |  |  | alert(accountId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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"}, | 
|---|
|  |  |  | ]; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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> | 
|---|
|  |  |  |  | 
|---|