Skip to content

Commit 2dc000a

Browse files
committed
feat: 导出 Sprite 加载处理函数
- 提取 createSpriteLoadHandler 供外部 WebApp 使用 - 从 common 和 mapboxgl 包入口导出该函数 - 补充公共导出测试 AI-GEN: 90% gpt5.6-luna
1 parent 305b351 commit 2dc000a

5 files changed

Lines changed: 37 additions & 16 deletions

File tree

‎src/common/mapping/WebMapV3.js‎

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,28 @@ export const LEGEND_STYLE_TYPES = {
160160
IMAGE: 'image',
161161
STYLE: 'style'
162162
};
163+
164+
/**
165+
* 按地图版本创建 Sprite 加载处理函数,供 WebMap 和外部 WebApp 共用。
166+
* @param {string} mapVersion 地图版本号。
167+
* @returns {Function|undefined} 旧版地图返回线符号处理函数,新版地图不需要额外处理。
168+
*/
169+
export function createSpriteLoadHandler(mapVersion) {
170+
const [major, minor, patch] = typeof mapVersion === 'string' ? mapVersion.split('.').map(Number) : [];
171+
// 3.3.7 及以前的地图线符号需要垂直翻转;新版本由地图数据自身保证方向。
172+
if (major > 3 || (major === 3 && minor > 3) || (major === 3 && minor === 3 && patch > 7)) {
173+
return;
174+
}
175+
return (id, imageData, width, height) => {
176+
// 翻转所有 line- 开头的图案
177+
if (id && id.startsWith('line-')) {
178+
return flipImageVertically(imageData, width, height);
179+
}
180+
181+
return null;
182+
};
183+
}
184+
163185
export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, crsManager, l7LayerUtil, webMapService }) {
164186
return class WebMapV3 extends SuperClass {
165187
constructor(mapId, options, mapOptions = {}) {
@@ -319,20 +341,7 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, crsMa
319341
}
320342

321343
_getSpriteLoad() {
322-
const version = this._mapInfo && this._mapInfo.version;
323-
const [major, minor, patch] = typeof version === 'string' ? version.split('.').map(Number) : [];
324-
// 3.3.7 及以前的地图线符号需要垂直翻转;新版本由地图数据自身保证方向。
325-
if (major > 3 || (major === 3 && minor > 3) || (major === 3 && minor === 3 && patch > 7)) {
326-
return;
327-
}
328-
return (id, imageData, width, height) => {
329-
// 翻转所有 line- 开头的图案
330-
if (id && id.startsWith('line-')) {
331-
return flipImageVertically(imageData, width, height);
332-
}
333-
334-
return null;
335-
};
344+
return createSpriteLoadHandler(this._mapInfo && this._mapInfo.version);
336345
}
337346

338347
_getTransformRequest() {

‎src/common/mapping/index.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ export * from './WebMapV2Base';
22
export * from './WebMapService';
33
export * from './utils/epsg-define';
44
export * from './WebMapBase';
5-
export * from './utils/SourceListModelV2';
5+
export * from './utils/SourceListModelV2';
6+
export { createSpriteLoadHandler } from './WebMapV3';

‎src/mapboxgl/mapping/index.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export { WebMap } from './WebMap';
22
export { initMap } from './InitMap';
3-
export { VideoMap } from './VideoMap';
3+
export { VideoMap } from './VideoMap';
4+
export { createSpriteLoadHandler } from '@supermapgis/iclient-common/mapping/WebMapV3';

‎test/common/mapping/WebMapV3Spec.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createWebMapV3Extending } from '../../../src/common/mapping/WebMapV3';
2+
import { createSpriteLoadHandler } from '../../../src/common/mapping';
23
import { createWebMapBaseExtending } from '../../../src/common/mapping/WebMapBase';
34
import { Events } from '../../../src/common/commontypes';
45

@@ -131,6 +132,11 @@ describe('WebMapV3 - addLocalIdeographFontFamily', () => {
131132
});
132133

133134
describe('_getSpriteLoad', () => {
135+
it('should be exported for external WebApps', () => {
136+
expect(createSpriteLoadHandler('3.3.7')).toEqual(jasmine.any(Function));
137+
expect(createSpriteLoadHandler('3.3.8')).toBeUndefined();
138+
});
139+
134140
it('should flip line sprites for maps at version 3.3.7', () => {
135141
instance._mapInfo = { version: '3.3.7' };
136142
const onSpriteLoad = instance._getSpriteLoad();

‎test/mapboxgl/mapping/WebMapV3Spec.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { createWebMapV3Extending } from '../../../src/common/mapping/WebMapV3';
44
import { createMapClassExtending } from '../../../src/common/mapping/MapBase';
55
import { L7LayerUtil } from '../../../src/common/mapping/utils/L7LayerUtil';
66
import { WebMap } from '../../../src/mapboxgl/mapping/WebMap';
7+
import { createSpriteLoadHandler } from '../../../src/mapboxgl';
78
import * as MapManagerUtil from '../../../src/mapboxgl/mapping/webmap/MapManager';
89
import { CRSManager } from '../../../src/mapboxgl/mapping/webmap/CRSManager';
910
import { featureFilter, expression } from '@mapbox/mapbox-gl-style-spec';
@@ -15,6 +16,9 @@ import '../../resources/WebMapV3.js';
1516
import '../../resources/WebMapV5.js';
1617

1718
describe('mapboxgl-webmap3.0', () => {
19+
it('exports the Sprite load handler from the package entry point', () => {
20+
expect(createSpriteLoadHandler('3.3.7')).toEqual(jasmine.any(Function));
21+
});
1822
var originalTimeout, testDiv;
1923
var server = 'http://localhost:8190/iportal/';
2024
var id = 617580084;

0 commit comments

Comments
 (0)