forked from huiyan-fe/mapv
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaidu-map-point-datgui.html
More file actions
589 lines (540 loc) · 19.1 KB
/
baidu-map-point-datgui.html
File metadata and controls
589 lines (540 loc) · 19.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
#map {
width: 100%;
height: 100%;
}
#dragzone {
position: absolute;
left: 5px;
top: 30px;
padding: 10px;
width: 120px;
font-size: 12px;
height: 30px;
line-height: 30px;
background: rgba(255, 255, 55, 0.8);
border: 1px dashed #999;
}
#panel {
position: absolute;
left: 5px;
top: 5px;
}
</style>
</head>
<body>
<div id="map"></div>
<div id="dragzone">数据csv文件拖放到此</div>
<div id="panel">
<input type="text" id="keyword" value="北京市,河北省,天津市"/>
<input type="button" value="查看边界" id="boundaryBtn"/>
<input type="button" value="切换底图" id="switchMap"/>
</div>
<script type="text/javascript" src="//cdn.bootcss.com/jquery/3.0.0/jquery.min.js"></script>
<script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=49tGfOjwBKkG9zG76wgcpIbce4VZdbv6"></script>
<script type="text/javascript" src="../build/mapv.js"></script>
<script type="text/javascript" src="js/dat.gui.min.js"></script>
<script type="text/javascript">
// 百度地图API功能
var map = new BMap.Map("map", {
enableMapClick: false
}); // 创建Map实例
map.centerAndZoom(new BMap.Point(105.403119, 38.028658), 5); // 初始化地图,设置中心点坐标和地图级别
map.enableScrollWheelZoom(true); // 开启鼠标滚轮缩放
var pt = new BMap.Point(127.733142,21.226515);
var jiuduanwidth = 408;
var jiuduanheight = 563;
var scale = 4.5;
var myIcon = new BMap.Icon("./images/nanhai.png", new BMap.Size(jiuduanwidth / scale, jiuduanheight / scale), {
imageSize: new BMap.Size(jiuduanwidth / scale, jiuduanheight / scale)
});
var marker2 = new BMap.Marker(pt,{icon:myIcon}); // 创建标注
map.addOverlay(marker2);
function setNullStyle() {
map.setMapStyle({
styleJson: [
{
"featureType": "all",
"elementType": "all",
"stylers": {
"visibility": "off"
}
}
]
});
map.getContainer().style.background = '#fff';
}
function setGrayStyle() {
map.setMapStyle({
styleJson: [
{
"featureType": "all",
"elementType": "all",
"stylers": {
"lightness": 61,
"saturation": -100
}
},
{
"featureType": "all",
"elementType": "labels",
"stylers": {
"visibility": "off"
}
}
]
});
}
function setDarkStyle() {
map.setMapStyle({
styleJson: [{
featureType: 'water',
elementType: 'all',
stylers: {
color: '#044161'
}
}, {
featureType: 'land',
elementType: 'all',
stylers: {
color: '#091934'
}
}, {
featureType: 'boundary',
elementType: 'geometry',
stylers: {
color: '#064f85'
}
}, {
featureType: 'railway',
elementType: 'all',
stylers: {
visibility: 'off'
}
}, {
featureType: 'highway',
elementType: 'geometry',
stylers: {
color: '#004981'
}
}, {
featureType: 'highway',
elementType: 'geometry.fill',
stylers: {
color: '#005b96',
lightness: 1
}
}, {
featureType: 'highway',
elementType: 'labels',
stylers: {
visibility: 'on'
}
}, {
featureType: 'arterial',
elementType: 'geometry',
stylers: {
color: '#004981',
lightness: -39
}
}, {
featureType: 'arterial',
elementType: 'geometry.fill',
stylers: {
color: '#00508b'
}
}, {
featureType: 'poi',
elementType: 'all',
stylers: {
visibility: 'off'
}
}, {
featureType: 'green',
elementType: 'all',
stylers: {
color: '#056197',
visibility: 'off'
}
}, {
featureType: 'subway',
elementType: 'all',
stylers: {
visibility: 'off'
}
}, {
featureType: 'manmade',
elementType: 'all',
stylers: {
visibility: 'off'
}
}, {
featureType: 'local',
elementType: 'all',
stylers: {
visibility: 'off'
}
}, {
featureType: 'arterial',
elementType: 'labels',
stylers: {
visibility: 'off'
}
}, {
featureType: 'boundary',
elementType: 'geometry.fill',
stylers: {
color: '#029fd4'
}
}, {
featureType: 'building',
elementType: 'all',
stylers: {
color: '#1a5787'
}
}, {
featureType: 'label',
elementType: 'all',
stylers: {
visibility: 'off'
}
}, {
featureType: 'poi',
elementType: 'labels.text.fill',
stylers: {
color: '#ffffff'
}
}, {
featureType: 'poi',
elementType: 'labels.text.stroke',
stylers: {
color: '#1e1c1c'
}
},
{
"featureType": "all",
"elementType": "labels",
"stylers": {
"visibility": "off"
}
}
]
});
}
setNullStyle();
var chinaLayer = null;
$.get('data/china.json', function(geojson) {
var dataSet = mapv.geojson.getDataSet(geojson);
var options = {
fillStyle: 'rgba(218, 218, 218, 1)',
//fillStyle: '#1495ff',
//fillStyle: 'lightblue',
//fillStyle: 'rgba(50, 50, 50, 0.5)',
//strokeStyle: '#999',
strokeStyle: 'rgba(255, 255, 255, 1)',
lineWidth: 1,
zIndex: -2,
paneName: 'mapPane',
draw: 'simple'
}
chinaLayer = new mapv.baiduMapLayer(map, dataSet, options);
});
var randomCount = 300;
var data = [];
var citys = ["北京","天津","上海","重庆","石家庄","太原","呼和浩特","哈尔滨","长春","沈阳","济南","南京","合肥","杭州","南昌","福州","郑州","武汉","长沙","广州","南宁","西安","银川","兰州","西宁","乌鲁木齐","成都","贵阳","昆明","拉萨","海口"];
// 构造数据
while (randomCount--) {
var cityCenter = mapv.utilCityCenter.getCenterByCityName(citys[parseInt(Math.random() * citys.length)]);
data.push({
geometry: {
type: 'Point',
coordinates: [cityCenter.lng - 2 + Math.random() * 4, cityCenter.lat - 2 + Math.random() * 4]
},
count: 100 * Math.random()
});
}
var dataSet = new mapv.DataSet(data);
var options = {
draw: 'heatmap',
max: 100,
coordType: 'bd09mc',
size: 5,
symbol: 'circle',
zIndex: 1,
maxSize: 50,
maxOpacity: 0.8,
globalAlpha: 1,
lineWidth: 0,
unit: 'px',
gradient: {
0.25: "rgba(0, 0, 255, 1)",
0.55: "rgba(0, 255, 0, 1)",
0.85: "rgba(255, 255, 0, 1)",
1.0: "rgba(255, 0, 0, 1)"
},
fillStyle: 'rgba(55, 50, 250, 0.6)',
strokeStyle: 'rgba(55, 50, 250, 0.6)',
// shadowColor: 'rgba(55, 50, 250, 0.5)',
// shadowBlur: 10
}
var mapvLayer = new mapv.baiduMapLayer(map, dataSet, options);
function finished() {
mapvLayer.update({
options: options
});
};
window.onload = function() {
initGui();
};
var gradientOptions = [
{
0.25: "rgba(0, 0, 255, 1)",
0.55: "rgba(0, 255, 0, 1)",
0.85: "rgba(255, 255, 0, 1)",
1.0: "rgba(255, 0, 0, 1)"
},
{
'0': 'Black',
'0.5': 'Aqua',
'1': 'White'
},
{
'0.0': 'blue',
'1': 'red'
},
{
'0.0': 'rgb(0, 0, 0)',
'0.6': 'rgb(24, 53, 103)',
'0.75': 'rgb(46, 100, 158)',
'0.9': 'rgb(23, 173, 203)',
'1.0': 'rgb(0, 250, 250)'
},
{
'0': 'Navy',
'0.25': 'Blue',
'0.5': 'Green',
'0.75': 'Yellow',
'1': 'Red'
},
{
'0': 'Black',
'0.33': 'DarkRed',
'0.66': 'Yellow',
'1': 'White'
},
{
'0': 'Black',
'0.4': 'Purple',
'0.6': 'Red',
'0.8': 'Yellow',
'1': 'White'
},
{
'0': 'Red',
'0.66': 'Yellow',
'1': 'White'
},
{
'0': 'Navy', '0.25': 'Navy',
'0.26': 'Green',
'0.5': 'Green',
'0.51': 'Yellow',
'0.75': 'Yellow',
'0.76': 'Red',
'1': 'Red'
},
{
'0.00': 'rgb(255,0,255)',
'0.25': 'rgb(0,0,255)',
'0.50': 'rgb(0,255,0)',
'0.75': 'rgb(255,255,0)',
'1.00': 'rgb(255,0,0)'
},
{
0: "yellow",
1.0: "red"
},
{
0: "white",
1.0: "blue"
},
{
0: "green",
1.0: "rgb(0, 255, 255)"
}
];
var gui;
function initGui() {
gui && gui.destroy();
gui = new dat.GUI({
nameMap: {
draw: '绘制方法',
unit: '单位',
size: '大小',
fillStyle: '颜色',
symbol: '形状',
globalAlpha: '图层透明度',
maxOpacity: '图层透明度',
// shadowColor: '阴影颜色',
// shadowBlur: '阴影大小',
gradient: '渐变色',
lineWidth: '线宽',
strokeStyle: '线颜色',
maxSize: '最大半径值',
max: '最大阈值',
}
});
gui.add(options, 'draw', {
'普通': 'simple',
'热力图': 'heatmap',
'气泡': 'bubble',
'颜色分类': 'category',
'蜂窝状聚类': 'honeycomb',
'网格聚类': 'grid',
'值区间分类': 'choropleth',
'颜色渐变': 'intensity'
}).onFinishChange(function () {
initGui();
finished();
});
gui.add(options, 'unit', {
'像素': 'px',
'米': 'm'
}).onFinishChange(function () {
initGui();
finished();
});
if (options.draw !== 'bubble') {
if (options.unit == 'm') {
gui.add(options, 'size', 0.1, 200000).onFinishChange(finished);
} else {
gui.add(options, 'size', 0.1, 100).onFinishChange(finished);
}
}
if (options.draw !== 'heatmap') {
gui.add(options, 'globalAlpha', 0, 1).onFinishChange(finished);
}
switch (options.draw) {
case 'simple':
gui.addColor(options, 'fillStyle').onChange(finished);
// gui.addColor(options, 'shadowColor').onChange(finished);
// gui.add(options, 'shadowBlur', 1, 100).onFinishChange(finished);
gui.add(options, 'lineWidth', 1, 10).onFinishChange(finished);
gui.addColor(options, 'strokeStyle').onChange(finished);
gui.add(options, 'symbol', {
'圆形': 'circle',
'矩形': 'rect',
}).onFinishChange(finished);
break;
case 'bubble':
gui.addColor(options, 'fillStyle').onChange(finished);
// gui.addColor(options, 'shadowColor').onChange(finished);
// gui.add(options, 'shadowBlur', 1, 100).onFinishChange(finished);
gui.add(options, 'lineWidth', 1, 10).onFinishChange(finished);
gui.addColor(options, 'strokeStyle').onChange(finished);
gui.add(options, 'max', 1, 1000).onFinishChange(finished);
gui.add(options, 'maxSize', 35, 100).onFinishChange(finished);
break;
case 'heatmap':
// gui.add(options, 'shadowBlur', 1, 100).onFinishChange(finished);
gui.add(options, 'max', 1, 1000).onFinishChange(finished);
gui.add(options, 'maxOpacity', 0, 1).onFinishChange(finished);
gui.addGradient(options, 'gradient', gradientOptions).onFinishChange(finished);
break;
case 'grid':
case 'intensity':
case 'honeycomb':
gui.add(options, 'max', 1, 1000).onFinishChange(finished);
gui.add(options, 'lineWidth', 1, 10).onFinishChange(finished);
gui.addColor(options, 'strokeStyle').onChange(finished);
gui.addGradient(options, 'gradient', gradientOptions).onFinishChange(finished);
break;
}
}
function dragHandle(event) {
var info = "",
files, i, len;
event.preventDefault();
if(event.type == "drop") {
files = event.dataTransfer.files;
var fr = new FileReader() ;
fr.readAsText(files[0]);
fr.onload = function() {
var rs = this.result;
if (rs[0] == '[' && rs[rs.length - 1] == ']') {
rs = JSON.parse(rs);
rs = rs.map(function (item) {
return {
geometry: {
type: 'Point',
coordinates: [item.x, item.y]
}
}
});
dataSet.set(rs);
} else {
var newDataSet = mapv.csv.getDataSet(rs);
newDataSet.initGeometry();
dataSet.set(newDataSet.get());
}
}
}
}
var dropTargetEle = document.getElementById("dragzone");
dropTargetEle.addEventListener("dragenter", dragHandle, false);
dropTargetEle.addEventListener("dragover", dragHandle, false);
dropTargetEle.addEventListener("drop", dragHandle, false);
$('#boundaryBtn').bind('click', function () {
var val = $("#keyword").val().split(',');
for (var i= 0; i < val.length; i++) {
getBoundary(val[i]);
}
});
function getBoundary(city){
var bdary = new BMap.Boundary();
bdary.get(city, function(rs){ //获取行政区域
var count = rs.boundaries.length; //行政区域的点有多少个
if (count === 0) {
alert('未能获取当前输入行政区域');
return ;
}
var pointArray = [];
for (var i = 0; i < count; i++) {
var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 0, strokeStyle: 'dashed', strokeOpacity: '0', fillOpacity: '0.5', fillColor: 'red', strokeColor: "yellow"}); //建立多边形覆盖物
map.addOverlay(ply); //添加覆盖物
pointArray = pointArray.concat(ply.getPath());
}
});
}
var isChina = 1;
$('#switchMap').bind('click', function() {
isChina++;
if (isChina > 3) {
isChina = 1;
}
if (isChina == 1) {
setNullStyle();
chinaLayer.show();
} else if (isChina == 2) {
setGrayStyle();
chinaLayer.hide();
} else {
setDarkStyle();
chinaLayer.hide();
}
});
</script>
</body>
</html>