forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathd3RangeThemeLayer.html
More file actions
129 lines (125 loc) · 5.08 KB
/
d3RangeThemeLayer.html
File metadata and controls
129 lines (125 loc) · 5.08 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
<!--********************************************************************
* Copyright© 2000 - 2018 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title data-i18n="resources.title_rangeThemeLayer"></title>
<script type="text/javascript" include="jquery,bootstrap" src="../js/include-web.js"></script>
<script type="text/javascript" include="d3,d3Layer" src="../../dist/leaflet/include-leaflet.js"></script>
<style type="text/css">
.legendItemHeader,
.legendItemValue {
width: 120px;
height: 18px;
font-size: 14px;
}
</style>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
<div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
<script type="text/javascript">
var host = window.isLocal ? window.server : "http://54.223.164.155:8090";
var map, resultLayer,
baseUrl = host + "/iserver/services/map-jingjin/rest/maps/京津地区地图",
url = host + "/iserver/services/data-jingjin/rest/data";
map = L.map('map', {
preferCanvas: true,
crs: L.CRS.EPSG4326,
center: [39.79, 116.85],
maxZoom: 18,
zoom: 7
});
L.supermap.tiledMapLayer(baseUrl).addTo(map);
query();
var rangeStyles = [{
start: 0,
end: 0.02,
color: 'rgb(253,226,202)'
}, {
start: 0.02,
end: 0.04,
color: 'rgb(250,206,156)'
}, {
start: 0.04,
end: 0.06,
color: 'rgb(240,156,66)'
}, {
start: 0.06,
end: 0.1,
color: 'rgb(208,119,11)'
}, {
start: 0.1,
end: 0.2,
color: 'rgb(148,83,5)'
}];
function query() {
var sqlParam = new SuperMap.GetFeaturesBySQLParameters({
queryParameter: {
name: "Jingjin",
attributeFilter: "SMID >= -1"
},
datasetNames: ["Jingjin:BaseMap_R"],
fromIndex: 0,
toIndex: 200
});
L.supermap.featureService(url).getFeaturesBySQL(sqlParam, function (serviceResult) {
var d3Layer = L.supermap.d3Layer(function (sel, proj) {
var upd = sel.selectAll('path').data(serviceResult.result.features.features);
upd.enter()
.append('path')
.attr('d', proj.pathFromGeojson)
.attr('fill', function (feature) {
var pop = parseFloat(feature.properties.POP_DENSITY99);
for (var i = 0; i < rangeStyles.length; i++) {
var rangeStyle = rangeStyles[i];
if (pop >= rangeStyle['start'] && pop <= rangeStyle['end']) {
return rangeStyle['color'];
}
}
})
.attr('fill-opacity', '0.8')
});
d3Layer.addTo(map);
initLegendView();
});
}
//图例控件
function initLegendView() {
var legendView = L.control({position: 'bottomright'});
legendView.onAdd = function () {
this._div = L.DomUtil.create('div', 'panel panel-primary legend ');
var title = "<div class='panel-heading'><h5 class='panel-title text-center'>" + resources.text_legend + "</h5></div>";
$(title + "<div class='panel-body text-center' ><table>" +
"<tr><td class='legendItemHeader'>" + resources.text_populationDensity + "</td><td class='legendItemValue'>" + resources.text_color + "</td></tr>" +
"<tr> <td class='legendItemHeader'>0 - 0.02</td> <td class='legendItemValue' style='background: #FDE2CA'></td></tr>" +
"<tr> <td class='legendItemHeader'>0.02 - 0.04</td> <td class='legendItemValue' style='background: #FACE9C'></td> </tr>" +
"<tr> <td class='legendItemHeader'>0.04 - 0.06</td> <td class='legendItemValue' style='background: #F09C42'></td> </tr>" +
"<tr> <td class='legendItemHeader'>0.06 - 0.1</td> <td class='legendItemValue' style='background: #D0770B'></td> </tr>" +
"<tr> <td class='legendItemHeader'>0.1 - 0.2</td> <td class='legendItemValue' style='background: #945305'></td> </tr>" +
"</table></div>"
).appendTo(this._div);
handleMapEvent(this._div, this._map);
return this._div;
};
legendView.addTo(map);
}
function handleMapEvent(div, map) {
if (!div || !map) {
return;
}
div.addEventListener('mouseover', function () {
map.dragging.disable();
map.scrollWheelZoom.disable();
map.doubleClickZoom.disable();
});
div.addEventListener('mouseout', function () {
map.dragging.enable();
map.scrollWheelZoom.enable();
map.doubleClickZoom.enable();
});
}
</script>
</body>
</html>