Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9923979

Browse files
[fix]ISVJ-9831
1 parent e4a804c commit 9923979

File tree

5 files changed

+121
-24
lines changed

5 files changed

+121
-24
lines changed

‎src/common/mapping/WebMapV2.js

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
130130
extent: [extent.leftBottom.x, extent.leftBottom.y, extent.rightTop.x, extent.rightTop.y],
131131
wkt: this._getProjectionWKT(projection)
132132
};
133-
if (!crsManager.getCRS(epsgCode)&&baseLayer.layerType!=='ZXY_TILE') {
133+
if (!crsManager.getCRS(epsgCode)) {
134134
switch (baseLayer.layerType) {
135135
case 'MAPBOXSTYLE': {
136136
let url = baseLayer.dataSource.url;
@@ -165,6 +165,11 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
165165
}
166166
break;
167167
}
168+
case 'ZXY_TILE': {
169+
const extent = this._getZXYTileCrsExtent(baseLayer);
170+
crs.extent = extent;
171+
break;
172+
}
168173
default:
169174
crs = null;
170175
break;
@@ -240,14 +245,20 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
240245
let zoomBase = 0;
241246
let { bounds, minZoom, maxZoom } = this.mapOptions;
242247
const interactive = this.mapOptions.interactive;
248+
const tileSize = mapInfo.baseLayer.tileSize;
249+
250+
if (mapInfo.baseLayer.layerType === 'ZXY_TILE') {
251+
const {leftBottom, rightTop} = mapInfo.extent;
252+
mapInfo.visibleExtent = [leftBottom.x, leftBottom.y, rightTop.x, rightTop.y];
253+
}
243254
if (isNaN(minZoom)) {
244255
minZoom = mapInfo.minScale
245-
? this._transformScaleToZoom(mapInfo.minScale, mapRepo.CRS.get(this.baseProjection))
256+
? this._transformScaleToZoom(mapInfo.minScale, mapRepo.CRS.get(this.baseProjection),tileSize)
246257
: 0;
247258
}
248259
if (isNaN(maxZoom)) {
249260
maxZoom = mapInfo.maxScale
250-
? this._transformScaleToZoom(mapInfo.maxScale, mapRepo.CRS.get(this.baseProjection))
261+
? this._transformScaleToZoom(mapInfo.maxScale, mapRepo.CRS.get(this.baseProjection),tileSize)
251262
: 22;
252263
}
253264
if (mapInfo.visibleExtent && mapInfo.visibleExtent.length === 4 && !bounds) {
@@ -262,8 +273,8 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
262273
if (!bounds) {
263274
if (mapInfo.minScale && mapInfo.maxScale) {
264275
zoomBase = Math.min(
265-
this._transformScaleToZoom(mapInfo.minScale, mapRepo.CRS.get(this.baseProjection)),
266-
this._transformScaleToZoom(mapInfo.maxScale, mapRepo.CRS.get(this.baseProjection))
276+
this._transformScaleToZoom(mapInfo.minScale, mapRepo.CRS.get(this.baseProjection),tileSize),
277+
this._transformScaleToZoom(mapInfo.maxScale, mapRepo.CRS.get(this.baseProjection),tileSize)
267278
);
268279
} else {
269280
zoomBase = +Math.log2(
@@ -433,8 +444,8 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
433444
if (layer.visibleScale) {
434445
const { minScale, maxScale } = layer.visibleScale;
435446
const crs = this.map.getCRS();
436-
layer.minzoom = Math.max(this._transformScaleToZoom(minScale, crs), 0);
437-
layer.maxzoom = Math.min(24, this._transformScaleToZoom(maxScale, crs) + 0.0000001);
447+
layer.minzoom = Math.max(this._transformScaleToZoom(minScale, crs,layer.tileSize), 0);
448+
layer.maxzoom = Math.min(24, this._transformScaleToZoom(maxScale, crs,layer.tileSize) + 0.0000001);
438449
}
439450

440451
if (type === 'tile') {
@@ -701,17 +712,26 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
701712
}
702713

703714
_createZXYLayer(layerInfo, addedCallback) {
704-
const { url, subdomains, layerID, name, visible, tileSize, resolutions, origin, minZoom: minzoom, maxZoom: maxzoom } = layerInfo;
715+
const { url, subdomains, layerID, name, visible, tileSize, resolutions, origin, minZoom: minzoom, maxZoom: maxzoom, mapBounds } = layerInfo;
705716
const urls = (subdomains && subdomains.length) ? subdomains.map(item => url.replace('{s}', item)) : [url];
706717
const layerId = layerID || name;
707718
const isSupport = this._isSupportZXYTileLayer({ resolutions, tileSize, origin });
708719
if (isSupport) {
709-
this._addBaselayer({ url: urls, layerID: layerId, visibility: visible, minzoom, maxzoom, isIserver: false, tileSize });
720+
const bounds = this._getSourceBounds(mapBounds);
721+
this._addBaselayer({ url: urls, layerID: layerId, visibility: visible, minzoom, maxzoom, bounds, isIserver: false, tileSize });
710722
} else {
711723
this.fire('xyztilelayernotsupport', { error: `The resolutions or origin of layer ${name} on XYZ Tile does not match the map`, error_code: 'XYZ_TILE_LAYER_NOT_SUPPORTED', layer: layerInfo});
712724
}
713725
addedCallback && addedCallback();
714726
}
727+
_getSourceBounds(mapBounds) {
728+
if(!mapBounds) {
729+
return;
730+
}
731+
const lb = this._unproject([mapBounds[0], mapBounds[1]]);
732+
const rt = this._unproject([mapBounds[2], mapBounds[3]]);
733+
return [...lb, ...rt];
734+
}
715735
_isSupportZXYTileLayer({ resolutions, tileSize, origin }) {
716736
const isOldWebMecartor = origin === undefined && resolutions === undefined;
717737
if (isOldWebMecartor) {
@@ -745,6 +765,18 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
745765
}
746766
return resolutions;
747767
}
768+
_getZXYTileCrsExtent(layerInfo) {
769+
const { tileSize = 256, resolutions, origin } = layerInfo;
770+
if (resolutions) {
771+
const maxResolution = resolutions.sort((a, b) => b - a)[0];
772+
const size = maxResolution * tileSize;
773+
return [origin[0], origin[1] - size, origin[0] + size, origin[1]];
774+
}
775+
// 兼容之前的3857全球剖分
776+
if (this.baseProjection == 'EPSG:3857') {
777+
return [-20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892];
778+
}
779+
}
748780

749781
_createDynamicTiledLayer(layerInfo, addedCallback) {
750782
const url = layerInfo.url;
@@ -2969,10 +3001,11 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
29693001
return Math.max(bounds[2] - bounds[0], bounds[3] - bounds[1]) / tileSize;
29703002
}
29713003

2972-
_transformScaleToZoom(scale, crs) {
3004+
_transformScaleToZoom(scale, crs, tileSize) {
3005+
tileSize = tileSize || 512
29733006
const extent = crs.getExtent();
29743007
const unit = crs.unit;
2975-
const scaleBase = 1.0 / Util.getScaleFromResolutionDpi((extent[2] - extent[0]) / 512, 96, unit);
3008+
const scaleBase = 1.0 / Util.getScaleFromResolutionDpi((extent[2] - extent[0]) / tileSize, 96, unit);
29763009
const scaleDenominator = scale.split(':')[1];
29773010
return Math.min(24, +Math.log2(scaleBase / +scaleDenominator).toFixed(2));
29783011
}

‎src/openlayers/mapping/WebMap.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ export class WebMap extends Observable {
433433
res,
434434
scale,
435435
resolutionArray = [],
436-
coordUnit = baseLayerInfo.coordUnit || olProj.get(baseLayerInfo.projection).getUnits();
436+
coordUnit = baseLayerInfo.coordUnit || baseLayerInfo.units||olProj.get(baseLayerInfo.projection).getUnits();
437437
if (!coordUnit) {
438438
coordUnit = this.baseProjection == 'EPSG:3857' ? 'm' : 'degree';
439439
}
@@ -457,6 +457,14 @@ export class WebMap extends Observable {
457457
resolutionArray.push(res);
458458
scales.push(scale);
459459
}, this);
460+
} else if(baseLayerInfo.layerType === 'ZXY_TILE') {
461+
const { resolutions: visibleResolution } = baseLayerInfo;
462+
visibleResolution.forEach(result => {
463+
const currentScale = this.getScaleFromRes(result, coordUnit);
464+
resolutions[this.formatScale(currentScale)] = result;
465+
scales.push(currentScale);
466+
})
467+
resolutionArray = visibleResolution;
460468
} else {
461469
let { minZoom = 0, maxZoom = 22 } = baseLayerInfo,
462470
view = this.map.getView();
@@ -775,9 +783,10 @@ export class WebMap extends Observable {
775783
[minZoom, maxZoom] = [maxZoom, minZoom];
776784
}
777785
if (minZoom !== 0 || maxZoom !== visibleScales.length - 1) {
786+
const oldViewOptions = this.map.getView().options_ || this.map.getView().getProperties();
778787
this.map.setView(
779788
new View(
780-
Object.assign({}, this.map.getView().options_, {
789+
Object.assign({}, oldViewOptions, {
781790
maxResolution: undefined,
782791
minResolution: undefined,
783792
minZoom,
@@ -882,7 +891,7 @@ export class WebMap extends Observable {
882891
) {
883892
//底图有固定比例尺,就直接获取。不用view计算
884893
this.getScales(baseLayer);
885-
} else if (options.baseLayer && extent && extent.length === 4) {
894+
} else if (baseLayer&&baseLayer.layerType!=="ZXY_TILE" && extent && extent.length === 4) {
886895
let width = extent[2] - extent[0];
887896
let height = extent[3] - extent[1];
888897
let maxResolution1 = width / 512;
@@ -896,7 +905,11 @@ export class WebMap extends Observable {
896905
this.map.setView(new View({ zoom, center, projection, maxZoom, maxResolution }));
897906
let viewOptions = {};
898907

899-
if (
908+
if (baseLayer.layerType === "ZXY_TILE") {
909+
const { resolutions, minZoom, maxZoom } = baseLayer;
910+
viewOptions = { minZoom, maxZoom, zoom, center, projection, resolutions};
911+
this.getScales(baseLayer);
912+
} else if (
900913
(baseLayer.scales && baseLayer.scales.length > 0 && baseLayer.layerType === 'WMTS') ||
901914
(this.resolutionArray && this.resolutionArray.length > 0)
902915
) {
@@ -1364,8 +1377,8 @@ export class WebMap extends Observable {
13641377
const { layerType, extent, minZoom, maxZoom } = layerInfo;
13651378
const extentVal = layerType === 'ZXY_TILE' ? this._getZXYTileMapBounds(layerInfo) : extent;
13661379
const options = { extent: extentVal };
1367-
if (typeof minZoom === 'number') {
1368-
options.minZoom = minZoom;
1380+
if (typeof minZoom === 'number'&&minZoom!==0) {
1381+
options.minZoom = minZoom-1;
13691382
}
13701383
if (typeof maxZoom === 'number') {
13711384
options.maxZoom = maxZoom;

‎test/mapboxgl/mapping/WebMapV2Spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2834,10 +2834,17 @@ describe('mapboxgl_WebMapV2', () => {
28342834
});
28352835
datavizWebmap.on('mapcreatesucceeded', ({ map }) => {
28362836
const layers = map.getStyle().layers;
2837+
const sources = map.getStyle().sources;
28372838
expect(layers.length).toBe(1);
28382839
const xyzLayer = layers[0];
28392840
expect(xyzLayer.id).toBe('2326底图');
28402841
expect(xyzLayer.type).toBe('raster');
2842+
expect(sources['2326底图'].bounds).toEqual([
2843+
113.77925526971052,
2844+
22.086139328930617,
2845+
114.53407583886273,
2846+
22.61831019233164
2847+
]);
28412848
done();
28422849
});
28432850
});

‎test/openlayers/mapping/WebMapSpec.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,47 @@ describe('openlayers_WebMap', () => {
227227
}
228228
});
229229

230+
it('initialize_ZXYtILE baseLayer 4214 epsgcode', (done) => {
231+
let options = {
232+
server: server,
233+
successCallback,
234+
errorCallback: function () { }
235+
};
236+
spyOn(FetchRequest, 'get').and.callFake((url) => {
237+
if (url.indexOf('map.json') > -1) {
238+
return Promise.resolve(new Response(JSON.stringify(datavizWebmap_ZXYTILE_4214)));
239+
}
240+
return Promise.resolve(new Response(JSON.stringify({})));
241+
});
242+
var datavizWebmap = new WebMap(id, options);
243+
function successCallback() {
244+
expect(datavizWebmap.mapParams.title).toBe('4326-zxy-tile');
245+
expect(datavizWebmap.layerAdded).toBe(1);
246+
done();
247+
}
248+
});
249+
250+
it('initialize_ZXYtILE baseLayer 2326 epsgcode', (done) => {
251+
let options = {
252+
server: server,
253+
successCallback,
254+
errorCallback: function () { }
255+
};
256+
spyOn(FetchRequest, 'get').and.callFake((url) => {
257+
if (url.indexOf('map.json') > -1) {
258+
return Promise.resolve(new Response(JSON.stringify(xyzLayer2326)));
259+
}
260+
return Promise.resolve(new Response(JSON.stringify({})));
261+
});
262+
var datavizWebmap = new WebMap(id, options);
263+
function successCallback(map) {
264+
expect(datavizWebmap.mapParams.title).toBe('4326-zxy-tile');
265+
expect(datavizWebmap.layerAdded).toBe(1);
266+
expect(map.getView().getMinZoom()).toBe(9);
267+
done();
268+
}
269+
});
270+
230271
it('jsonsql', (done) => {
231272
let options = {
232273
server: server,

‎test/resources/WebMapV5.js

Lines changed: 10 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /