1+ <!DOCTYPE html>
2+ < html >
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < title > 空间分析-离散点插值分析</ title >
6+
7+ < link href ="http://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css " rel ="stylesheet ">
8+ < link href ="http://cdn.bootcss.com/openlayers/4.2.0/ol.css " rel ="stylesheet ">
9+ </ head >
10+ < body style =" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100% ">
11+ < div id ="map " style ="width: 100%;height:100% "> </ div >
12+
13+ < script src ="http://cdn.bootcss.com/openlayers/4.2.0/ol.js "> </ script >
14+ < script type ="text/javascript " src ="../../dist/iclient9-openlayers.min.js "> </ script >
15+ < script type ="text/javascript ">
16+ var map , options , interpolationAnalystService , interpolationAnalystParameters , interpolationAnalystResult , points ,
17+ themeService , themeGridRange , themeParameters ,
18+ baseUrl = "http://support.supermap.com.cn:8090/iserver/services/map-temperature/rest/maps/全国温度变化图" ,
19+ serviceUrl = "http://support.supermap.com.cn:8090/iserver/services/spatialanalyst-sample/restjsr/spatialanalyst" ;
20+ var mapService = new ol . supermap . MapService ( baseUrl ) ;
21+ var extent = [ - 2640403.63 , 1873792.1 , 3247669.39 , 5921501.4 ] ;
22+ var projection = new ol . proj . Projection ( {
23+ extent : extent ,
24+ units : 'm'
25+ } ) ;
26+ mapService . getMapInfo ( function ( serviceResult ) {
27+ var mapJSONObj = serviceResult . result ;
28+ map = new ol . Map ( {
29+ target : 'map' ,
30+ controls : ol . control . defaults ( { attributionOptions : { collapsed : false } } )
31+ . extend ( [ new ol . supermap . control . Logo ( ) ] ) ,
32+ view : new ol . View ( {
33+ center : [ 531762 , 3580330 ] ,
34+ zoom : 1 ,
35+ projection : projection
36+ } )
37+ } ) ;
38+ options = ol . source . TileSuperMapRest . optionsFromMapJSON ( baseUrl , mapJSONObj ) ;
39+ options . layersID = "[0,1,2]" ;
40+ var layer = new ol . layer . Tile ( {
41+ source : new ol . source . TileSuperMapRest ( options )
42+ } ) ;
43+ map . addLayer ( layer ) ;
44+ interpolationAnalystProcess ( ) ;
45+ } ) ;
46+
47+ function interpolationAnalystProcess ( ) {
48+ //通过SQL查询的方法获取用于插值分析的geometry
49+ var queryBySQLParams , queryBySQLService ;
50+ queryBySQLService = new ol . supermap . QueryService ( baseUrl ) ;
51+ queryBySQLParams = new SuperMap . QueryBySQLParameters ( {
52+ queryParams : [
53+ new SuperMap . FilterParameter ( {
54+ name : "SamplesP@Interpolation" ,
55+ attributeFilter : "SMID>0"
56+ } )
57+ ]
58+ } ) ;
59+ queryBySQLService . queryBySQL ( queryBySQLParams , function ( serviceResult ) {
60+ var result = serviceResult . result ;
61+ var z ;
62+ var zMin = parseFloat ( - 5 ) , zMax = parseFloat ( 28 ) ;
63+ points = [ ] ;
64+ if ( result ) {
65+ for ( var i = 0 ; i < result . recordsets [ 0 ] . features . features . length ; i ++ ) {
66+ gp = result . recordsets [ 0 ] . features . features [ i ] . geometry ;
67+ var point = new ol . geom . Point ( [ gp . coordinates [ 0 ] , gp . coordinates [ 1 ] ] ) ;
68+ //每个插值点在插值过程中的权重值
69+ z = Math . random ( ) * ( zMax - zMin ) + zMin ;
70+ point . tag = z ;
71+ points . push ( point ) ;
72+ }
73+ }
74+
75+ //创建离散点插值分析服务实例
76+ interpolationAnalystService = new ol . supermap . SpatialAnalystService ( serviceUrl ) ;
77+ //创建离散点插值分析参数实例
78+ interpolationAnalystParameters = new SuperMap . InterpolationIDWAnalystParameters ( {
79+ // 插值分析类型,geometry类型表示对离散点插值分析,默认为“dataset”
80+ InterpolationAnalystType : "geometry" ,
81+ // 插值分析结果数据集的名称
82+ outputDatasetName : "IDWcretePoints_result" ,
83+ // 插值分析结果数据源的名称
84+ outputDatasourceName : "Interpolation" ,
85+ // 结果栅格数据集存储的像素格式
86+ pixelFormat : SuperMap . PixelFormat . BIT16 ,
87+ // 用于做插值分析的离散点集合
88+ inputPoints : points ,
89+ // 属性过滤条件
90+ // filterQueryParameter: {
91+ // attributeFilter: ""
92+ // },
93+ // 采取定长查找参与运算点的方式
94+ searchMode : "KDTREE_FIXED_RADIUS" ,
95+ // 查找半径,与点数据单位相同
96+ searchRadius : 200 ,
97+ resolution : 3000 ,
98+ bounds : [ - 2640403.63 , 1873792.1 , 3247669.39 , 5921501.4 ]
99+ } ) ;
100+ interpolationAnalystService . interpolationAnalysis ( interpolationAnalystParameters , function ( serviceResult ) {
101+ interpolationAnalystResult = serviceResult . result ;
102+ //用栅格专题图展示分析结果
103+ showAnalysisResult_ThemeGridRange ( ) ;
104+ } ) ;
105+ } ) ;
106+
107+
108+ //构造栅格专题图
109+ function showAnalysisResult_ThemeGridRange ( ) {
110+ //创建专题图服务实例
111+ themeService = new ol . supermap . ThemeService ( baseUrl ) ;
112+ var color1 = new SuperMap . ServerColor ( 170 , 240 , 233 ) ,
113+ color2 = new SuperMap . ServerColor ( 176 , 244 , 188 ) ,
114+ color3 = new SuperMap . ServerColor ( 218 , 251 , 178 ) ,
115+ color4 = new SuperMap . ServerColor ( 220 , 236 , 145 ) ,
116+ color5 = new SuperMap . ServerColor ( 96 , 198 , 66 ) ,
117+ color6 = new SuperMap . ServerColor ( 20 , 142 , 53 ) ,
118+ color7 = new SuperMap . ServerColor ( 85 , 144 , 55 ) ,
119+ color8 = new SuperMap . ServerColor ( 171 , 168 , 38 ) ,
120+ color9 = new SuperMap . ServerColor ( 235 , 165 , 9 ) ,
121+ color10 = new SuperMap . ServerColor ( 203 , 89 , 2 ) ,
122+ color11 = new SuperMap . ServerColor ( 157 , 25 , 1 ) ,
123+ color12 = new SuperMap . ServerColor ( 118 , 15 , 3 ) ,
124+ color13 = new SuperMap . ServerColor ( 112 , 32 , 7 ) ,
125+ color14 = new SuperMap . ServerColor ( 106 , 45 , 12 ) ,
126+ color15 = new SuperMap . ServerColor ( 129 , 80 , 50 ) ,
127+ color16 = new SuperMap . ServerColor ( 160 , 154 , 146 ) ,
128+ color17 = new SuperMap . ServerColor ( 107 , 47 , 14 ) ,
129+ color18 = new SuperMap . ServerColor ( 125 , 75 , 44 ) ,
130+ color19 = new SuperMap . ServerColor ( 146 , 110 , 88 ) ,
131+ color20 = new SuperMap . ServerColor ( 166 , 153 , 146 ) ;
132+
133+ var themeGridRangeItem1 = new SuperMap . ThemeGridRangeItem ( {
134+ start : - 5 ,
135+ end : - 3.4 ,
136+ color : color1
137+ } ) ,
138+ themeGridRangeItem2 = new SuperMap . ThemeGridRangeItem ( {
139+ start : - 3.4 ,
140+ end : - 1.8 ,
141+ color : color2
142+ } ) ,
143+ themeGridRangeItem3 = new SuperMap . ThemeGridRangeItem ( {
144+ start : - 1.8 ,
145+ end : - 0.2 ,
146+ color : color3
147+ } ) ,
148+ themeGridRangeItem4 = new SuperMap . ThemeGridRangeItem ( {
149+ start : - 0.2 ,
150+ end : 1.4 ,
151+ color : color4
152+ } ) ,
153+ themeGridRangeItem5 = new SuperMap . ThemeGridRangeItem ( {
154+ start : 1.4 ,
155+ end : 3 ,
156+ color : color5
157+ } ) ,
158+ themeGridRangeItem6 = new SuperMap . ThemeGridRangeItem ( {
159+ start : 3 ,
160+ end : 4.6 ,
161+ color : color6
162+ } ) ,
163+ themeGridRangeItem7 = new SuperMap . ThemeGridRangeItem ( {
164+ start : 4.6 ,
165+ end : 6.2 ,
166+ color : color7
167+ } ) ,
168+ themeGridRangeItem8 = new SuperMap . ThemeGridRangeItem ( {
169+ start : 6.2 ,
170+ end : 7.8 ,
171+ color : color8
172+ } ) ,
173+ themeGridRangeItem9 = new SuperMap . ThemeGridRangeItem ( {
174+ start : 7.8 ,
175+ end : 9.4 ,
176+ color : color9
177+ } ) ,
178+ themeGridRangeItem10 = new SuperMap . ThemeGridRangeItem ( {
179+ start : 9.4 ,
180+ end : 11 ,
181+ color : color10
182+ } ) ,
183+ themeGridRangeItem11 = new SuperMap . ThemeGridRangeItem ( {
184+ start : 11 ,
185+ end : 12.6 ,
186+ color : color11
187+ } ) ,
188+ themeGridRangeItem12 = new SuperMap . ThemeGridRangeItem ( {
189+ start : 12.6 ,
190+ end : 14.2 ,
191+ color : color12
192+ } ) ,
193+ themeGridRangeItem13 = new SuperMap . ThemeGridRangeItem ( {
194+ start : 14.2 ,
195+ end : 15.8 ,
196+ color : color13
197+ } ) ,
198+ themeGridRangeItem14 = new SuperMap . ThemeGridRangeItem ( {
199+ start : 15.8 ,
200+ end : 17.4 ,
201+ color : color14
202+ } ) ,
203+ themeGridRangeItem15 = new SuperMap . ThemeGridRangeItem ( {
204+ start : 17.4 ,
205+ end : 19 ,
206+ color : color15
207+ } ) ,
208+ themeGridRangeItem16 = new SuperMap . ThemeGridRangeItem ( {
209+ start : 19 ,
210+ end : 20.6 ,
211+ color : color16
212+ } ) ,
213+ themeGridRangeItem17 = new SuperMap . ThemeGridRangeItem ( {
214+ start : 20.6 ,
215+ end : 22.2 ,
216+ color : color17
217+ } ) ,
218+ themeGridRangeItem18 = new SuperMap . ThemeGridRangeItem ( {
219+ start : 22.2 ,
220+ end : 23.8 ,
221+ color : color18
222+ } ) ,
223+ themeGridRangeItem19 = new SuperMap . ThemeGridRangeItem ( {
224+ start : 23.8 ,
225+ end : 25.4 ,
226+ color : color19
227+ } ) ,
228+ themeGridRangeItem20 = new SuperMap . ThemeGridRangeItem ( {
229+ start : 25.4 ,
230+ end : 27 ,
231+ color : color20
232+ } ) ;
233+
234+ themeGridRange = new SuperMap . ThemeGridRange ( {
235+ reverseColor : false ,
236+ rangeMode : SuperMap . RangeMode . EQUALINTERVAL ,
237+ //栅格分段专题图子项数组
238+ items : [ themeGridRangeItem1 , themeGridRangeItem2 ,
239+ themeGridRangeItem3 , themeGridRangeItem4 ,
240+ themeGridRangeItem5 , themeGridRangeItem6 ,
241+ themeGridRangeItem7 , themeGridRangeItem8 ,
242+ themeGridRangeItem9 , themeGridRangeItem10 ,
243+ themeGridRangeItem11 , themeGridRangeItem12 ,
244+ themeGridRangeItem13 , themeGridRangeItem14 ,
245+ themeGridRangeItem15 , themeGridRangeItem16 ,
246+ themeGridRangeItem17 , themeGridRangeItem18 ,
247+ themeGridRangeItem19 , themeGridRangeItem20
248+ ]
249+ } ) ;
250+
251+ themeParameters = new SuperMap . ThemeParameters ( {
252+ //制作专题图的数据集
253+ datasetNames : [ interpolationAnalystResult . dataset . split ( '@' ) [ 0 ] ] ,
254+ dataSourceNames : [ "Interpolation" ] ,
255+ joinItems : null ,
256+ themes : [ themeGridRange ]
257+ } ) ;
258+
259+ themeService . getThemeInfo ( themeParameters , function ( serviceResult ) {
260+ var result = serviceResult . result ;
261+ if ( result && result . newResourceID ) {
262+ var themeLayer = new ol . layer . Tile ( {
263+ source : new ol . source . TileSuperMapRest ( {
264+ url : baseUrl ,
265+ noWrap : true ,
266+ cacheEnabled : false ,
267+ transparent : true ,
268+ layersID : result . newResourceID ,
269+ tileGrid : new ol . tilegrid . TileGrid ( {
270+ extent : extent ,
271+ resolutions : options . tileGrid . getResolutions ( )
272+ } ) ,
273+ } )
274+ } ) ;
275+ map . addLayer ( themeLayer ) ;
276+ }
277+ } ) ;
278+ }
279+ }
280+ </ script >
281+ </ body >
282+ </ html >
0 commit comments