forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraphicLayer.html
More file actions
178 lines (156 loc) · 5.44 KB
/
graphicLayer.html
File metadata and controls
178 lines (156 loc) · 5.44 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
<!--********************************************************************
* Copyright© 2000 - 2018 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!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 data-i18n="resources.title_mb_graphicLayer"></title>
<style>
body {
margin: 0;
overflow: hidden;
background: #fff;
width: 100%;
height: 100%
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
#title {
position: absolute;
color: white;
left: 0;
top: 30px;
text-align: center;
width: 100%;
z-index: 2;
}
#title > h3{
margin: 10px 0;
letter-spacing: 0.1em;
}
#title > h6 {
margin: 0;
font-weight: normal;
}
</style>
</head>
<body>
<div id="title">
<h3 data-i18n="resources.text_graphicLayer_title"></h3>
<h6 data-i18n="resources.text_graphicLayer_subTitle"></h6>
</div>
<div id="map"></div>
<script type="text/javascript" include="papaparse,jquery,dat-gui,widgets" src="../js/include-web.js"></script>
<script type="text/javascript" include="deck" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
<script type="text/javascript">
var host = window.isLocal ? window.server : "http://support.supermap.com.cn:8090",
url = host + "/iserver/services/map-china400/rest/maps/ChinaDark";
var map, graphicLayer;
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> ";
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": 22
}]
},
center: [-73.91426, 40.7594],
zoom: 10.64
});
map.addControl(new mapboxgl.NavigationControl(), 'top-left');
widgets.loader.showLoader("data loading...");
$.get('../data/nyc-taxi.csv', function (csvstr) {
widgets.loader.removeLoader();
var result = Papa.parse(csvstr, {skipEmptyLines: true, header: true});
addLayer(result.data);
});
function addLayer(points) {
var graphics = [], popup = new mapboxgl.Popup({closeOnClick: false}).addTo(map);
for (var i = 0; i < points.length; i++) {
var lngLat = {
lng: parseFloat(points[i].lng),
lat: parseFloat(points[i].lat)
};
/**
* 可以单独给要素设置颜色和半径:
* new mapboxgl.supermap.Graphic(lngLat,{
* color:[255,0,0],
* radius:40
* });
*/
graphics.push(new mapboxgl.supermap.Graphic(lngLat));
}
var graphicStyle = {
color: [0, 255, 128],
radius: 10
};
graphicLayer = new mapboxgl.supermap.GraphicLayer("graphic", {
graphics: graphics,
radius: graphicStyle.radius,
color: graphicStyle.color,
highlightColor: [255, 0, 0, 255],
onClick: function (e) {
console.log(e);
if (!popup.isOpen()) {
popup.addTo(map);
}
popup.setLngLat(e.lngLat)
.setHTML("position:" + JSON.stringify(e.lngLat))
}
});
map.addLayer(graphicLayer);
initDatGui(graphicStyle)
}
//设置面板
function initDatGui(options) {
var gui = new dat.GUI();
var Control = createConfigControl();
map.addControl(new Control(gui.domElement), 'top-right');
gui.addColor(options, 'color').onChange(finished);
gui.add(options, 'radius', 0, 100).onChange(finished);
function finished() {
graphicLayer.setStyle(options);
}
}
//创建图层操作控件
function createConfigControl() {
function ConfigControl(domElement) {
this.dom = domElement;
}
ConfigControl.prototype.onAdd = function (map) {
this._map = map;
this._container = this.dom;
this._container.className = 'mapboxgl-ctrl ' + this._container.className;
return this._container;
};
ConfigControl.prototype.onRemove = function () {
this._container.parentNode.removeChild(this._container);
this._map = undefined;
};
return ConfigControl;
}
</script>
</body>
</html>