1+ <!DOCTYPE html>
2+ < html >
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < title > 分段专题图</ title >
6+ < link href ="http://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css " rel ="stylesheet ">
7+ < link rel ="stylesheet " href ="http://cdn.bootcss.com/leaflet/1.0.3/leaflet.css ">
8+ < script type ="text/javascript " src ="http://cdn.bootcss.com/leaflet/1.0.3/leaflet.js "> </ script >
9+ < script type ="text/javascript " src ="http://cdn.bootcss.com/jquery/3.1.1/jquery.min.js "> </ script >
10+ < script type ="text/javascript " src ="../../dist/iclient9-leaflet.js "> </ script >
11+ < style type ="text/css ">
12+ .legendItemHeader ,
13+ .legendItemValue {
14+ width : 120px ;
15+ height : 18px ;
16+ font-size : 14px ;
17+ }
18+ </ style >
19+ </ head >
20+ < body style =" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0; ">
21+ < div id ="map " style ="margin:0 auto;width: 100%;height: 100%;border: 1px solid #dddddd "> </ div >
22+ < script type ="text/javascript ">
23+ var map , themeLayer , infoView ,
24+ baseUrl = "http://113.209.64.227:8090/iserver/services/map-Jingjin/rest/maps/京津地区地图" ,
25+ dataUrl = "http://113.209.64.227:8090/iserver/services/data-Jingjin/rest/data" ;
26+
27+ init ( ) ;
28+ function init ( ) {
29+ // 检测是否支持 Canvas
30+ if ( ! document . createElement ( 'canvas' ) . getContext ) {
31+ alert ( "您的浏览器不支持 Canvas,请升级!" ) ;
32+ return ;
33+ }
34+
35+ map = L . map ( "map" , {
36+ crs : L . CRS . EPSG4326 ,
37+ center : [ 40 , 117 ] ,
38+ maxZoom : 18 ,
39+ zoom : 7
40+ } ) ;
41+ L . supermap . tiledMapLayer ( baseUrl ) . addTo ( map ) ;
42+ initThemeLayer ( ) ;
43+ }
44+ function initThemeLayer ( ) {
45+ themeLayer = L . supermap . rangeThemeLayer ( "ThemeLayer" , {
46+ // 开启 hover 高亮效果
47+ isHoverAble : true ,
48+ opacity : 0.8
49+ } ) . addTo ( map ) ;
50+
51+ themeLayer . style = new SuperMap . ThemeStyle ( {
52+ shadowBlur : 16 ,
53+ shadowColor : "#000000" ,
54+ fillColor : "#FFFFFF"
55+ } ) ;
56+
57+ // hover 高亮样式
58+ themeLayer . highlightStyle = new SuperMap . ThemeStyle ( {
59+ stroke : true ,
60+ strokeWidth : 4 ,
61+ strokeColor : 'blue' ,
62+ fillColor : "#00EEEE" ,
63+ fillOpacity : 0.8
64+ } ) ;
65+
66+ // 用于单值专题图的属性字段名称
67+ themeLayer . themeField = "POP_DENSITY99" ;
68+ // 风格数组,设定值对应的样式
69+ themeLayer . styleGroups = [ {
70+ start : 0 ,
71+ end : 0.02 ,
72+ style : {
73+ color : '#FDE2CA'
74+ }
75+ } , {
76+ start : 0.02 ,
77+ end : 0.04 ,
78+ style : {
79+ color : '#FACE9C'
80+ }
81+ } , {
82+ start : 0.04 ,
83+ end : 0.06 ,
84+ style : {
85+ color : '#F09C42'
86+ }
87+ } , {
88+ start : 0.06 ,
89+ end : 0.1 ,
90+ style : {
91+ color : '#D0770B'
92+ }
93+ } , {
94+ start : 0.1 ,
95+ end : 0.2 ,
96+ style : {
97+ color : '#945305'
98+ }
99+ } ] ;
100+
101+ themeLayer . on ( 'mousemove' , highLightLayer ) ;
102+ addThemeLayer ( ) ;
103+ }
104+
105+ function addThemeLayer ( ) {
106+ var getFeatureBySQLParams = new SuperMap . GetFeaturesBySQLParameters ( {
107+ queryParameter : new SuperMap . FilterParameter ( {
108+ name : "Jingjin" ,
109+ attributeFilter : "SMID > -1"
110+ } ) ,
111+ toIndex : 500 ,
112+ datasetNames : [ "Jingjin:BaseMap_R" ]
113+ } ) ;
114+ L . supermap . featureService ( dataUrl )
115+ . getFeaturesBySQL ( getFeatureBySQLParams , processComplete , SuperMap . DataFormat . ISERVER ) ;
116+
117+ }
118+
119+ function processComplete ( serviceResult ) {
120+ var result = serviceResult . result ;
121+ if ( result && result . features ) {
122+ themeLayer . addFeatures ( result . features ) ;
123+ }
124+ initLegendView ( ) ;
125+ initInfoView ( ) ;
126+ }
127+
128+ //高亮时显示图层信息框的控件
129+ function initInfoView ( ) {
130+ infoView = L . control ( { position : 'bottomright' } ) ;
131+ infoView . onAdd = function ( ) {
132+ this . _div = L . DomUtil . create ( 'div' , 'panel panel-primary infoPane' ) ;
133+ $ ( this . _div ) . css ( "width" , "272px" ) ;
134+ $ ( "<div class='panel-heading'><h5 class='panel-title text-center'>属性表</h5></div>" ) . appendTo ( this . _div ) ;
135+ var content = $ ( "<div class='panel-body content'></div>" ) . appendTo ( this . _div ) ;
136+ content . css ( 'fontSize' , '14px' ) ;
137+ return this . _div ;
138+ } ;
139+
140+ infoView . update = function ( fea ) {
141+ var content = $ ( ".content" ) ;
142+ content . text ( "" ) ;
143+ if ( ! fea ) {
144+ return ;
145+ }
146+ var innerHtml = "ID: " + fea . attributes . SMID + "<br/>" ;
147+ innerHtml += "行政区名:" + fea . attributes . NAME + "<br/>" ;
148+ innerHtml += "人口密度:" + parseFloat ( fea . attributes . POP_DENSITY99 ) . toFixed ( 5 ) + "<br/>" ;
149+ content . html ( innerHtml ) ;
150+ }
151+ }
152+
153+ //图例控件
154+ function initLegendView ( ) {
155+ var legendView = L . control ( { position : 'bottomright' } ) ;
156+ legendView . onAdd = function ( ) {
157+ this . _div = L . DomUtil . create ( 'div' , 'panel panel-primary legend ' ) ;
158+ var title = "<div class='panel-heading'><h5 class='panel-title text-center'>图例</h5></div>" ;
159+ $ ( title + "<div class='panel-body text-center' ><table>" +
160+ "<tr><td class='legendItemHeader'>人口密度(1999年)</td><td class='legendItemValue'>颜色</td></tr>" +
161+ "<tr> <td class='legendItemHeader'>0 - 0.02</td> <td class='legendItemValue' style='background: #FDE2CA'></td></tr>" +
162+ "<tr> <td class='legendItemHeader'>0.02 - 0.04</td> <td class='legendItemValue' style='background: #FACE9C'></td> </tr>" +
163+ "<tr> <td class='legendItemHeader'>0.04 - 0.06</td> <td class='legendItemValue' style='background: #F09C42'></td> </tr>" +
164+ "<tr> <td class='legendItemHeader'>0.06 - 0.1</td> <td class='legendItemValue' style='background: #D0770B'></td> </tr>" +
165+ "<tr> <td class='legendItemHeader'>0.1 - 0.2</td> <td class='legendItemValue' style='background: #945305'></td> </tr>" +
166+ "</table></div>"
167+ ) . appendTo ( this . _div ) ;
168+ return this . _div ;
169+ } ;
170+ legendView . addTo ( map ) ;
171+ }
172+
173+ function highLightLayer ( e ) {
174+ if ( e . target && e . target . refDataID ) {
175+ var fea = themeLayer . getFeatureById ( e . target . refDataID ) ;
176+ if ( fea ) {
177+ infoView . addTo ( map ) ;
178+ infoView . update ( fea ) ;
179+ }
180+ } else if ( infoView ) {
181+ infoView . remove ( ) ;
182+ }
183+ }
184+
185+ </ script >
186+ </ body >
187+ </ html >
0 commit comments