-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path3D热力图.html
221 lines (198 loc) · 6.74 KB
/
3D热力图.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>热力实战 - 玉渊潭周边定位分布</title>
<meta name="description" content="北京玉渊潭周边1万7千条定位数据的热力分布情况,颜色和高度表示定位聚合后的情况。同时配有图例说明。">
<link rel="stylesheet" href="//a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css"/>
<style>
html, body, #container {
margin: 0; padding: 0; width: 100%; height: 100%;
}
/* 图例样式 */
.legend {
position: absolute;
top: 20px;
left: 20px;
}
.legend ul {
padding: 0;
margin: 0;
list-style: none;
}
.color-item {
width: 60px;
height: 20px;
display: inline-block;
}
.label-item {
display: inline-block;
width: 60px;
margin-left: -2px;
font-size: 14px;
}
/* 信息浮框 */
.info span {
min-width: 150px;
max-width: 300px;
color: #1b91ff;
font-size: 1.2em;
}
</style>
</head>
<body>
<div id="container"></div>
<div class="legend">
<ul class="colors" id="legend-color"></ul>
<ul class="labels" id="legend-label"></ul>
</div>
<div class="info" style="width: 300px;">
<h4>热力数据</h4>
<p>当前热力值:<span id="val">--</span></p>
<p>热力中心点坐标:
<span id="lng-lat">--</span>
</p>
</div>
<script src="//webapi.amap.com/loca?v=1.2.0&key=5d618dc0cf638896d006fbc5f9d7f7ce"></script>
<script src="//a.amap.com/Loca/static/dist/jquery.min.js"></script>
<script>
var map = Loca.create('container', {
pitch: 60,
center: [118.3697, 31.3740],
zoom: 13,
features: ['bg', 'road']
});
var layer = Loca.visualLayer({
container: map,
eventSupport: true,
type: 'heatmap',
shape: 'hexagon' // 蜂窝六边形
});
map.on('mapload', function () {
map.getMap().plugin(['AMap.ControlBar'], function () {
var controlBar = new AMap.ControlBar({
showZoomBar:false,
showControlButton:true,
position:{
left:'0px',
top:'60px'
}
});
map.getMap().addControl(controlBar);
});
});
$.get('data/jt.json', function (data) {
layer.setData(data, {
lnglat: 'lnglat',
value: 'cnt',
type: 'json'
});
layer.setOptions({
unit: 'meter',
heightUnit: 'meter',
style: {
color: [
'#2c7bb6',
'#abd9e9',
'#ffffbf',
'#fdae61',
'#d7191c'
],
height: [0, 500],
radius: 15,
gap: 2,
opacity: 0.85,
},
selectStyle: {
color: '#dbf21d',
opacity: 0.9
}
});
layer.render();
});
layer.on('legendupdate', function (ev) {
var colorLegend = ev.colorLegend;
initLegend(colorLegend);
});
layer.on('mousemove', function (ev) {
updateInfo(ev);
});
function initLegend(colorLegend) {
var legends = colorLegend.map(function (item) {
return `<li class="color-item" style="background-color: ${item.color}"></li>`
});
var ranges = colorLegend.map((item, index) => {
// range 可能为小数,可以自行取整计算
item.range[0] = Math.round(item.range[0]);
item.range[1] = Math.round(item.range[1]);
if (index == colorLegend.length - 1) {
return `<li class="label-item">${item.range[0]}</li><li class="label-item">${item.range[1]}</li>`;
}
return `<li class="label-item">${item.range[0]}</li>`;
});
document.getElementById('legend-color').innerHTML = legends.join('');
document.getElementById('legend-label').innerHTML = ranges.join('');
}
function updateInfo(ev) {
var $val = document.getElementById('val');
var $lngLat = document.getElementById('lng-lat');
$val.innerText = ev.value;
$lngLat.innerText = ev.lngLat.valueOf();
}
</script>
</body>
</html>
<!--<!–获取点的坐标–>-->
<!--<!doctype html>-->
<!--<html>-->
<!--<head>-->
<!--<meta charset="utf-8">-->
<!--<meta http-equiv="X-UA-Compatible" content="IE=edge">-->
<!--<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">-->
<!--<title>鼠标拾取地图坐标</title>-->
<!--<link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/>-->
<!--<script type="text/javascript"-->
<!--src="http://webapi.amap.com/maps?v=1.3&key=5d618dc0cf638896d006fbc5f9d7f7ce&plugin=AMap.Autocomplete"></script>-->
<!--<script type="text/javascript" src="http://cache.amap.com/lbs/static/addToolbar.js"></script>-->
<!--</head>-->
<!--<body>-->
<!--<div id="container"></div>-->
<!--<div id="myPageTop">-->
<!--<table>-->
<!--<tr>-->
<!--<td class="column2">-->
<!--<label>左击获取经纬度:</label>-->
<!--</td>-->
<!--</tr>-->
<!--<tr>-->
<!--<td class="column2">-->
<!--<input type="text" readonly="true" id="lnglat">-->
<!--</td>-->
<!--</tr>-->
<!--</table>-->
<!--</div>-->
<!--<script type="text/javascript">-->
<!--var map = new AMap.Map("container", {-->
<!--resizeEnable: true-->
<!--});-->
<!--//为地图注册click事件获取鼠标点击出的经纬度坐标-->
<!--var clickEventListener = map.on('click', function(e) {-->
<!--document.getElementById("lnglat").value = e.lnglat.getLng() + ',' + e.lnglat.getLat()-->
<!--var v = document.getElementById("lnglat").value;-->
<!--console.log("{\"lnglat\":["+v+"],\"cnt\":1},");-->
<!--});-->
<!--var auto = new AMap.Autocomplete({-->
<!--input: "tipinput"-->
<!--});-->
<!--AMap.event.addListener(auto, "select", select);//注册监听,当选中某条记录时会触发-->
<!--function select(e) {-->
<!--if (e.poi && e.poi.location) {-->
<!--map.setZoom(15);-->
<!--map.setCenter(e.poi.location);-->
<!--}-->
<!--}-->
<!--</script>-->
<!--</body>-->
<!--</html>-->