Skip to content

Commit 2de4f48

Browse files
committed
【fix】webmapv2 引入xx.supermap.xx; review by qiw
1 parent 3044618 commit 2de4f48

File tree

6 files changed

+44
-11
lines changed

6 files changed

+44
-11
lines changed

src/common/commontypes/Util.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,30 @@ const Util = {
10861086
}
10871087
return encodeURIComponent(value);
10881088
});
1089+
},
1090+
/**
1091+
* @description 十六进制转 RGBA 格式。
1092+
* @param {Object} hex - 十六进制格式。
1093+
* @param {number} opacity - 不透明度Alpha。
1094+
* @returns {string} 生成的 RGBA 格式。
1095+
*/
1096+
hexToRgba(hex, opacity) {
1097+
var color = [],
1098+
rgba = [];
1099+
hex = hex.replace(/#/, "");
1100+
if (hex.length == 3) {
1101+
var tmp = [];
1102+
for (let i = 0; i < 3; i++) {
1103+
tmp.push(hex.charAt(i) + hex.charAt(i));
1104+
}
1105+
hex = tmp.join("");
1106+
}
1107+
for (let i = 0; i < 6; i += 2) {
1108+
color[i] = "0x" + hex.substr(i, 2);
1109+
rgba.push(parseInt(Number(color[i])));
1110+
}
1111+
rgba.push(opacity);
1112+
return "rgba(" + rgba.join(",") + ")";
10891113
}
10901114
};
10911115

src/common/mapping/WebMapV2.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const INTERNET_MAP_BOUNDS = {
1717
BING: [-180, -90, 180, 90]
1818
}
1919

20-
export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
20+
export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, DataFlowService, GraticuleLayer }) {
2121
return class WebMapV2 extends SuperClass {
2222
constructor(
2323
id,
@@ -537,7 +537,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
537537

538538
_initGraticuleLayer(graticuleInfo) {
539539
const options = this._createGraticuleOptions(graticuleInfo);
540-
const graticuleLayer = new mapRepo.supermap.GraticuleLayer(options);
540+
const graticuleLayer = new GraticuleLayer(options);
541541
this._setGraticuleDash(options.strokeStyle, graticuleLayer);
542542
this._graticuleLayer = graticuleLayer;
543543
this.map.addLayer(graticuleLayer);
@@ -950,7 +950,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
950950
}
951951

952952
_createDataflowLayer(layerInfo) {
953-
const dataflowService = new mapRepo.supermap.DataFlowService(layerInfo.wsUrl).initSubscribe();
953+
const dataflowService = new DataFlowService(layerInfo.wsUrl).initSubscribe();
954954
this._handleDataflowFeaturesCallback = this._handleDataflowFeatures.bind(this, layerInfo);
955955
this._initDataflowLayerCallback = this._initDataflowLayer.bind(this, layerInfo);
956956
dataflowService.on('subscribesucceeded', this._initDataflowLayerCallback);
@@ -2179,10 +2179,10 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
21792179
layerOption.gradient.forEach((item, index) => {
21802180
color.push(step[index]);
21812181
if (index === 0) {
2182-
item = mapRepo.supermap.Util.hexToRgba(item, 0);
2182+
item = Util.hexToRgba(item, 0);
21832183
}
21842184
if (index === 1) {
2185-
item = mapRepo.supermap.Util.hexToRgba(item, 0.5);
2185+
item = Util.hexToRgba(item, 0.5);
21862186
}
21872187
color.push(item);
21882188
});

src/mapboxgl/mapping/WebMap.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { featureFilter, expression } from '@mapbox/mapbox-gl-style-spec';
1010
import spec from '@mapbox/mapbox-gl-style-spec/reference/v8';
1111
import { L7Layer, L7 } from '../overlay/L7Layer';
1212
import MapManager from './webmap/MapManager';
13+
import { DataFlowService } from '../services/DataFlowService';
14+
import { GraticuleLayer } from '../overlay/GraticuleLayer';
1315

1416
/**
1517
* @class WebMap
@@ -71,7 +73,7 @@ import MapManager from './webmap/MapManager';
7173
*/
7274
export class WebMap extends createWebMapBaseExtending(mapboxgl.Evented, { mapRepo: mapboxgl }) {
7375
_createWebMapFactory(type) {
74-
const commonFactoryOptions = { MapManager, mapRepo: mapboxgl, mapRepoName: 'mapbox-gl' };
76+
const commonFactoryOptions = { MapManager, mapRepo: mapboxgl, mapRepoName: 'mapbox-gl', DataFlowService, GraticuleLayer };
7577
const l7LayerUtil = L7LayerUtil({ featureFilter, expression, spec, L7Layer, L7, proj4: this.options.proj4 });
7678
switch (type) {
7779
case 'MapStyle':

src/maplibregl/mapping/WebMap.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { featureFilter, expression } from '@maplibre/maplibre-gl-style-spec';
1010
import spec from '@maplibre/maplibre-gl-style-spec/src/reference/v8';
1111
import { L7Layer, L7 } from '../overlay/L7Layer';
1212
import MapManager from './webmap/MapManager';
13+
import { DataFlowService } from '../services/DataFlowService';
14+
import { GraticuleLayer } from '../overlay/GraticuleLayer';
1315

1416
/**
1517
* @class WebMap
@@ -71,7 +73,7 @@ import MapManager from './webmap/MapManager';
7173
*/
7274
export class WebMap extends createWebMapBaseExtending(maplibregl.Evented, { mapRepo: maplibregl }) {
7375
_createWebMapFactory(type) {
74-
const commonFactoryOptions = { MapManager, mapRepo: maplibregl, mapRepoName: 'maplibre-gl' };
76+
const commonFactoryOptions = { MapManager, mapRepo: maplibregl, mapRepoName: 'maplibre-gl', DataFlowService, GraticuleLayer };
7577
const l7LayerUtil = L7LayerUtil({ featureFilter, expression, spec, L7Layer, L7, proj4: this.options.proj4 });
7678
switch (type) {
7779
case 'MapStyle':

test/mapboxgl/mapping/WebMapV2Spec.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { WebMap } from '../../../src/mapboxgl/mapping/WebMap';
44
import * as MapManagerUtil from '../../../src/mapboxgl/mapping/webmap/MapManager';
55
import { ArrayStatistic } from '@supermapgis/iclient-common/util/ArrayStatistic';
66
import { FetchRequest } from '@supermapgis/iclient-common/util/FetchRequest';
7+
import * as DataFlowServiceUtil from '../../../src/mapboxgl/services/DataFlowService';
78
import '../../resources/WebMapV5.js';
89

910
function DataFlowService(serviceUrl) {
@@ -189,8 +190,10 @@ describe('mapboxgl_WebMapV2', () => {
189190
getNorth: () => -1
190191
}
191192
};
193+
var dataFlowServiceSpyTest;
192194
beforeEach(() => {
193195
spyOn(MapManagerUtil, 'default').and.callFake(mbglmap);
196+
dataFlowServiceSpyTest = spyOn(DataFlowServiceUtil, 'DataFlowService').and.callFake(DataFlowService);
194197
mapboxgl.CRS = CRS;
195198
commonMap = {
196199
style: {},
@@ -344,6 +347,7 @@ describe('mapboxgl_WebMapV2', () => {
344347
window.canvg = undefined;
345348
window.geostats = undefined;
346349
window.EchartsLayer = undefined;
350+
dataFlowServiceSpyTest = null;
347351
});
348352

349353
xit('_setCRS', (done) => {
@@ -1254,12 +1258,11 @@ describe('mapboxgl_WebMapV2', () => {
12541258
}
12551259
return Promise.resolve();
12561260
});
1257-
const spyTest = spyOn(mapboxgl.supermap, 'DataFlowService').and.callFake(DataFlowService);
12581261
datavizWebmap = new WebMap(dataflowLayer, { ...commonOption, map: commonMap }, undefined);
12591262
const callback = function (data) {
12601263
if (data.allLoaded) {
12611264
const appreciableLayers = datavizWebmap.getLayers();
1262-
expect(spyTest.calls.count()).toBe(dataflowLayer.layers.length);
1265+
expect(dataFlowServiceSpyTest.calls.count()).toBe(dataflowLayer.layers.length);
12631266
expect(appreciableLayers.length).toBe(dataflowLayer.layers.length + 1);
12641267
const updateLayer = { ...dataflowLayer.layers[2], id: appreciableLayers[3].renderLayers[0] };
12651268
datavizWebmap.updateOverlayLayer(updateLayer);

test/maplibregl/mapping/WebMapV2Spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { WebMap } from '../../../src/maplibregl/mapping/WebMap';
44
import * as MapManagerUtil from '../../../src/maplibregl/mapping/webmap/MapManager';
55
import { ArrayStatistic } from '@supermapgis/iclient-common/util/ArrayStatistic';
66
import { FetchRequest } from '@supermapgis/iclient-common/util/FetchRequest';
7+
import * as DataFlowServiceUtil from '../../../src/maplibregl/services/DataFlowService';
78
import '../../resources/WebMapV5.js';
89

910
function DataFlowService(serviceUrl) {
@@ -189,8 +190,10 @@ describe('maplibregl_WebMapV2', () => {
189190
getNorth: () => -1
190191
}
191192
};
193+
var dataFlowServiceSpyTest;
192194
beforeEach(() => {
193195
spyOn(MapManagerUtil, 'default').and.callFake(mbglmap);
196+
dataFlowServiceSpyTest = spyOn(DataFlowServiceUtil, 'DataFlowService').and.callFake(DataFlowService);
194197
maplibregl.CRS = CRS;
195198
commonMap = {
196199
style: {},
@@ -1193,12 +1196,11 @@ describe('maplibregl_WebMapV2', () => {
11931196
}
11941197
return Promise.resolve();
11951198
});
1196-
const spyTest = spyOn(maplibregl.supermap, 'DataFlowService').and.callFake(DataFlowService);
11971199
datavizWebmap = new WebMap(dataflowLayer, { ...commonOption, map: commonMap }, undefined);
11981200
const callback = function (data) {
11991201
if (data.allLoaded) {
12001202
const appreciableLayers = datavizWebmap.getLayers();
1201-
expect(spyTest.calls.count()).toBe(dataflowLayer.layers.length);
1203+
expect(dataFlowServiceSpyTest.calls.count()).toBe(dataflowLayer.layers.length);
12021204
expect(appreciableLayers.length).toBe(dataflowLayer.layers.length + 1);
12031205
const updateLayer = { ...dataflowLayer.layers[2], id: appreciableLayers[3].renderLayers[0] };
12041206
datavizWebmap.updateOverlayLayer(updateLayer);

0 commit comments

Comments
 (0)