Skip to content

Commit

Permalink
[feature]webmap对接webmercator全球剖分瓦片 by qiw
Browse files Browse the repository at this point in the history
  • Loading branch information
luoxiao-supermap committed Oct 24, 2024
1 parent 5398599 commit 4372b35
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/mapboxgl/mapping/WebMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ export class WebMap extends mapboxgl.Evented {
case 'SUPERMAP_REST':
this._createDynamicTiledLayer(layerInfo);
break;
case 'ZXY_TILE':
this._createZXYLayer(layerInfo);
break;
case 'CLOUD':
case 'CLOUD_BLACK':
case 'OSM':
Expand Down Expand Up @@ -566,6 +569,13 @@ export class WebMap extends mapboxgl.Evented {
this._addBaselayer(urlArr, 'XYZ-layers-' + layerInfo.name);
}

_createZXYLayer(layerInfo) {
const { url, subdomains, layerID, name, visible } = layerInfo;
const urls = (subdomains && subdomains.length) ? subdomains.map(item => url.replace('{s}', item)) : [url];
const layerId = layerID || name;
this._addBaselayer(urls, layerId, undefined, undefined, false, visible);
}

/**
* @private
* @function WebMap.prototype._createDynamicTiledLayer
Expand Down Expand Up @@ -758,6 +768,7 @@ export class WebMap extends mapboxgl.Evented {
this.fire('getlayersfailed', { error: error, map: this.map });
});
} else if (
layer.layerType === 'ZXY_TILE' ||
layer.layerType === 'SUPERMAP_REST' ||
layer.layerType === 'TILE' ||
layer.layerType === 'WMS' ||
Expand Down Expand Up @@ -1955,7 +1966,7 @@ export class WebMap extends mapboxgl.Evented {
}
}

_addBaselayer(url, layerID, minzoom = 0, maxzoom = 22, isIserver) {
_addBaselayer(url, layerID, minzoom = 0, maxzoom = 22, isIserver, visible = true) {
this.map.addLayer({
id: layerID,
type: 'raster',
Expand All @@ -1966,6 +1977,7 @@ export class WebMap extends mapboxgl.Evented {
rasterSource: isIserver ? 'iserver' : '',
prjCoordSys: isIserver ? { epsgCode: this.baseProjection.split(':')[1] } : ''
},
layout: { visibility: visible ? 'visible': 'none' },
minzoom: minzoom,
maxzoom: maxzoom
});
Expand Down
27 changes: 27 additions & 0 deletions src/openlayers/mapping/WebMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,9 @@ export class WebMap extends Observable {
case 'SUPERMAP_REST':
source = that.createDynamicTiledSource(layerInfo, isBaseLayer);
break;
case 'ZXY_TILE':
source = this.createXYZTileSource(layerInfo);
break;
case 'CLOUD':
case 'CLOUD_BLACK':
case 'OSM':
Expand Down Expand Up @@ -1116,6 +1119,26 @@ export class WebMap extends Observable {
break;
}
}

/**
* @private
* @function WebMap.prototype.createXYZTileSource
* @description 创建图层的XYZTilesource。
* @param {Object} layerInfo - 图层信息
* @returns {ol.source.XYZ} xyz的source
*/
createXYZTileSource(layerInfo) {
const { url, subdomains } = layerInfo;
const urls = (subdomains && subdomains.length) ? subdomains.map(item => url.replace('{s}', item)) : [url];
const tileGrid = TileSuperMapRest.createTileGrid([-20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892]);
return new XYZ({
urls,
wrapX: false,
crossOrigin: 'anonymous',
tileGrid
});
}

/**
* @private
* @function WebMap.prototype.createDynamicTiledSource
Expand Down Expand Up @@ -1939,6 +1962,10 @@ export class WebMap extends Observable {
that.layerAdded++;
that.errorCallback && that.errorCallback(e, 'getFeatureFaild', that.map);
})
} else if (layer.layerType === 'ZXY_TILE') {
that.map.addLayer(that.createBaseLayer(layer, layerIndex));
that.layerAdded++;
that.sendMapToUser(len);
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions test/mapboxgl/mapping/WebMapSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,28 @@ describe('mapboxgl_WebMap', () => {
done();
});
});
it('add zxytile layer', (done) => {
spyOn(FetchRequest, 'get').and.callFake((url) => {
if (url.indexOf('portal.json') > -1) {
return Promise.resolve(new Response(JSON.stringify(iportal_serviceProxy)));
} else if (url.indexOf('/map.json') > -1) {
return Promise.resolve(new Response(datavizWebmap_ZXYTILE));
}
return Promise.resolve();
});
datavizWebmap = new WebMap(
'test',
{
target: 'map',
serverUrl: 'http://fake/fakeiportal',
withCredentials: false
}
);
datavizWebmap.on('addlayerssucceeded', ({ layers }) => {
expect(layers.length).toBe(2);
done();
});
});
it('initialize_TIANDITU_IMAGE', (done) => {
spyOn(FetchRequest, 'get').and.callFake((url) => {
if (url.indexOf('map.json') > -1) {
Expand Down
21 changes: 21 additions & 0 deletions test/openlayers/mapping/WebMapSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,27 @@ describe('openlayers_WebMap', () => {
}
});

it('initialize_ZXYtILE', (done) => {
let options = {
server: server,
successCallback,
errorCallback: function () { }
};
spyOn(FetchRequest, 'get').and.callFake((url) => {
if (url.indexOf('map.json') > -1) {
var mapJson = datavizWebmap_ZXYTILE;
return Promise.resolve(new Response(mapJson));
}
return Promise.resolve();
});
var datavizWebmap = new WebMap(id, options);
function successCallback() {
expect(datavizWebmap.mapParams.title).toBe('xyz');
// expect(datavizWebmap.layerAdded).toBe(2);
done();
}
});

it('initialize_CLOUD', (done) => {
let options = {
server: server,
Expand Down
2 changes: 2 additions & 0 deletions test/resources/WebMapV5.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4372b35

Please sign in to comment.