* @private * @function WebMap.prototype.createView * @description 创建地图视图 * @param {Object} options - 关于地图的信息
(options)
| 880 | * @param {Object} options - 关于地图的信息 |
| 881 | */ |
| 882 | createView(options) { |
| 883 | let oldcenter = options.center, |
| 884 | zoom = options.level !== undefined ? options.level : 1, |
| 885 | maxZoom = options.maxZoom || 22, |
| 886 | extent, |
| 887 | projection = this.baseProjection; |
| 888 | let center = []; |
| 889 | for (let key in oldcenter) { |
| 890 | center.push(oldcenter[key]); |
| 891 | } |
| 892 | if (center.length === 0) { |
| 893 | //兼容wms |
| 894 | center = [0, 0]; |
| 895 | } |
| 896 | //与DV一致用底图的默认范围,不用存储的范围。否则会导致地图拖不动 |
| 897 | this.baseLayerExtent = extent = options.baseLayer && options.baseLayer.extent; |
| 898 | if (this.mapParams) { |
| 899 | this.mapParams.extent = extent; |
| 900 | this.mapParams.projection = projection; |
| 901 | } |
| 902 | //当前中心点不在extent内,就用extent的中心点 todo |
| 903 | !containsCoordinate(extent, center) && (center = getCenter(extent)); |
| 904 | |
| 905 | // 计算当前最大分辨率 |
| 906 | let baseLayer = options.baseLayer; |
| 907 | let maxResolution; |
| 908 | if ( |
| 909 | (baseLayer.visibleScales && baseLayer.visibleScales.length > 0) || |
| 910 | (baseLayer.scales && baseLayer.scales.length > 0) |
| 911 | ) { |
| 912 | //底图有固定比例尺,就直接获取。不用view计算 |
| 913 | this.getScales(baseLayer); |
| 914 | } else if (baseLayer && baseLayer.layerType !=="ZXY_TILE" && extent && extent.length === 4) { |
| 915 | let width = extent[2] - extent[0]; |
| 916 | let height = extent[3] - extent[1]; |
| 917 | let maxResolution1 = width / 512; |
| 918 | let maxResolution2 = height / 512; |
| 919 | maxResolution = Math.max(maxResolution1, maxResolution2); |
| 920 | } |
| 921 | |
| 922 | // if(options.baseLayer.visibleScales && options.baseLayer.visibleScales.length > 0){ |
| 923 | // maxZoom = options.baseLayer.visibleScales.length; |
| 924 | // } |
| 925 | this.map.setView(new View({ zoom, center, projection, maxZoom, maxResolution })); |
| 926 | let viewOptions = {}; |
| 927 | |
| 928 | if (baseLayer.layerType === "ZXY_TILE") { |
| 929 | const { resolutions, minZoom, maxZoom } = baseLayer; |
| 930 | viewOptions = { minZoom, maxZoom, zoom, center, projection, resolutions}; |
| 931 | this.getScales(baseLayer); |
| 932 | } else if ( |
| 933 | (baseLayer.scales && baseLayer.scales.length > 0 && baseLayer.layerType === 'WMTS') || |
| 934 | (this.resolutionArray && this.resolutionArray.length > 0) |
| 935 | ) { |
| 936 | viewOptions = { zoom, center, projection, resolutions: this.resolutionArray, maxZoom }; |
| 937 | } else if (baseLayer.layerType === 'WMTS') { |
| 938 | viewOptions = { zoom, center, projection, maxZoom }; |
| 939 | this.getScales(baseLayer); |