|
2 | 2 | * This program are made available under the terms of the Apache License, Version 2.0 |
3 | 3 | * which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html. */ |
4 | 4 | import cloneDeep from 'lodash.clonedeep'; |
5 | | -import { getProjection, toEpsgCode, transformCoodinates } from './utils/epsg-define'; |
6 | | -import { ColorsPickerUtil } from '../util/ColorsPickerUtil'; |
7 | 5 | import { Util } from '../commontypes/Util'; |
8 | 6 | import { ArrayStatistic } from '../util/ArrayStatistic'; |
| 7 | +import { ColorsPickerUtil } from '../util/ColorsPickerUtil'; |
9 | 8 | import { FetchRequest } from '../util/FetchRequest'; |
| 9 | +import { getProjection, toEpsgCode, transformCoodinates } from './utils/epsg-define'; |
10 | 10 | import { SourceListModelV2 } from './utils/SourceListModelV2'; |
11 | 11 | import { isSameRasterLayer, mergeFeatures } from './utils/util'; |
12 | 12 |
|
@@ -60,6 +60,10 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa |
60 | 60 | } |
61 | 61 | this._appendLayers = true; |
62 | 62 | this.map = map; |
| 63 | + if (this.map.addLocalIdeographFontFamily) { |
| 64 | + const fontFamilys = this._getLabelFontFamily(mapInfo); |
| 65 | + this.map.addLocalIdeographFontFamily(fontFamilys); |
| 66 | + } |
63 | 67 | } |
64 | 68 | this._mapInfo = mapInfo; |
65 | 69 | this._loadLayers(mapInfo, this._taskID); |
@@ -181,6 +185,45 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa |
181 | 185 | crsManager.registerCRS(crs); |
182 | 186 | return epsgCode; |
183 | 187 | } |
| 188 | + _getPopupInfos() { |
| 189 | + const { layers = [] } = this._mapInfo; |
| 190 | + return layers.map((layer) => { |
| 191 | + const { popupInfo, enableFields, name, layerID: layerId, captions: fieldCaptions } = layer; |
| 192 | + if (popupInfo){ |
| 193 | + let elements = popupInfo.elements || []; |
| 194 | + if (fieldCaptions) { |
| 195 | + elements = (popupInfo.elements || []).map(item => { |
| 196 | + if (item.type === 'FIELD') { |
| 197 | + item.fieldCaption = fieldCaptions[item.fieldName] || item.fieldName; |
| 198 | + } |
| 199 | + return item; |
| 200 | + }); |
| 201 | + } |
| 202 | + return { ...popupInfo, layerId: [layerId], elements, title: name }; |
| 203 | + } |
| 204 | + if (enableFields) { |
| 205 | + const elements = enableFields.map((fieldName) => ({ |
| 206 | + type: 'FIELD', |
| 207 | + fieldName, |
| 208 | + fieldCaption: fieldCaptions ? (fieldCaptions[fieldName] || fieldName) : fieldName |
| 209 | + })); |
| 210 | + return { elements, layerId: [layerId], title: name }; |
| 211 | + } |
| 212 | + return null; |
| 213 | + }).filter(item => item !== null); |
| 214 | + } |
| 215 | + |
| 216 | + _getLegendInfos() { |
| 217 | + const { layers = [] } = this._mapInfo; |
| 218 | + return layers.map((layer) => { |
| 219 | + const { legendSetting, name, layerID: layerId } = layer; |
| 220 | + return { |
| 221 | + showLegend: legendSetting ? legendSetting?.isShow !== false : false, |
| 222 | + id: layerId, |
| 223 | + title: name |
| 224 | + }; |
| 225 | + }); |
| 226 | + } |
184 | 227 |
|
185 | 228 | _handleLayerInfo(mapInfo, _taskID) { |
186 | 229 | mapInfo = this._setLayerID(mapInfo); |
@@ -812,6 +855,9 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa |
812 | 855 | bounds = this._getBoundList(res); |
813 | 856 | } |
814 | 857 | } |
| 858 | + if (bounds && !this._isValidBounds(bounds)) { |
| 859 | + bounds = null; |
| 860 | + } |
815 | 861 | } |
816 | 862 | this._addBaselayer({ |
817 | 863 | url: [url], |
@@ -2764,6 +2810,35 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa |
2764 | 2810 | return coor; |
2765 | 2811 | } |
2766 | 2812 |
|
| 2813 | + // 校验 bounds 是否为合法的经纬度范围(EPSG:4326) |
| 2814 | + // 不合法返回 false:值非数字/无穷、左>=右、下>=上、四个坐标都在 ±0.5 度内(认为退化为原点附近)、超出经纬度范围 |
| 2815 | + _isValidBounds(bounds) { |
| 2816 | + if (!Array.isArray(bounds) || bounds.length !== 4) { |
| 2817 | + return false; |
| 2818 | + } |
| 2819 | + const [left, bottom, right, top] = bounds; |
| 2820 | + if (![left, bottom, right, top].every((v) => typeof v === 'number' && Number.isFinite(v))) { |
| 2821 | + return false; |
| 2822 | + } |
| 2823 | + if (left >= right || bottom >= top) { |
| 2824 | + return false; |
| 2825 | + } |
| 2826 | + // 容差,吸收浮点计算误差(如 180.00000000000006) |
| 2827 | + const tolerance = 1e-6; |
| 2828 | + if ( |
| 2829 | + Math.abs(left) > 180 + tolerance || |
| 2830 | + Math.abs(right) > 180 + tolerance || |
| 2831 | + Math.abs(bottom) > 90 + tolerance || |
| 2832 | + Math.abs(top) > 90 + tolerance |
| 2833 | + ) { |
| 2834 | + return false; |
| 2835 | + } |
| 2836 | + if (Math.abs(left) < 0.5 && Math.abs(right) < 0.5 && Math.abs(bottom) < 0.5 && Math.abs(top) < 0.5) { |
| 2837 | + return false; |
| 2838 | + } |
| 2839 | + return true; |
| 2840 | + } |
| 2841 | + |
2767 | 2842 | _getMapCenter(mapInfo) { |
2768 | 2843 | // center |
2769 | 2844 | let center = mapInfo.center && [mapInfo.center.x, mapInfo.center.y]; |
|
0 commit comments