diff --git a/src/common/mapping/WebMapService.js b/src/common/mapping/WebMapService.js index 44f6e6c44..ab92ba1cb 100644 --- a/src/common/mapping/WebMapService.js +++ b/src/common/mapping/WebMapService.js @@ -657,6 +657,7 @@ export class WebMapService { let type; let isHosted = (dataSource && dataSource.serverId) || layerType === 'MARKER' || layerType === 'HOSTED_TILE'; let isTile = + layerType === 'ZXY_TILE' || layerType === 'SUPERMAP_REST' || layerType === 'TILE' || layerType === 'WMS' || diff --git a/src/common/mapping/WebMapV2.js b/src/common/mapping/WebMapV2.js index c0ba474ba..2c35bd8dd 100644 --- a/src/common/mapping/WebMapV2.js +++ b/src/common/mapping/WebMapV2.js @@ -403,6 +403,9 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) { case 'TILE': this._createDynamicTiledLayer(layerInfo, addedCallback); break; + case 'ZXY_TILE': + this._createZXYLayer(layerInfo, addedCallback); + break; case 'CLOUD': case 'XYZ': url = mapUrls[layerInfo.layerType] @@ -442,6 +445,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) { layer.minzoom = Math.max(this._transformScaleToZoom(minScale, crs), 0); layer.maxzoom = Math.min(24, this._transformScaleToZoom(maxScale, crs) + 0.0000001); } + console.log('_initOverlayLayers') if (type === 'tile') { if (layer.autoUpdateTime) { @@ -705,6 +709,14 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) { addedCallback && addedCallback(); } + _createZXYLayer(layerInfo, addedCallback) { + 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({ url: urls, layerID: layerId, visibility: visible }); + addedCallback && addedCallback(); + } + _createDynamicTiledLayer(layerInfo, addedCallback) { const url = layerInfo.url; const layerId = layerInfo.layerID || layerInfo.name; diff --git a/src/openlayers/mapping/WebMap.js b/src/openlayers/mapping/WebMap.js index 75f317bd7..5e011d710 100644 --- a/src/openlayers/mapping/WebMap.js +++ b/src/openlayers/mapping/WebMap.js @@ -968,6 +968,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': @@ -1321,6 +1324,25 @@ export class WebMap extends Observable { }); } + /** + * @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.createWMSSource @@ -2107,6 +2129,10 @@ export class WebMap extends Observable { 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); } } } diff --git a/test/common/mapping/WebMapServiceSpec.js b/test/common/mapping/WebMapServiceSpec.js index 50c5b9908..d4548ab08 100644 --- a/test/common/mapping/WebMapServiceSpec.js +++ b/test/common/mapping/WebMapServiceSpec.js @@ -179,6 +179,23 @@ describe('WebMapServiceSpec.js', () => { }); }); + xit('getsourcetype zxytile', done => { + const options = { + ...options, + serverUrl: 'https://fakeiportal.supermap.io/iportal/' // 没有通过处理在末尾加 '/',在此处理 + }; + spyOn(FetchRequest, 'get').and.callFake((url) => { + if (url.indexOf('map.json') > -1) { + return Promise.resolve(mapJson); + } + return Promise.resolve(new Response(JSON.stringify(iportal_serviceProxy))); + }); + const service = new WebMapService(mapId, options); + const res = service.getDatasourceType({layerType: 'ZXY_TILE'}); + expect(res).toBe('tile'); + done() + }); + it('get the wrong iPortal service proxy', (done) => { const options = { ...options, diff --git a/test/mapboxgl/mapping/WebMapV2Spec.js b/test/mapboxgl/mapping/WebMapV2Spec.js index 3dcb78825..ef2e78948 100644 --- a/test/mapboxgl/mapping/WebMapV2Spec.js +++ b/test/mapboxgl/mapping/WebMapV2Spec.js @@ -1522,6 +1522,36 @@ describe('mapboxgl_WebMapV2', () => { }); }); + 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 + }, + { + style: { + version: 8, + sources: {}, + layers: [] + } + } + ); + datavizWebmap.on('mapcreatesucceeded', ({ layers }) => { + expect(layers.length).toBe(2); + done(); + }); + }); + it('isvj-5215', (done) => { spyOn(FetchRequest, 'get').and.callFake((url) => { if (url.indexOf('portal.json') > -1) { diff --git a/test/openlayers/mapping/WebMapSpec.js b/test/openlayers/mapping/WebMapSpec.js index e65adf607..f2cdb9c88 100644 --- a/test/openlayers/mapping/WebMapSpec.js +++ b/test/openlayers/mapping/WebMapSpec.js @@ -184,6 +184,28 @@ 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('jsonsql', (done) => { let options = { server: server, diff --git a/test/resources/WebMapV5.js b/test/resources/WebMapV5.js index 727adf36e..dafa1996b 100644 --- a/test/resources/WebMapV5.js +++ b/test/resources/WebMapV5.js @@ -12,6 +12,8 @@ var datavizWebMap_TIANDITU_TER = '{"version":"2.0","title":"ter","description":" var datavizWebMap_BAIDU = '{"version":"2.0","title":"百度","description":"","projection":"EPSG:3857","center":{"x":9565084.985351142,"y":6230623.14371253},"level":3,"extent":{"leftBottom":{"x":-20037508.3427892,"y":-20037508.3427892},"rightTop":{"x":20037508.3427892,"y":20037508.3427892}},"baseLayer":{"layerType":"BAIDU","name":"百度地图"},"layers":[],"sourceType":"DataViz","thumbnail":"http://127.0.0.1:8090/iportal/static/dataviz/static/imgs/thumbnail_default.png","rootUrl":"http://127.0.0.1:8090/iportal/"}'; +var datavizWebmap_ZXYTILE = '{"extent":{"leftBottom":{"x":-20037508.3427892,"y":-20037508.3427892},"rightTop":{"x":20037508.3427892,"y":20037508.3427892}},"maxScale":"1:144447.92746805","level":1,"center":{"x":0,"y":-7.081154551613622e-10},"baseLayer":{"layerType":"TILE","visible":true,"name":"中国暗色地图","url":"https://iportal/rest/maps/China_Dark"},"layers":[{"layerType":"ZXY_TILE","subdomains":["a","c"],"visible":true,"name":"aaa","url":"https://{s}.tile.fake/{z}/{x}/{y}.png"}],"description":"","projection":"EPSG:3857","minScale":"1:591658710.909131","title":"xyz","version":"2.3.0","rootUrl":"http://127.0.0.1:8190/iportal/"}'; + var datavizWebMap_OPENSTREET = '{"version":"2.0","title":"openstreet","description":"","projection":"EPSG:3857","center":{"x":7044436.526761844,"y":-1643701.8562444348},"level":2,"extent":{"leftBottom":{"x":-20037508.34,"y":-20037508.34},"rightTop":{"x":20037508.34,"y":20037508.34}},"baseLayer":{"layerType":"OSM","name":"OpenStreetMap"},"layers":[],"sourceType":"DataViz","thumbnail":"http://127.0.0.1:8090/iportal/static/dataviz/static/imgs/thumbnail_default.png"}'; var datavizWebMap_CLOUD = '{"version":"2.0","title":"GAOD","description":"","projection":"EPSG:3857","center":{"x":0,"y":-7.081154551613622e-10},"level":1,"extent":{"leftBottom":{"x":-20037508.3427892,"y":-20037508.3427892},"rightTop":{"x":20037508.3427892,"y":20037508.3427892}},"baseLayer":{"layerType":"CLOUD","name":"高德地图"},"layers":[],"sourceType":"DataViz","thumbnail":"http://127.0.0.1:8090/iportal/static/dataviz/static/imgs/thumbnail_default.png"}';