@@ -158,23 +158,27 @@ export class WebMap extends ol.Observable {
158
158
return ;
159
159
}
160
160
that . baseProjection = mapInfo . projection ;
161
+ that . mapParams = {
162
+ title : mapInfo . title ,
163
+ description : mapInfo . description
164
+ } ; //存储地图的名称以及描述等信息,返回给用户
161
165
162
166
// 多坐标系支持
163
167
if ( proj4 ) {
164
168
ol . proj . setProj4 ( proj4 ) ;
165
169
}
166
- if ( that . addProjctionFromWKT ( mapInfo . projection ) ) {
170
+ if ( mapInfo . projection === "EPSG:-1000" || mapInfo . projection === "EPSG:0" ) {
171
+ //对于这两种地图,只能view,不能叠加其他图层
172
+ that . createSpecLayer ( mapInfo ) ;
173
+ return ;
174
+ } else if ( that . addProjctionFromWKT ( mapInfo . projection ) ) {
167
175
mapInfo . projection = that . baseProjection = that . getEpsgInfoFromWKT ( mapInfo . projection ) ;
168
176
} else {
169
177
// 不支持的坐标系
170
178
that . errorCallback && that . errorCallback ( { type : "Not support CS" , errorMsg : `Not support CS: ${ mapInfo . projection } ` } , 'getMapFaild' , that . map ) ;
171
179
return ;
172
180
}
173
181
174
- that . mapParams = {
175
- title : mapInfo . title ,
176
- description : mapInfo . description
177
- } ; //存储地图的名称以及描述等信息,返回给用户
178
182
that . addBaseMap ( mapInfo ) ;
179
183
if ( ! mapInfo . layers || mapInfo . layers . length === 0 ) {
180
184
that . sendMapToUser ( 0 ) ;
@@ -185,6 +189,110 @@ export class WebMap extends ol.Observable {
185
189
that . errorCallback && that . errorCallback ( error , 'getMapFaild' , that . map ) ;
186
190
} ) ;
187
191
}
192
+
193
+ /**
194
+ * @private
195
+ * @function ol.supermap.WebMap.prototype.createSpecLayer
196
+ * @description 创建坐标系为0和-1000的图层
197
+ * @param {object } mapInfo - 地图信息
198
+ */
199
+ createSpecLayer ( mapInfo ) {
200
+ let me = this ,
201
+ baseLayerInfo = mapInfo . baseLayer ,
202
+ url = baseLayerInfo . url ,
203
+ baseLayerType = baseLayerInfo . layerType ;
204
+
205
+ let proj = new ol . proj . Projection ( {
206
+ extent : [ mapInfo . extent . leftBottom . x , mapInfo . extent . leftBottom . y , mapInfo . extent . rightTop . x , mapInfo . extent . rightTop . y ] ,
207
+ units : 'm' ,
208
+ code : 'EPSG:0'
209
+ } ) ;
210
+ ol . proj . addProjection ( proj ) ;
211
+ let options = {
212
+ center : mapInfo . center ,
213
+ level : 0
214
+ }
215
+ //添加view
216
+ me . baseProjection = proj ;
217
+ me . createView ( options ) ;
218
+
219
+ let source ;
220
+ if ( baseLayerType === "TILE" ) {
221
+ FetchRequest . get ( `${ me . getProxy ( ) } ${ url } .json` , null , {
222
+ withCredentials : this . withCredentials
223
+ } ) . then ( function ( response ) {
224
+ return response . json ( ) ;
225
+ } ) . then ( function ( result ) {
226
+ baseLayerInfo . originResult = result ;
227
+ source = new ol . source . TileSuperMapRest ( {
228
+ url : baseLayerInfo . url ,
229
+ tileGrid : ol . source . TileSuperMapRest . optionsFromMapJSON ( baseLayerInfo . url , baseLayerInfo . originResult ) . tileGrid
230
+ } ) ;
231
+ me . addSpecToMap ( source ) ;
232
+ } ) . catch ( function ( error ) {
233
+ me . errorCallback && me . errorCallback ( error , 'getMapFaild' , me . map ) ;
234
+ } ) ;
235
+ } else if ( baseLayerType === "WMS" ) {
236
+ source = me . createWMSSource ( baseLayerInfo ) ;
237
+ me . addSpecToMap ( source ) ;
238
+ } else if ( baseLayerType === "WMTS" ) {
239
+ FetchRequest . get ( `${ me . getProxy ( ) } ${ url } ` , null , {
240
+ withCredentials : this . withCredentials
241
+ } ) . then ( function ( response ) {
242
+ return response . text ( ) ;
243
+ } ) . then ( function ( capabilitiesText ) {
244
+ baseLayerInfo . extent = [ mapInfo . extent . leftBottom . x , mapInfo . extent . leftBottom . y , mapInfo . extent . rightTop . x , mapInfo . extent . rightTop . y ] ;
245
+ baseLayerInfo . scales = me . getWMTSScales ( baseLayerInfo . tileMatrixSet , capabilitiesText ) ;
246
+ baseLayerInfo . dpi = 90.6 ;
247
+ source = me . createWMTSSource ( baseLayerInfo ) ;
248
+ me . addSpecToMap ( source ) ;
249
+ } ) . catch ( function ( error ) {
250
+ me . errorCallback && me . errorCallback ( error , 'getMapFaild' , me . map ) ;
251
+ } )
252
+ } else {
253
+ me . errorCallback && me . errorCallback ( { type : "Not support CS" , errorMsg : `Not support CS: ${ baseLayerType } ` } , 'getMapFaild' , me . map ) ;
254
+ }
255
+ }
256
+
257
+ /**
258
+ * @private
259
+ * @function ol.supermap.WebMap.prototype.addSpecToMap
260
+ * @description 将坐标系为0和-1000的图层添加到地图上
261
+ * @param {object } mapInfo - 地图信息
262
+ */
263
+ addSpecToMap ( source ) {
264
+ let layer = new ol . layer . Tile ( {
265
+ source : source ,
266
+ zIndex : 0
267
+ } ) ;
268
+ layer && this . map . addLayer ( layer ) ;
269
+ this . sendMapToUser ( 0 ) ;
270
+ }
271
+ /**
272
+ * @private
273
+ * @function ol.supermap.WebMap.prototype.getWMTSScales
274
+ * @description 获取wmts的比例尺
275
+ * @param {object } identifier - 图层存储的标识信息
276
+ * @param {object } capabilitiesText - wmts信息
277
+ */
278
+ getWMTSScales ( identifier , capabilitiesText ) {
279
+ const format = new ol . format . WMTSCapabilities ( ) ;
280
+ let capabilities = format . read ( capabilitiesText ) ;
281
+
282
+ let content = capabilities . Contents ,
283
+ tileMatrixSet = content . TileMatrixSet ;
284
+ let scales = [ ] ;
285
+ for ( let i = 0 ; i < tileMatrixSet . length ; i ++ ) {
286
+ if ( tileMatrixSet [ i ] . Identifier === identifier ) {
287
+ for ( let h = 0 ; h < tileMatrixSet [ i ] . TileMatrix . length ; h ++ ) {
288
+ scales . push ( tileMatrixSet [ i ] . TileMatrix [ h ] . ScaleDenominator )
289
+ }
290
+ break ;
291
+ }
292
+ }
293
+ return scales ;
294
+ }
295
+
188
296
/**
189
297
* @private
190
298
* @function ol.supermap.WebMap.prototype.addBaseMap
@@ -225,15 +333,15 @@ export class WebMap extends ol.Observable {
225
333
center = [ 0 , 0 ] ;
226
334
}
227
335
//与DV一致用底图的默认范围,不用存储的范围。否则会导致地图拖不动
228
- this . baseLayerExtent = extent = options . baseLayer . extent ;
336
+ this . baseLayerExtent = extent = options . baseLayer && options . baseLayer . extent ;
229
337
if ( this . mapParams ) {
230
338
this . mapParams . extent = extent ;
231
339
this . mapParams . projection = projection ;
232
340
}
233
341
234
342
// 计算当前最大分辨率
235
343
let maxResolution ;
236
- if ( options . baseLayer . layerType === "TILE" && extent && extent . length === 4 ) {
344
+ if ( options . baseLayer && options . baseLayer . layerType === "TILE" && extent && extent . length === 4 ) {
237
345
let width = extent [ 2 ] - extent [ 0 ] ;
238
346
let height = extent [ 3 ] - extent [ 1 ] ;
239
347
let maxResolution1 = width / 256 ;
@@ -765,7 +873,6 @@ export class WebMap extends ol.Observable {
765
873
url : layerInfo . url ,
766
874
layer : layerInfo . name ,
767
875
format : 'image/png' ,
768
- // style: 'default',
769
876
matrixSet : layerInfo . tileMatrixSet ,
770
877
requestEncoding : layerInfo . requestEncoding || 'KVP' ,
771
878
tileGrid : this . getWMTSTileGrid ( extent , layerInfo . scales , unit , layerInfo . dpi ) ,
@@ -2297,21 +2404,25 @@ export class WebMap extends ol.Observable {
2297
2404
let geomType = feature . getGeometry ( ) . getType ( ) . toUpperCase ( ) ;
2298
2405
// let styleType = geomType === "POINT" ? 'MARKER' : geomType;
2299
2406
let defaultStyle = feature . getProperties ( ) . useStyle ;
2300
- if ( geomType === 'POINT' && defaultStyle . text ) {
2301
- //说明是文字的feature类型
2302
- geomType = "TEXT" ;
2303
- }
2304
- let featureInfo = this . setFeatureInfo ( feature ) ;
2305
- feature . setProperties ( {
2306
- useStyle : defaultStyle ,
2307
- featureInfo : featureInfo
2308
- } ) ;
2309
- //标注图层的feature上需要存一个layerId,为了之后样式应用到图层上使用
2310
- // feature.layerId = timeId;
2311
- if ( geomType === 'POINT' && defaultStyle . src &&
2312
- defaultStyle . src . indexOf ( 'http://' ) === - 1 && defaultStyle . src . indexOf ( 'https://' ) === - 1 ) {
2313
- //说明地址不完整
2314
- defaultStyle . src = that . server + defaultStyle . src ;
2407
+ if ( defaultStyle ) {
2408
+ if ( geomType === 'POINT' && defaultStyle . text ) {
2409
+ //说明是文字的feature类型
2410
+ geomType = "TEXT" ;
2411
+ }
2412
+ let featureInfo = this . setFeatureInfo ( feature ) ;
2413
+ feature . setProperties ( {
2414
+ useStyle : defaultStyle ,
2415
+ featureInfo : featureInfo
2416
+ } ) ;
2417
+ //标注图层的feature上需要存一个layerId,为了之后样式应用到图层上使用
2418
+ // feature.layerId = timeId;
2419
+ if ( geomType === 'POINT' && defaultStyle . src &&
2420
+ defaultStyle . src . indexOf ( 'http://' ) === - 1 && defaultStyle . src . indexOf ( 'https://' ) === - 1 ) {
2421
+ //说明地址不完整
2422
+ defaultStyle . src = that . server + defaultStyle . src ;
2423
+ }
2424
+ } else {
2425
+ defaultStyle = StyleUtils . getMarkerDefaultStyle ( geomType , that . server ) ;
2315
2426
}
2316
2427
feature . setStyle ( StyleUtils . toOpenLayersStyle ( defaultStyle , geomType ) )
2317
2428
} , this )
@@ -2512,6 +2623,16 @@ export class WebMap extends ol.Observable {
2512
2623
return result ;
2513
2624
} ) ;
2514
2625
}
2626
+ /**
2627
+ * @private
2628
+ * @function ol.supermap.WebMap.prototype.getProxy
2629
+ * @description 获取代理地址
2630
+ * @returns {Promise<T | never> } 代理地址
2631
+ */
2632
+ getProxy ( ) {
2633
+ return this . server + 'apps/viewer/getUrlResource.json?url=' ;
2634
+ }
2635
+
2515
2636
/**
2516
2637
* @private
2517
2638
* @function ol.supermap.WebMap.prototype.getTileLayerInfo
0 commit comments