forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheatMapLayer.html
More file actions
166 lines (155 loc) · 5.83 KB
/
heatMapLayer.html
File metadata and controls
166 lines (155 loc) · 5.83 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
<!--********************************************************************
* Copyright© 2000 - 2018 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title data-i18n="resources.title_heatMapLayer"></title>
<style type="text/css">
body {
margin: 0;
overflow: hidden;
background: #fff;
width: 100%;
height: 100%
}
#map {
position: absolute;
width: 100%;
height: 100%;
border: 1px solid #3473b7;
}
#toolbar {
position: absolute;
top: 50px;
right: 10px;
width: 300px;
text-align: center;
z-index: 100;
border-radius: 4px;
}
</style>
</head>
<body>
<div id="toolbar" class="panel panel-primary">
<div class='panel-heading'>
<h5 class='panel-title text-center' data-i18n="resources.text_fastHeatMapLayer"></h5></div>
<div class='panel-body content'>
<div class='panel'>
<div class='input-group'>
<span class='input-group-addon' data-i18n="resources.text_countsDraw"></span>
<input type='text' class='form-control' id='heatNums' value='200'/>
</div>
</div>
<div class='panel'>
<div class='input-group'>
<span class='input-group-addon' data-i18n="resources.text_radius"></span>
<input class='form-control' style='width: 50px' value='50' id='heatradius'/>
<select class='form-control' style='width:auto' id='radiusUnit'>
<option value='px'>px</option>
<option data-i18n='[value]resources.text_degree;resources.text_degree'></option>
</select>
</div>
</div>
<input type="button" class="btn btn-default" data-i18n="[value]resources.btn_startDraw"
onclick="createHeatPoints()"/>
<input type="button" class="btn btn-default" data-i18n="[value]resources.text_input_value_clear"
onclick="clearHeatPoints()"/>
</div>
</div>
<div id="map"></div>
<script type="text/javascript" include="bootstrap" src="../js/include-web.js"></script>
<script type="text/javascript" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
<script type="text/javascript">
var host = window.isLocal ? window.server : "http://support.supermap.com.cn:8090";
var map, heatMapLayer,
url = host + "/iserver/services/map-world/rest/maps/World";
var attribution = "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
" with <span>© <a href='http://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
" Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ";
var map = new mapboxgl.Map({
container: 'map',
style: {
"version": 8,
"sources": {
"raster-tiles": {
"attribution": attribution,
"type": "raster",
"tiles": [url + '/zxyTileImage.png?z={z}&x={x}&y={y}'],
"tileSize": 256,
},
},
"layers": [{
"id": "simple-tiles",
"type": "raster",
"source": "raster-tiles",
"minzoom": 0,
"maxzoom": 9
}]
},
center: [0, 0],
zoom: 1
});
map.addControl(new mapboxgl.NavigationControl(), 'top-left');
map.addControl(new mapboxgl.supermap.LogoControl(), 'bottom-right');
heatMapLayer = new mapboxgl.supermap.HeatMapLayer(
"heatMap",
{
"map": map,
"id": "heatmap",
"radius": 45,
// 设置图层透明度:(参数方式)
// "opacity": 0.5,
//featureWeight指定以哪个属性值为热力权重值创建热力图:
"featureWeight": "value",
}
);
function createHeatPoints() {
clearHeatPoints();
var heatPoints = [];
var num = parseInt(document.getElementById('heatNums').value);
var radius = parseInt(document.getElementById('heatradius').value);
var unit = document.getElementById("radiusUnit").value;
//resources.text_degree 表示 id=radiusUnit 选项的第一选项值
if (resources.text_degree == unit) {
//热力半径单位使用地理单位
heatMapLayer.useGeoUnit = true;
} else {
//热力半径单位不使用用地理单位
heatMapLayer.useGeoUnit = false;
}
heatMapLayer.radius = radius;
var features = [];
for (var i = 0; i < num; i++) {
features[i] =
{
"type": "feature",
"geometry": {
"type": "Point",
"coordinates": [
Math.random() * 360 - 180,
Math.random() * 160 - 80]
},
"properties": {
"value": Math.random() * 9,
}
};
}
var heatPoints = {
"type": "FeatureCollection",
"features": features
};
heatMapLayer.addFeatures(heatPoints);
// 设置图层透明度:(函数方式)
// heatMapLayer.setOpacity(0.5);
map.addLayer(heatMapLayer);
}
function clearHeatPoints() {
if (map.getLayer("heatmap")) {
map.removeLayer("heatmap");
}
}
</script>
</body>
</html>