Skip to content

Commit a336b7c

Browse files
committed
【feature】1) 增加从iportal直接打开epsgcode是0和-1000的地图
2)兼容online上,老版本的标注地图 (reviewed by yuzy)
1 parent fabc1d8 commit a336b7c

File tree

1 file changed

+144
-23
lines changed

1 file changed

+144
-23
lines changed

src/openlayers/mapping/WebMap.js

Lines changed: 144 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -158,23 +158,27 @@ export class WebMap extends ol.Observable {
158158
return;
159159
}
160160
that.baseProjection = mapInfo.projection;
161+
that.mapParams = {
162+
title: mapInfo.title,
163+
description: mapInfo.description
164+
}; //存储地图的名称以及描述等信息,返回给用户
161165

162166
// 多坐标系支持
163167
if(proj4){
164168
ol.proj.setProj4(proj4);
165169
}
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)){
167175
mapInfo.projection = that.baseProjection = that.getEpsgInfoFromWKT(mapInfo.projection);
168176
}else{
169177
// 不支持的坐标系
170178
that.errorCallback && that.errorCallback({type: "Not support CS", errorMsg: `Not support CS: ${mapInfo.projection}`}, 'getMapFaild', that.map);
171179
return;
172180
}
173181

174-
that.mapParams = {
175-
title: mapInfo.title,
176-
description: mapInfo.description
177-
}; //存储地图的名称以及描述等信息,返回给用户
178182
that.addBaseMap(mapInfo);
179183
if (!mapInfo.layers || mapInfo.layers.length === 0) {
180184
that.sendMapToUser(0);
@@ -185,6 +189,110 @@ export class WebMap extends ol.Observable {
185189
that.errorCallback && that.errorCallback(error, 'getMapFaild', that.map);
186190
});
187191
}
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+
188296
/**
189297
* @private
190298
* @function ol.supermap.WebMap.prototype.addBaseMap
@@ -225,15 +333,15 @@ export class WebMap extends ol.Observable {
225333
center = [0, 0];
226334
}
227335
//与DV一致用底图的默认范围,不用存储的范围。否则会导致地图拖不动
228-
this.baseLayerExtent = extent = options.baseLayer.extent;
336+
this.baseLayerExtent = extent = options.baseLayer && options.baseLayer.extent;
229337
if(this.mapParams) {
230338
this.mapParams.extent = extent;
231339
this.mapParams.projection = projection;
232340
}
233341

234342
// 计算当前最大分辨率
235343
let maxResolution;
236-
if(options.baseLayer.layerType === "TILE" && extent && extent.length === 4){
344+
if(options.baseLayer && options.baseLayer.layerType === "TILE" && extent && extent.length === 4){
237345
let width = extent[2] - extent[0];
238346
let height = extent[3] - extent[1];
239347
let maxResolution1 = width/256;
@@ -765,7 +873,6 @@ export class WebMap extends ol.Observable {
765873
url: layerInfo.url,
766874
layer: layerInfo.name,
767875
format: 'image/png',
768-
// style: 'default',
769876
matrixSet: layerInfo.tileMatrixSet,
770877
requestEncoding: layerInfo.requestEncoding || 'KVP',
771878
tileGrid: this.getWMTSTileGrid(extent, layerInfo.scales, unit, layerInfo.dpi),
@@ -2297,21 +2404,25 @@ export class WebMap extends ol.Observable {
22972404
let geomType = feature.getGeometry().getType().toUpperCase();
22982405
// let styleType = geomType === "POINT" ? 'MARKER' : geomType;
22992406
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);
23152426
}
23162427
feature.setStyle(StyleUtils.toOpenLayersStyle(defaultStyle, geomType))
23172428
}, this)
@@ -2512,6 +2623,16 @@ export class WebMap extends ol.Observable {
25122623
return result;
25132624
});
25142625
}
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+
25152636
/**
25162637
* @private
25172638
* @function ol.supermap.WebMap.prototype.getTileLayerInfo

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy