forked from marsprj/Map5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclusterLayer2.html
152 lines (123 loc) · 3.95 KB
/
clusterLayer2.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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="../lib/css/Map5.min.css">
<script type="text/javascript" src="../lib/Map5.min.js"></script>
<script type="text/javascript" src="js/tianjin_gongchangValue.js"></script>
<style type="text/css">
body{
margin: 0px;
}
</style>
<script type="text/javascript">
// 地图变量
var mapObj = null;
function init(){
// 地图的范围
var extent = new GeoBeans.Envelope(-180,-90,180,90);
// 地图的容器为"mapDiv",地图名称"map",地图范围,地图的空间参考,4326为经纬度
mapObj = new GeoBeans.Map("mapDiv","map",extent,4326);
if(mapObj == null){
return;
}
// 定义一个QuadServer图层,作为底图,第一个参数为图层名称,第二个参数为QuadServer地址
var layer = new GeoBeans.Layer.QSLayer("base","/QuadServer/maprequest?services=world_vector");
// 添加图层
mapObj.addLayer(layer);
// 设置中心点
var center = new GeoBeans.Geometry.Point(0,0);
mapObj.setCenter(center);
// 设置级别
mapObj.setLevel(3);
addFeatureLayer();
// 绘图
mapObj.draw();
}
function addFeatureLayer(){
// 不是new 出来的
var fields = [
{
name : "name", // 字段名称
type : "string" // 字段类型
},{
name : "type",
type : "int"
},{
name : "shape",
type : "geometry"
}
];
var geomType = GeoBeans.Geometry.Type.POINT;
var name = "testLayer";
// 创建一个featureLayer
// 第一个参数图层名称,第二个参数字段设置,第三个参数,图层的类型(点图层)
var featureLayer = mapObj.createFeatureLayer(name,fields,geomType);
// 添加图层
mapObj.addLayer(featureLayer);
var length = g_gongchangValue.length;
for(var i = 0; i < length;++i){
var v = g_gongchangValue[i];
var name = v.name;
var type = v.type;
var wkt = v.shape;
// 使用wkt转换为geometry
var geometry = GeoBeans.Utility.createGeometryFromWKT(wkt);
var id = "id_" + i;
var values = [name,type,geometry];
// 第一个参数要素的ID值,第二个参数要素的geometry,第三个参数要素字段值,与字段顺序一致
featureLayer.addFeatureObj(id,geometry,values);
}
// 设定样式
var style = createPointStyle();
featureLayer.setStyle(style);
mapObj.draw();
}
function createPointStyle(){
var style = new GeoBeans.Style.FeatureStyle();
var rule = new GeoBeans.Rule();
var symbolizer = new GeoBeans.Symbolizer.PointSymbolizer();
symbolizer.size = 1;
symbolizer.fill.color.set(255, 0, 0,1);
symbolizer.stroke = null;
rule.symbolizer = symbolizer;
style.addRule(rule);
return style;
}
function addChart(){
// 1、设置图层名称
var layerName = "chart";
// 2、选取底图名称
var baseLayerName = "testLayer";
// 3、定义点聚合图
var layer = new GeoBeans.Layer.ClusterLayer(layerName,baseLayerName);
// 4、添加图层
mapObj.addLayer(layer);
// 5、绘图
mapObj.draw();
}
function setLayerVisible(){
var layer = mapObj.getLayer("testLayer");
if(layer.visible){
layer.setVisiable(false);
}else{
layer.setVisiable(true);
}
mapObj.draw();
}
function removeChartLayer(){
// 1、根据名称删除图层
mapObj.removeLayer("chart");
// 2、绘图
mapObj.draw();
}
</script>
<title>Map5 -- 点聚合图</title>
<body onload="init()">
<!-- mapDiv 为初始化地图的容器,给定高度和宽度,并指定定位方式为绝对定位 -->
<div id="mapDiv" style="height:800px;width:100%;position:absolute;top:80px;">
</div>
<button onclick="addChart()">点聚合图(天津市工厂数据)</button>
<button onclick="setLayerVisible()">隐藏/显示原始图</button>
<button onclick="removeChartLayer()">删除点聚合图</button>
</body>