Skip to content

Commit 7c23bec

Browse files
committed
【fix】webmapv3 非常规投影时,proj4未注册,l7layer转坐标出错
1 parent 5801ebb commit 7c23bec

File tree

3 files changed

+306
-1
lines changed

3 files changed

+306
-1
lines changed

src/mapboxgl/mapping/webmap/v3/WebMap.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import mapboxgl from 'mapbox-gl';
55
import { FetchRequest } from '@supermapgis/iclient-common/util/FetchRequest';
66
import { Util } from '../../../core/Util';
77
import { addL7Layers, getL7MarkerLayers, isL7Layer } from '../../utils/L7LayerUtil';
8+
import proj4 from 'proj4';
89

910
const LEGEND_RENDER_TYPE = {
1011
TEXT: 'TEXT',
@@ -383,6 +384,9 @@ export class WebMap extends mapboxgl.Evented {
383384
_setCRS({ name, wkt, extent }) {
384385
const crs = new mapboxgl.CRS(name, wkt, extent, extent[2] > 180 ? 'meter' : 'degree');
385386
mapboxgl.CRS.set(crs);
387+
if (!proj4.defs(name)) {
388+
proj4.defs(name, wkt);
389+
}
386390
}
387391

388392
/**

test/mapboxgl/mapping/WebMapV3Spec.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { FetchRequest } from '@supermapgis/iclient-common/util/FetchRequest';
66
import * as L7 from '../../../src/mapboxgl/overlay/L7/l7-render';
77
import * as mockL7 from '../../tool/mock_l7';
88
import mbglmap from '../../tool/mock_mapboxgl_map';
9+
import proj4 from 'proj4';
910

1011
describe('mapboxgl-webmap3.0', () => {
1112
var originalTimeout, testDiv;
@@ -981,4 +982,47 @@ describe('mapboxgl-webmap3.0', () => {
981982
done();
982983
});
983984
});
985+
986+
it('when projection is unconventional projection', (done) => {
987+
const mapInfo = JSON.parse(mapstudio_multiProjection);
988+
spyOn(L7, 'HeatmapLayer').and.callFake(mockL7.PointLayer);
989+
spyOn(L7, 'Scene').and.callFake(mockL7.Scene);
990+
spyOn(L7, 'Mapbox').and.callFake(mockL7.Mapbox);
991+
mapboxgl.Map.prototype.getCRS = function () {
992+
return { epsgCode: mapInfo.crs.name, getExtent: () => {} };
993+
};
994+
spyOn(FetchRequest, 'get').and.callFake((url) => {
995+
if (url.indexOf('map.json') > -1) {
996+
return Promise.resolve(new Response(mapstudio_multiProjection));
997+
}
998+
if (url.indexOf('617580084.json') > -1) {
999+
return Promise.resolve(new Response(msProjectINfo_multiProjection));
1000+
}
1001+
if (url.indexOf('/sprite') > -1) {
1002+
return Promise.resolve(new Response(msSpriteInfo));
1003+
}
1004+
if (url.indexOf('/web/datas/962426788/structureddata/ogc-features/collections/all/items.json') > -1) {
1005+
return Promise.resolve(new Response(l7StructureData962426788Items));
1006+
}
1007+
if (url.indexOf('/web/datas/962426788/structureddata.json') > -1) {
1008+
return Promise.resolve(new Response(l7StructureData962426788));
1009+
}
1010+
return Promise.resolve();
1011+
});
1012+
mapboxgl.CRS = function () {};
1013+
mapboxgl.CRS.set = function () {};
1014+
expect(proj4.defs(mapInfo.crs.name)).toBeUndefined();
1015+
mapstudioWebmap = new WebMap(id, {
1016+
server: server
1017+
});
1018+
mapstudioWebmap.on('addlayerssucceeded', ({ map }) => {
1019+
const webmapInstance = mapstudioWebmap._getWebMapInstance();
1020+
expect(map).not.toBeUndefined();
1021+
expect(webmapInstance.map).toEqual(map);
1022+
expect(proj4.defs(mapInfo.crs.name)).not.toBeUndefined();
1023+
delete mapboxgl.Map.prototype.getCRS;
1024+
delete mapboxgl.CRS;
1025+
done();
1026+
});
1027+
});
9841028
});

test/resources/WebMapV3.js

Lines changed: 258 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2107,7 +2107,7 @@ var apstudioWebMap_layerData = JSON.stringify({
21072107
center: [116.39560889343761, 39.939177386003514],
21082108
zoom: 9.789811175067591,
21092109
glyphs: {
2110-
"ms_M_3857_1719917169016_4": "http://172.16.14.44:8090/iserver/services/map-multi0508/rest/maps/M_3857/tileFeature/sdffonts/{fontstack}/{range}.pbf"
2110+
"ms_M_3857_1719917169016_4": "http://localhost:8090/iserver/services/map-multi0508/rest/maps/M_3857/tileFeature/sdffonts/{fontstack}/{range}.pbf"
21112111
},
21122112
version: '3.2.1',
21132113
rootUrl: 'http://localhost:8190/iportal/',
@@ -2864,3 +2864,260 @@ var mapstudioWebMap_group = JSON.stringify({
28642864
pitch: 0,
28652865
minzoom: 0
28662866
});
2867+
2868+
var mapstudio_multiProjection = JSON.stringify({
2869+
metadata: {
2870+
layerCatalog: [
2871+
{
2872+
visible: true,
2873+
id: 'NewPoint4548',
2874+
title: 'NewPoint4548',
2875+
type: 'basic'
2876+
},
2877+
{
2878+
visible: true,
2879+
id: 'ms-background',
2880+
title: '纯色底图',
2881+
type: 'basic'
2882+
}
2883+
]
2884+
},
2885+
sources: {
2886+
ms_aggregation_962426788_1724056440862_23: {
2887+
cluster: true,
2888+
clusterType: 'grid',
2889+
clusterMethod: 'avg',
2890+
data: {
2891+
dataId: '962426788',
2892+
type: 'supermap-structured-data'
2893+
},
2894+
type: 'geojson',
2895+
clusterField: 'smpid',
2896+
clusterRadius: 900000
2897+
}
2898+
},
2899+
crs: {
2900+
extent: [345754.3017317925, 2500241.087997996, 3374092.172217019, 5528578.958483222],
2901+
wkt: 'PROJCS["CGCS2000 / 3-degree Gauss-Kruger CM 117E",GEOGCS["China Geodetic Coordinate System 2000",DATUM["China_2000",SPHEROID["CGCS2000",6378137,298.257222101,AUTHORITY["EPSG","1024"]],AUTHORITY["EPSG","1043"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4490"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",117],PARAMETER["scale_factor",1],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],AXIS["Northing", "NORTH"],AXIS["Easting", "EAST"],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AUTHORITY["EPSG","4548"]]',
2902+
name: 'EPSG:4548'
2903+
},
2904+
center: [133.2673120035025, 32.94911515042364],
2905+
zoom: 0.5203223527391135,
2906+
glyphs: {},
2907+
version: '3.2.2',
2908+
rootUrl: 'http://localhost:8190/iportal/',
2909+
maxzoom: 12,
2910+
name: '2343-ms',
2911+
viewExtent: [114.85431014925224, 20.37423487607389, 152.81962894145246, 49.86984527494917],
2912+
layers: [
2913+
{
2914+
paint: {
2915+
'background-color': 'rgba(14,14,14,1)'
2916+
},
2917+
id: 'ms-background',
2918+
type: 'background'
2919+
},
2920+
{
2921+
layout: {
2922+
'heatmap-coverage': 1,
2923+
visibility: 'visible',
2924+
'heatmap-rotate': 0,
2925+
'heatmap-shape': 'square'
2926+
},
2927+
metadata: {
2928+
MapStudio: {
2929+
title: 'NewPoint4548'
2930+
}
2931+
},
2932+
maxzoom: 24,
2933+
paint: {
2934+
'heatmap-color': '#EE4D5A',
2935+
'heatmap-opacity': 0.9
2936+
},
2937+
source: 'ms_aggregation_962426788_1724056440862_23',
2938+
id: 'NewPoint4548',
2939+
type: 'heatmap',
2940+
minzoom: 0
2941+
}
2942+
],
2943+
pitch: 37.00000000000002,
2944+
minzoom: 0
2945+
});
2946+
2947+
var msProjectINfo_multiProjection = JSON.stringify({
2948+
extent: null,
2949+
controls: null,
2950+
extentString: '',
2951+
description: '',
2952+
verifyReason: null,
2953+
units: null,
2954+
title: '2343-ms',
2955+
resolution: 0,
2956+
checkStatus: 'SUCCESSFUL',
2957+
projectInfo:
2958+
'{"catalogs":[{"visualization":{"renderer":{"coverage":{"type":"simple","value":1},"color":{"type":"simple","value":"#EE4D5A"},"angle":{"type":"simple","value":0},"opacity":{"type":"simple","value":0.9},"type":"heatGrid","styleRenderMode":"antvL7"}},"visible":true,"catalogType":"layer","labelsContent":[],"source":{"option":{"clusterOption":{"aggType":"AVG","aggField":"smpid","groupBy":{"aggCellSize":900000,"aggCellUnit":"PX"}},"cluster":true}},"title":"NewPoint4548","layerSourceType":"Data","zoomRange":[0,24],"layersContent":[],"msDatasetId":"ms_datasetId_1724056435204_20","bounds":[116.80751966064098,24.657602137018205,117.60524238203818,42.48026915788759],"id":"NewPoint4548","popupInfo":{"elements":[{"fieldName":"smpid","type":"FIELD"},{"fieldName":"num","type":"FIELD"},{"fieldName":"SmUserID","type":"FIELD"},{"fieldName":"name","type":"FIELD"},{"fieldName":"geometry","type":"FIELD"}],"title":"NewPoint4548"}}],"datas":[{"sourceType":"STRUCTURE_DATA","datasets":[{"datasetTitle":"NewPoint4548","msDatasetId":"ms_datasetId_1724056435204_20","datasetId":"962426788","geometryField":"geometry"}],"title":"NewPoint4548"}],"baseLayer":{"color":"rgba(14,14,14,1)","projection":"EPSG:4548","type":"BACKGROUND"},"version":"3.0.4"}',
2959+
visitCount: 73,
2960+
centerString: '{"x":133.2673120035025,"y":32.94911515042364}',
2961+
epsgCode: 4548,
2962+
nickname: 'admin_123',
2963+
layers: [],
2964+
id: 473422324,
2965+
thumbnail: 'http://localhost:8190/iportal/resources/thumbnail/map/map473422324.png',
2966+
level: 0,
2967+
center: {
2968+
x: 133.2673120035025,
2969+
y: 32.94911515042364
2970+
}
2971+
});
2972+
2973+
var l7StructureData962426788Items = JSON.stringify({
2974+
timeStamp: '2024-09-24T05:42:46Z',
2975+
features: [
2976+
{
2977+
geometry: {
2978+
coordinates: [507276.4742796922, 4705161.709043069],
2979+
type: 'Point'
2980+
},
2981+
id: '1',
2982+
type: 'Feature',
2983+
properties: {
2984+
smpid: 1,
2985+
num: 1,
2986+
name: 1,
2987+
SmUserID: 0
2988+
}
2989+
},
2990+
{
2991+
geometry: {
2992+
coordinates: [515356.3470900338, 4438766.589724715],
2993+
type: 'Point'
2994+
},
2995+
id: '2',
2996+
type: 'Feature',
2997+
properties: {
2998+
smpid: 2,
2999+
num: 2,
3000+
name: 2,
3001+
SmUserID: 0
3002+
}
3003+
},
3004+
{
3005+
geometry: {
3006+
coordinates: [549766.0475474435, 4032304.717571498],
3007+
type: 'Point'
3008+
},
3009+
id: '3',
3010+
type: 'Feature',
3011+
properties: {
3012+
smpid: 3,
3013+
num: 3,
3014+
name: 3,
3015+
SmUserID: 0
3016+
}
3017+
},
3018+
{
3019+
geometry: {
3020+
coordinates: [497691.9905545708, 3794406.293987407],
3021+
type: 'Point'
3022+
},
3023+
id: '4',
3024+
type: 'Feature',
3025+
properties: {
3026+
smpid: 4,
3027+
num: 4,
3028+
name: 4,
3029+
SmUserID: 0
3030+
}
3031+
},
3032+
{
3033+
geometry: {
3034+
coordinates: [480515.5660373094, 3439828.3757625716],
3035+
type: 'Point'
3036+
},
3037+
id: '5',
3038+
type: 'Feature',
3039+
properties: {
3040+
smpid: 5,
3041+
num: 5,
3042+
name: 5,
3043+
SmUserID: 0
3044+
}
3045+
},
3046+
{
3047+
geometry: {
3048+
coordinates: [504696.1104849293, 2999163.261754166],
3049+
type: 'Point'
3050+
},
3051+
id: '6',
3052+
type: 'Feature',
3053+
properties: {
3054+
smpid: 6,
3055+
num: 6,
3056+
name: 6,
3057+
SmUserID: 0
3058+
}
3059+
},
3060+
{
3061+
geometry: {
3062+
coordinates: [480819.0020892108, 2728140.293486495],
3063+
type: 'Point'
3064+
},
3065+
id: '7',
3066+
type: 'Feature',
3067+
properties: {
3068+
smpid: 7,
3069+
num: 7,
3070+
name: 7,
3071+
SmUserID: 0
3072+
}
3073+
}
3074+
],
3075+
numberReturned: 7,
3076+
links: [
3077+
{
3078+
rel: 'self',
3079+
href: 'http://172.16.14.44:8190/iportal/web/datas/962426788/structureddata/ogc-features/collections/all/items.json',
3080+
type: 'application/geo+json',
3081+
title: 'this document'
3082+
}
3083+
],
3084+
numberMatched: 7,
3085+
type: 'FeatureCollection'
3086+
});
3087+
3088+
var l7StructureData962426788 = JSON.stringify({
3089+
extent: {
3090+
top: 4705161.709043069,
3091+
left: 480515.5660373094,
3092+
bottom: 2728140.293486495,
3093+
leftBottom: {
3094+
x: 480515.5660373094,
3095+
y: 2728140.293486495
3096+
},
3097+
right: 549766.0475474435,
3098+
rightTop: {
3099+
x: 549766.0475474435,
3100+
y: 4705161.709043069
3101+
}
3102+
},
3103+
firstRowIsHead: false,
3104+
fileEncoding: null,
3105+
fieldNames: ['smpid', 'num', 'SmUserID', 'name', 'geometry'],
3106+
type: 'json',
3107+
separator: null,
3108+
tableName: 'smp962426788_newpoint4548',
3109+
urn: 'urn:supermapabc:since-1.0:bigdata:_defaulthost:962426788',
3110+
epsgCode: 4548,
3111+
fieldTypes: ['INT', 'LONG', 'LONG', 'LONG', 'POINT'],
3112+
name: 'NewPoint4548',
3113+
tableFieldNames: ['smpid', 'num', 'smuserid', 'name', 'geometry'],
3114+
links: [
3115+
{
3116+
rel: null,
3117+
href: 'http://172.16.14.44:8190/iportal/analytics',
3118+
type: 'ANALYTICS_SERVICE',
3119+
title: null
3120+
}
3121+
],
3122+
id: '962426788'
3123+
});

0 commit comments

Comments
 (0)