| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3044618 commit 2de4f48
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1086,6 +1086,30 @@ const Util = { | |||
| 1086 | 1086 | } | |
| 1087 | 1087 | return encodeURIComponent(value); | |
| 1088 | 1088 | }); | |
| 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(",") + ")"; | ||
| 1089 | 1113 | } | |
| 1090 | 1114 | }; | |
| 1091 | 1115 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,7 +17,7 @@ const INTERNET_MAP_BOUNDS = { | |||
| 17 | 17 | BING: [-180, -90, 180, 90] | |
| 18 | 18 | } | |
| 19 | 19 | ||
| 20 | - export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) { | ||
| 20 | + export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, DataFlowService, GraticuleLayer }) { | ||
| 21 | 21 | return class WebMapV2 extends SuperClass { | |
| 22 | 22 | constructor( | |
| 23 | 23 | id, | |
@@ -537,7 +537,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) { | |||
| 537 | 537 | ||
| 538 | 538 | _initGraticuleLayer(graticuleInfo) { | |
| 539 | 539 | const options = this._createGraticuleOptions(graticuleInfo); | |
| 540 | - const graticuleLayer = new mapRepo.supermap.GraticuleLayer(options); | ||
| 540 | + const graticuleLayer = new GraticuleLayer(options); | ||
| 541 | 541 | this._setGraticuleDash(options.strokeStyle, graticuleLayer); | |
| 542 | 542 | this._graticuleLayer = graticuleLayer; | |
| 543 | 543 | this.map.addLayer(graticuleLayer); | |
@@ -950,7 +950,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) { | |||
| 950 | 950 | } | |
| 951 | 951 | ||
| 952 | 952 | _createDataflowLayer(layerInfo) { | |
| 953 | - const dataflowService = new mapRepo.supermap.DataFlowService(layerInfo.wsUrl).initSubscribe(); | ||
| 953 | + const dataflowService = new DataFlowService(layerInfo.wsUrl).initSubscribe(); | ||
| 954 | 954 | this._handleDataflowFeaturesCallback = this._handleDataflowFeatures.bind(this, layerInfo); | |
| 955 | 955 | this._initDataflowLayerCallback = this._initDataflowLayer.bind(this, layerInfo); | |
| 956 | 956 | dataflowService.on('subscribesucceeded', this._initDataflowLayerCallback); | |
@@ -2179,10 +2179,10 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) { | |||
| 2179 | 2179 | layerOption.gradient.forEach((item, index) => { | |
| 2180 | 2180 | color.push(step[index]); | |
| 2181 | 2181 | if (index === 0) { | |
| 2182 | - item = mapRepo.supermap.Util.hexToRgba(item, 0); | ||
| 2182 | + item = Util.hexToRgba(item, 0); | ||
| 2183 | 2183 | } | |
| 2184 | 2184 | if (index === 1) { | |
| 2185 | - item = mapRepo.supermap.Util.hexToRgba(item, 0.5); | ||
| 2185 | + item = Util.hexToRgba(item, 0.5); | ||
| 2186 | 2186 | } | |
| 2187 | 2187 | color.push(item); | |
| 2188 | 2188 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,8 @@ import { featureFilter, expression } from '@mapbox/mapbox-gl-style-spec'; | |||
| 10 | 10 | import spec from '@mapbox/mapbox-gl-style-spec/reference/v8'; | |
| 11 | 11 | import { L7Layer, L7 } from '../overlay/L7Layer'; | |
| 12 | 12 | import MapManager from './webmap/MapManager'; | |
| 13 | + import { DataFlowService } from '../services/DataFlowService'; | ||
| 14 | + import { GraticuleLayer } from '../overlay/GraticuleLayer'; | ||
| 13 | 15 | ||
| 14 | 16 | /** | |
| 15 | 17 | * @class WebMap | |
@@ -71,7 +73,7 @@ import MapManager from './webmap/MapManager'; | |||
| 71 | 73 | */ | |
| 72 | 74 | export class WebMap extends createWebMapBaseExtending(mapboxgl.Evented, { mapRepo: mapboxgl }) { | |
| 73 | 75 | _createWebMapFactory(type) { | |
| 74 | - const commonFactoryOptions = { MapManager, mapRepo: mapboxgl, mapRepoName: 'mapbox-gl' }; | ||
| 76 | + const commonFactoryOptions = { MapManager, mapRepo: mapboxgl, mapRepoName: 'mapbox-gl', DataFlowService, GraticuleLayer }; | ||
| 75 | 77 | const l7LayerUtil = L7LayerUtil({ featureFilter, expression, spec, L7Layer, L7, proj4: this.options.proj4 }); | |
| 76 | 78 | switch (type) { | |
| 77 | 79 | case 'MapStyle': | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,8 @@ import { featureFilter, expression } from '@maplibre/maplibre-gl-style-spec'; | |||
| 10 | 10 | import spec from '@maplibre/maplibre-gl-style-spec/src/reference/v8'; | |
| 11 | 11 | import { L7Layer, L7 } from '../overlay/L7Layer'; | |
| 12 | 12 | import MapManager from './webmap/MapManager'; | |
| 13 | + import { DataFlowService } from '../services/DataFlowService'; | ||
| 14 | + import { GraticuleLayer } from '../overlay/GraticuleLayer'; | ||
| 13 | 15 | ||
| 14 | 16 | /** | |
| 15 | 17 | * @class WebMap | |
@@ -71,7 +73,7 @@ import MapManager from './webmap/MapManager'; | |||
| 71 | 73 | */ | |
| 72 | 74 | export class WebMap extends createWebMapBaseExtending(maplibregl.Evented, { mapRepo: maplibregl }) { | |
| 73 | 75 | _createWebMapFactory(type) { | |
| 74 | - const commonFactoryOptions = { MapManager, mapRepo: maplibregl, mapRepoName: 'maplibre-gl' }; | ||
| 76 | + const commonFactoryOptions = { MapManager, mapRepo: maplibregl, mapRepoName: 'maplibre-gl', DataFlowService, GraticuleLayer }; | ||
| 75 | 77 | const l7LayerUtil = L7LayerUtil({ featureFilter, expression, spec, L7Layer, L7, proj4: this.options.proj4 }); | |
| 76 | 78 | switch (type) { | |
| 77 | 79 | case 'MapStyle': | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,7 @@ import { WebMap } from '../../../src/mapboxgl/mapping/WebMap'; | |||
| 4 | 4 | import * as MapManagerUtil from '../../../src/mapboxgl/mapping/webmap/MapManager'; | |
| 5 | 5 | import { ArrayStatistic } from '@supermapgis/iclient-common/util/ArrayStatistic'; | |
| 6 | 6 | import { FetchRequest } from '@supermapgis/iclient-common/util/FetchRequest'; | |
| 7 | + import * as DataFlowServiceUtil from '../../../src/mapboxgl/services/DataFlowService'; | ||
| 7 | 8 | import '../../resources/WebMapV5.js'; | |
| 8 | 9 | ||
| 9 | 10 | function DataFlowService(serviceUrl) { | |
@@ -189,8 +190,10 @@ describe('mapboxgl_WebMapV2', () => { | |||
| 189 | 190 | getNorth: () => -1 | |
| 190 | 191 | } | |
| 191 | 192 | }; | |
| 193 | + var dataFlowServiceSpyTest; | ||
| 192 | 194 | beforeEach(() => { | |
| 193 | 195 | spyOn(MapManagerUtil, 'default').and.callFake(mbglmap); | |
| 196 | + dataFlowServiceSpyTest = spyOn(DataFlowServiceUtil, 'DataFlowService').and.callFake(DataFlowService); | ||
| 194 | 197 | mapboxgl.CRS = CRS; | |
| 195 | 198 | commonMap = { | |
| 196 | 199 | style: {}, | |
@@ -344,6 +347,7 @@ describe('mapboxgl_WebMapV2', () => { | |||
| 344 | 347 | window.canvg = undefined; | |
| 345 | 348 | window.geostats = undefined; | |
| 346 | 349 | window.EchartsLayer = undefined; | |
| 350 | + dataFlowServiceSpyTest = null; | ||
| 347 | 351 | }); | |
| 348 | 352 | ||
| 349 | 353 | xit('_setCRS', (done) => { | |
@@ -1254,12 +1258,11 @@ describe('mapboxgl_WebMapV2', () => { | |||
| 1254 | 1258 | } | |
| 1255 | 1259 | return Promise.resolve(); | |
| 1256 | 1260 | }); | |
| 1257 | - const spyTest = spyOn(mapboxgl.supermap, 'DataFlowService').and.callFake(DataFlowService); | ||
| 1258 | 1261 | datavizWebmap = new WebMap(dataflowLayer, { ...commonOption, map: commonMap }, undefined); | |
| 1259 | 1262 | const callback = function (data) { | |
| 1260 | 1263 | if (data.allLoaded) { | |
| 1261 | 1264 | const appreciableLayers = datavizWebmap.getLayers(); | |
| 1262 | - expect(spyTest.calls.count()).toBe(dataflowLayer.layers.length); | ||
| 1265 | + expect(dataFlowServiceSpyTest.calls.count()).toBe(dataflowLayer.layers.length); | ||
| 1263 | 1266 | expect(appreciableLayers.length).toBe(dataflowLayer.layers.length + 1); | |
| 1264 | 1267 | const updateLayer = { ...dataflowLayer.layers[2], id: appreciableLayers[3].renderLayers[0] }; | |
| 1265 | 1268 | datavizWebmap.updateOverlayLayer(updateLayer); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,7 @@ import { WebMap } from '../../../src/maplibregl/mapping/WebMap'; | |||
| 4 | 4 | import * as MapManagerUtil from '../../../src/maplibregl/mapping/webmap/MapManager'; | |
| 5 | 5 | import { ArrayStatistic } from '@supermapgis/iclient-common/util/ArrayStatistic'; | |
| 6 | 6 | import { FetchRequest } from '@supermapgis/iclient-common/util/FetchRequest'; | |
| 7 | + import * as DataFlowServiceUtil from '../../../src/maplibregl/services/DataFlowService'; | ||
| 7 | 8 | import '../../resources/WebMapV5.js'; | |
| 8 | 9 | ||
| 9 | 10 | function DataFlowService(serviceUrl) { | |
@@ -189,8 +190,10 @@ describe('maplibregl_WebMapV2', () => { | |||
| 189 | 190 | getNorth: () => -1 | |
| 190 | 191 | } | |
| 191 | 192 | }; | |
| 193 | + var dataFlowServiceSpyTest; | ||
| 192 | 194 | beforeEach(() => { | |
| 193 | 195 | spyOn(MapManagerUtil, 'default').and.callFake(mbglmap); | |
| 196 | + dataFlowServiceSpyTest = spyOn(DataFlowServiceUtil, 'DataFlowService').and.callFake(DataFlowService); | ||
| 194 | 197 | maplibregl.CRS = CRS; | |
| 195 | 198 | commonMap = { | |
| 196 | 199 | style: {}, | |
@@ -1193,12 +1196,11 @@ describe('maplibregl_WebMapV2', () => { | |||
| 1193 | 1196 | } | |
| 1194 | 1197 | return Promise.resolve(); | |
| 1195 | 1198 | }); | |
| 1196 | - const spyTest = spyOn(maplibregl.supermap, 'DataFlowService').and.callFake(DataFlowService); | ||
| 1197 | 1199 | datavizWebmap = new WebMap(dataflowLayer, { ...commonOption, map: commonMap }, undefined); | |
| 1198 | 1200 | const callback = function (data) { | |
| 1199 | 1201 | if (data.allLoaded) { | |
| 1200 | 1202 | const appreciableLayers = datavizWebmap.getLayers(); | |
| 1201 | - expect(spyTest.calls.count()).toBe(dataflowLayer.layers.length); | ||
| 1203 | + expect(dataFlowServiceSpyTest.calls.count()).toBe(dataflowLayer.layers.length); | ||
| 1202 | 1204 | expect(appreciableLayers.length).toBe(dataflowLayer.layers.length + 1); | |
| 1203 | 1205 | const updateLayer = { ...dataflowLayer.layers[2], id: appreciableLayers[3].renderLayers[0] }; | |
| 1204 | 1206 | datavizWebmap.updateOverlayLayer(updateLayer); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments