22 * This program are made available under the terms of the Apache License, Version 2.0
33 * which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
44import { FetchRequest } from '../util/FetchRequest' ;
5- import { getLayerCatalogRenderLayers , getLayerInfosFromCatalogs , getMainLayerFromCatalog , isSameRasterLayer , mergeFeatures , transformUrl } from './utils/util' ;
5+ import { getLayerCatalogRenderLayers , getLayerInfosFromCatalogs , getMainLayerFromCatalog , isSameRasterLayer , mergeFeatures , transformUrl , flipImageVertically } from './utils/util' ;
66import { SourceListModelV3 } from './utils/SourceListModelV3' ;
77import cloneDeep from 'lodash.clonedeep' ;
88
@@ -162,6 +162,28 @@ export const LEGEND_STYLE_TYPES = {
162162 IMAGE : 'image' ,
163163 STYLE : 'style'
164164} ;
165+
166+ /**
167+ * 按地图版本创建 Sprite 加载处理函数,供 WebMap 和外部 WebApp 共用。
168+ * @param {string } mapVersion 地图版本号。
169+ * @returns {Function|undefined } 旧版地图返回线符号处理函数,新版地图不需要额外处理。
170+ */
171+ export function createSpriteLoadHandler ( mapVersion ) {
172+ const [ major , minor , patch ] = typeof mapVersion === 'string' ? mapVersion . split ( '.' ) . map ( Number ) : [ ] ;
173+ // 3.3.7 及以前的地图线符号需要垂直翻转;新版本由地图数据自身保证方向。
174+ if ( major > 3 || ( major === 3 && minor > 3 ) || ( major === 3 && minor === 3 && patch > 7 ) ) {
175+ return ;
176+ }
177+ return ( id , imageData , width , height ) => {
178+ // 翻转所有 line- 开头的图案
179+ if ( id && id . startsWith ( 'line-' ) ) {
180+ return flipImageVertically ( imageData , width , height ) ;
181+ }
182+
183+ return null ;
184+ } ;
185+ }
186+
165187export function createWebMapV3Extending ( SuperClass , { MapManager, mapRepo, crsManager, l7LayerUtil, webMapService } ) {
166188 return class WebMapV3 extends SuperClass {
167189 constructor ( mapId , options , mapOptions = { } ) {
@@ -291,6 +313,9 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, crsMa
291313 // 初始化 map
292314 const mapOptions = {
293315 ...this . mapOptions ,
316+ // 统一线图案方向,避免 Mapbox GL 默认方向与 WebMap 符号方向约定不一致;旧版资源翻转由 _getSpriteLoad 按地图版本处理。
317+ linePatternOrientation : 'west-to-east' ,
318+ onSpriteLoad : this . _getSpriteLoad ( ) ,
294319 transformRequest : this . _getTransformRequest ( ) ,
295320 container : this . options . target ,
296321 crs : this . _baseProjection ,
@@ -317,6 +342,10 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, crsMa
317342 } ) ;
318343 }
319344
345+ _getSpriteLoad ( ) {
346+ return createSpriteLoadHandler ( this . _mapInfo && this . _mapInfo . version ) ;
347+ }
348+
320349 _getTransformRequest ( ) {
321350 if ( this . mapOptions . transformRequest ) {
322351 return this . mapOptions . transformRequest ;
0 commit comments