diff --git a/src/common/iServer/InitMapServiceBase.js b/src/common/iServer/InitMapServiceBase.js index 7b678f6de..6e7427dca 100644 --- a/src/common/iServer/InitMapServiceBase.js +++ b/src/common/iServer/InitMapServiceBase.js @@ -114,6 +114,38 @@ export function getEpsgCode(prjCoordSys) { return 'EPSG:' + epsgCode; } +/** + * @private + * @function getTileFormat + * @description 获取瓦片格式。 + * @returns {string} 瓦片格式 + */ + +export function getTileFormat(tileset) { + if (tileset.tileFormat) { + const format = tileset.tileFormat.toLowerCase(); + if (['jpg_png', 'default', 'png8'].includes(format)) { + return 'png'; + } + return format; + } + return 'png'; +} + +/** + * @private + * @function getTileset + * @description 获取 tilseset + * @returns {Object} + */ + +export function getTileset(tilesets = [], targets) { + const imageTilesets = tilesets.filter((i) => { + return i.metaData.tileType === targets.tileType || 'Image' && getEpsgCode(i.metaData.prjCoordSys) === getEpsgCode(targets.prjCoordSys); + }); + return imageTilesets[0] && imageTilesets[0].metaData; +} + /** * @private diff --git a/src/leaflet/mapping/initMap.js b/src/leaflet/mapping/initMap.js index de9761844..35b5a555a 100644 --- a/src/leaflet/mapping/initMap.js +++ b/src/leaflet/mapping/initMap.js @@ -10,7 +10,9 @@ import { MapService } from '../services/MapService'; import { InitMapServiceBase, isPlaneProjection, - getEpsgCode + getEpsgCode, + getTileFormat, + getTileset } from '@supermap/iclient-common/iServer/InitMapServiceBase'; import proj4 from 'proj4'; @@ -73,8 +75,9 @@ export async function initMap(url, options) { const origin = [tileset.originalPoint.x, tileset.originalPoint.y] const resolutions = tileset.resolutions; const scaleDenominators = tileset.scaleDenominators + const coordUnit = mapObject.coordUnit; maxZoom = resolutions.length - 1; - crs = crsFromMapJSON({ prjCoordSys, bounds, resolutions, origin, dpi: getDpi(1.0 / scaleDenominators[0], resolutions[0]) }, { maxZoom }); + crs = crsFromMapJSON({ prjCoordSys, bounds, resolutions, origin, dpi: getDpi(1.0 / scaleDenominators[0], resolutions[0], coordUnit) }, { maxZoom }); zoom = getZoomByResolution(1.0 / scale, scaleDenominators); } else { tileFormat = 'webp'; @@ -82,10 +85,10 @@ export async function initMap(url, options) { transparent = true; const { scale, dpi, coordUnit } = mapObject; const origin = [bounds.left, bounds.top]; - const resolutions = scalesToResolutions(mapObject.visibleScales, bounds, dpi, coordUnit, scale); + const resolutions = scalesToResolutions(mapObject.visibleScales, bounds, dpi, coordUnit, mapOptions.maxZoom, scale); maxZoom = resolutions.length - 1; crs = crsFromMapJSON({ prjCoordSys, bounds, resolutions, origin, dpi }, { maxZoom }); - zoom = getZoomByScale({ scale, dpi, coordUnit }, resolutions) + zoom = getZoomByScale({ scale, dpi, coordUnit }, resolutions); } const mapInfoOptions = { @@ -240,12 +243,6 @@ function getNonEarthCRS(bounds, origin, resolutions) { }; return new NonEarthCRS(options); } -function getTileset(tilesets = [], targets) { - const imageTilesets = tilesets.filter((i) => { - return i.metaData.tileType === targets.tileType || 'Image' && getEpsgCode(i.metaData.prjCoordSys) === getEpsgCode(targets.prjCoordSys); - }); - return imageTilesets[0] ? imageTilesets[0].metaData : {}; -} function getCRS(epsgCodeStr, { bounds, origin, dpi, resolutions }) { const wrapLngLeft = proj4(epsgCodeStr, 'EPSG:4326').forward([bounds.left, 0], true); @@ -262,13 +259,3 @@ function getCRS(epsgCodeStr, { bounds, origin, dpi, resolutions }) { } return new CRS(epsgCodeStr, options); } -function getTileFormat(tileset) { - if (tileset.tileFormat) { - const format = tileset.tileFormat.toLowerCase(); - if (['jpg_png', 'default', 'png8'].includes(format)) { - return 'png'; - } - return format; - } - return 'png'; -} diff --git a/src/openlayers/core/Util.js b/src/openlayers/core/Util.js index 9b0216289..345f528bf 100644 --- a/src/openlayers/core/Util.js +++ b/src/openlayers/core/Util.js @@ -3,7 +3,7 @@ * which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/ import { Bounds } from '@supermap/iclient-common/commontypes/Bounds'; import { GeoJSON as GeoJSONFormat } from '@supermap/iclient-common/format/GeoJSON'; - import { getMeterPerMapUnit, scalesToResolutions, getZoomByResolution } from '@supermap/iclient-common/util/MapCalculateUtil'; + import { getMeterPerMapUnit, scalesToResolutions, getZoomByResolution, getDpi } from '@supermap/iclient-common/util/MapCalculateUtil'; import * as olUtil from 'ol/util'; import Geometry from 'ol/geom/Geometry'; import { getVectorContext } from 'ol/render'; @@ -426,6 +426,7 @@ scalesToResolutions(scales, bounds, dpi, unit, mapobj, level) { return scalesToResolutions(scales, bounds, dpi, unit, mapobj, level); }, + getDpi, getProjection(prjCoordSys, extent) { let projection = get(`EPSG:${prjCoordSys.epsgCode}`); if (prjCoordSys.type == 'PCS_NON_EARTH') { diff --git a/src/openlayers/mapping/InitMap.js b/src/openlayers/mapping/InitMap.js index 169e9120d..edb1f02a9 100644 --- a/src/openlayers/mapping/InitMap.js +++ b/src/openlayers/mapping/InitMap.js @@ -1,5 +1,5 @@ import { MapService } from '../services/MapService'; -import { InitMapServiceBase, isPlaneProjection } from '@supermap/iclient-common/iServer/InitMapServiceBase'; +import { InitMapServiceBase, isPlaneProjection, getTileFormat, getTileset } from '@supermap/iclient-common/iServer/InitMapServiceBase'; import olMap from 'ol/Map'; import View from 'ol/View'; import Tile from 'ol/layer/Tile'; @@ -41,29 +41,53 @@ window.proj4 = proj4; * initMap(url, { mapOptions, viewOptions, layerOptions, sourceOptions }) * ``` * */ -export function initMap(url, options = {}) { +export async function initMap(url, options = {}) { const { mapOptions, viewOptions, layerOptions, sourceOptions } = options; const initMapService = new InitMapServiceBase(MapService, url, options); - return initMapService.getMapInfo(async function (serviceResult, resolve, reject) { - if (!serviceResult || !serviceResult.result) { - reject('service is not work!'); - return; - } - let { prjCoordSys, bounds } = serviceResult.result; - if (!get(`EPSG:${prjCoordSys.epsgCode}`) && !isPlaneProjection(prjCoordSys.type)) { - const wkt = await initMapService.getWKT(); - registerProj(prjCoordSys.epsgCode, wkt, bounds); - } + const tilesets = await initMapService.getTilesets(); + const result = await initMapService.getMapInfo(); + if (!result || !result.result) { + return 'service is not work!'; + } + const mapObject = result.result; + const { prjCoordSys, bounds, center, visibleScales, coordUnit, scale, dpi } = mapObject; + // tileset和地图不同投影,优先使用地图 + const tileset = getTileset(tilesets.result, { prjCoordSys, tileType: 'Image' }); - let map = createMap(serviceResult.result, mapOptions, viewOptions); - let { layer, source } = createLayer(url, serviceResult.result, sourceOptions, layerOptions); - map.addLayer(layer); - resolve({ - map, - source, - layer - }); - }); + const config = { + center, + bounds, + dpi, + visibleScales, + scale, + prjCoordSys, + coordUnit, + tileFormat: 'webp', + tileSize: 256 + }; + if (tileset) { + config.tileFormat = getTileFormat(tileset); + config.tileSize = tileset.tileWidth || 256; + config.transparent = tileset.transparent || true; + config.origin = [tileset.originalPoint.x, tileset.originalPoint.y]; + config.resolutions = tileset.resolutions; + config.scaleDenominators = tileset.scaleDenominators; + config.dpi = Util.getDpi(1.0 / tileset.scaleDenominators[0], tileset.resolutions[0], coordUnit); + } + + if (!get(`EPSG:${prjCoordSys.epsgCode}`) && !isPlaneProjection(prjCoordSys.type)) { + const wkt = await initMapService.getWKT(); + registerProj(prjCoordSys.epsgCode, wkt, bounds); + } + + let map = createMap(config, mapOptions, viewOptions); + let { layer, source } = createLayer(url, config, sourceOptions, layerOptions); + map.addLayer(layer); + return { + map, + source, + layer + }; } /** @@ -77,13 +101,14 @@ export function initMap(url, options = {}) { */ export function viewOptionsFromMapJSON(mapJSONObj, level = 22) { - let { bounds, dpi, center, visibleScales, scale, coordUnit, prjCoordSys } = mapJSONObj; + let { bounds, dpi, center, visibleScales, scale, coordUnit, prjCoordSys, scaleDenominators, resolutions } = mapJSONObj; const mapCenter = center.x && center.y ? [center.x, center.y] : [(bounds.left + bounds.right) / 2, (bounds.bottom + bounds.top) / 2]; const extent = [bounds.left, bounds.bottom, bounds.right, bounds.top]; let projection = Util.getProjection(prjCoordSys, extent); - var resolutions = Util.scalesToResolutions(visibleScales, bounds, dpi, coordUnit, level); - const zoom = Util.getZoomByResolution(Util.scaleToResolution(scale, dpi, coordUnit), resolutions); + resolutions = resolutions || Util.scalesToResolutions(visibleScales, bounds, dpi, coordUnit, level); + const resolution = scaleDenominators ? (1.0 / scale) : Util.scaleToResolution(scale, dpi, coordUnit); + const zoom = Util.getZoomByResolution(resolution, resolutions); return { center: mapCenter, projection, diff --git a/src/openlayers/mapping/TileSuperMapRest.js b/src/openlayers/mapping/TileSuperMapRest.js index 4710df0fe..e6c5e5694 100644 --- a/src/openlayers/mapping/TileSuperMapRest.js +++ b/src/openlayers/mapping/TileSuperMapRest.js @@ -322,7 +322,14 @@ export class TileSuperMapRest extends TileImage { * @param {Object} mapJSONObj - 地图 JSON 对象。 */ static optionsFromMapJSON(url, mapJSONObj) { - var options = {}; + var options = { + }; + if (mapJSONObj.tileFormat) { + options.format = mapJSONObj.tileFormat; + } + if (mapJSONObj.origin) { + options.origin = mapJSONObj.origin; + } options.url = url; options.crossOrigin = 'anonymous'; var extent = [mapJSONObj.bounds.left, mapJSONObj.bounds.bottom, mapJSONObj.bounds.right, mapJSONObj.bounds.top]; @@ -330,7 +337,8 @@ export class TileSuperMapRest extends TileImage { var resolutions = Util.scalesToResolutions(visibleScales, bounds, dpi, coordUnit); options.tileGrid = new TileGrid({ extent: extent, - resolutions: resolutions + resolutions: resolutions, + tileSize: mapJSONObj.tileSize || 256 }); return options; } diff --git a/test/leaflet/mapping/initMapSpec.js b/test/leaflet/mapping/initMapSpec.js index d69e63e0d..f1f8035a5 100644 --- a/test/leaflet/mapping/initMapSpec.js +++ b/test/leaflet/mapping/initMapSpec.js @@ -28,7 +28,7 @@ describe('initMap', () => { }); afterAll(() => {}); - it('initMap 3857', async () => { + it('initMap 3857', (done) => { var url = 'http:/fake:8090/iserver/services/map-Population/rest/maps/PopulationDistribution'; var mapInfo = { prjCoordSys: { @@ -66,19 +66,25 @@ describe('initMap', () => { coordUnit: 'METER' }; spyOn(FetchRequest, 'get').and.callFake((testUrl) => { - return Promise.resolve(new Response(JSON.stringify(mapInfo))); + if(testUrl.indexOf('tilesets') === -1) { + return Promise.resolve(new Response(JSON.stringify(mapInfo))); + } + return Promise.resolve(); }); - var res = await initMap(url); - map = res.map; - expect(map.options.crs.code).toBe('EPSG:3857'); - expect(map.options.crs.resolutions.length).toEqual(22); - expect(map.options.zoom).toBe(1); - expect(map.options.maxZoom).toBe(21); - expect(res.layer).not.toBeNull(); + initMap(url).then((res) => { + map = res.map; + expect(map.options.crs.code).toBe('EPSG:3857'); + expect(map.options.crs.resolutions.length).toEqual(22); + expect(map.options.zoom).toBe(2); + expect(map.options.maxZoom).toBe(21); + expect(res.layer).not.toBeNull(); + done(); + }); + }); - it('initMap 4326', async () => { + it('initMap 4326', (done) => { var url = 'http://fake:8090/iserver/services/map-jinjing/rest/maps/jinjing'; var mapInfo = { prjCoordSys: { @@ -112,19 +118,24 @@ describe('initMap', () => { coordUnit: 'DEGREE' }; spyOn(FetchRequest, 'get').and.callFake((testUrl) => { - return Promise.resolve(new Response(JSON.stringify(mapInfo))); + if(testUrl.indexOf('tilesets') === -1) { + return Promise.resolve(new Response(JSON.stringify(mapInfo))); + } + return Promise.resolve(); }); - var res = await initMap(url); - map = res.map; - expect(map.options.crs.code).toBe('EPSG:4326'); - expect(map.options.crs.resolutions.length).toEqual(22); - expect(map.options.zoom).toBe(2); - expect(map.options.maxZoom).toBe(21); - expect(res.layer).not.toBeNull(); + initMap(url).then((res) => { + map = res.map; + expect(map.options.crs.code).toBe('EPSG:4326'); + expect(map.options.crs.resolutions.length).toEqual(22); + expect(map.options.zoom).toBe(3); + expect(map.options.maxZoom).toBe(21); + expect(res.layer).not.toBeNull(); + done(); + }); }); - it('initMap -1000', async () => { + it('initMap -1000', (done) => { var url = 'http:/fake:8090/iserver/services/map-changchun/rest/maps/changchun'; var mapInfo = { prjCoordSys: { @@ -159,19 +170,24 @@ describe('initMap', () => { coordUnit: 'METER' }; spyOn(FetchRequest, 'get').and.callFake((testUrl) => { - return Promise.resolve(new Response(JSON.stringify(mapInfo))); + if(testUrl.indexOf('tilesets') === -1) { + return Promise.resolve(new Response(JSON.stringify(mapInfo))); + } + return Promise.resolve(); }); - var res = await initMap(url); - map = res.map; - expect(map.options.crs.code).toBe(undefined); - expect(map.options.crs.resolutions).toEqual(undefined); - expect(map.options.zoom).toBe(1); - expect(map.options.maxZoom).toBe(21); - expect(res.layer).not.toBeNull(); + initMap(url).then((res) => { + map = res.map; + expect(map.options.crs.code).toBe(undefined); + expect(map.options.crs.resolutions.length).toBe(22); + expect(map.options.zoom).toBe(2); + expect(map.options.maxZoom).toBe(21); + expect(res.layer).not.toBeNull(); + done(); + }); }); - it('initMap 3857 visibleScales', async () => { + it('initMap 3857 visibleScales', (done) => { var url = 'http:/fake:8090/iserver/services/map-china/rest/maps/china3857'; var mapInfo = { prjCoordSys: { @@ -209,19 +225,24 @@ describe('initMap', () => { coordUnit: 'METER' }; spyOn(FetchRequest, 'get').and.callFake((testUrl) => { - return Promise.resolve(new Response(JSON.stringify(mapInfo))); + if(testUrl.indexOf('tilesets') === -1) { + return Promise.resolve(new Response(JSON.stringify(mapInfo))); + } + return Promise.resolve(); }); - var res = await initMap(url); - map = res.map; - expect(map.options.crs.code).toBe('EPSG:3857'); - expect(map.options.crs.resolutions.length).toEqual(3); - expect(map.options.zoom).toBe(0); - expect(map.options.maxZoom).toBe(2); - expect(res.layer).not.toBeNull(); + initMap(url).then((res) => { + map = res.map; + expect(map.options.crs.code).toBe('EPSG:3857'); + expect(map.options.crs.resolutions.length).toEqual(3); + expect(map.options.zoom).toBe(0); + expect(map.options.maxZoom).toBe(2); + expect(res.layer).not.toBeNull(); + done(); + }); }); - it('initMap 4326 visibleScales', async () => { + it('initMap 4326 visibleScales', (done) => { var url = 'http:/fake:8090/iserver/services/map-china/rest/maps/china4326'; var mapInfo = { prjCoordSys: { @@ -256,19 +277,24 @@ describe('initMap', () => { coordUnit: 'DEGREE' }; spyOn(FetchRequest, 'get').and.callFake((testUrl) => { - return Promise.resolve(new Response(JSON.stringify(mapInfo))); + if(testUrl.indexOf('tilesets') === -1) { + return Promise.resolve(new Response(JSON.stringify(mapInfo))); + } + return Promise.resolve(); }); - var res = await initMap(url); - map = res.map; - expect(map.options.crs.code).toBe('EPSG:4326'); - expect(map.options.crs.resolutions.length).toEqual(3); - expect(map.options.zoom).toBe(0); - expect(map.options.maxZoom).toBe(2); - expect(res.layer).not.toBeNull(); + initMap(url).then((res) => { + map = res.map; + expect(map.options.crs.code).toBe('EPSG:4326'); + expect(map.options.crs.resolutions.length).toEqual(3); + expect(map.options.zoom).toBe(0); + expect(map.options.maxZoom).toBe(2); + expect(res.layer).not.toBeNull(); + done(); + }); }); - it('initMap 4490', async () => { + it('initMap 4490', (done) => { var url = 'http://fake:8090/iserver/services/map-china/rest/maps/chian4490'; var mapInfo = { prjCoordSys: { @@ -310,19 +336,24 @@ describe('initMap', () => { if (testUrl.includes('prjCoordSys.wkt')) { return Promise.resolve(new Response(def4490)); } - return Promise.resolve(new Response(JSON.stringify(mapInfo))); + if(testUrl.indexOf('tilesets') === -1) { + return Promise.resolve(new Response(JSON.stringify(mapInfo))); + } + return Promise.resolve(); }); - var res = await initMap(url); - map = res.map; - expect(map.options.crs.code).toBe('EPSG:4490'); - expect(map.options.crs.resolutions.length).toEqual(13); - expect(map.options.zoom).toBe(2); - expect(map.options.maxZoom).toBe(12); - expect(res.layer).not.toBeNull(); + initMap(url).then((res) => { + map = res.map; + expect(map.options.crs.code).toBe('EPSG:4490'); + expect(map.options.crs.resolutions.length).toEqual(13); + expect(map.options.zoom).toBe(2); + expect(map.options.maxZoom).toBe(12); + expect(res.layer).not.toBeNull(); + done(); + }); }); - it('initMap mapOptions', async () => { + it('initMap mapOptions', (done) => { var url = 'http:/fake:8090/iserver/services/map-Population/rest/maps/PopulationDistribution'; var mapInfo = { prjCoordSys: { @@ -361,19 +392,24 @@ describe('initMap', () => { overlapDisplayedOptions: false }; spyOn(FetchRequest, 'get').and.callFake((testUrl) => { - return Promise.resolve(new Response(JSON.stringify(mapInfo))); + if(testUrl.indexOf('tilesets') === -1) { + return Promise.resolve(new Response(JSON.stringify(mapInfo))); + } + return Promise.resolve(); }); - var res = await initMap(url, { mapOptions: { center: [0, 0], zoom: 1, maxZoom: 10 } }); - map = res.map; - expect(map.options.crs.code).toBe('EPSG:3857'); - expect(map.options.crs.resolutions.length).toEqual(10); - expect(map.options.zoom).toBe(1); - expect(map.options.maxZoom).toBe(10); - expect(res.layer).not.toBeNull(); + initMap(url, { mapOptions: { center: [0, 0], zoom: 1, maxZoom: 10 } }).then((res) => { + map = res.map; + expect(map.options.crs.code).toBe('EPSG:3857'); + expect(map.options.crs.resolutions.length).toEqual(10); + expect(map.options.zoom).toBe(1); + expect(map.options.maxZoom).toBe(10); + expect(res.layer).not.toBeNull(); + done(); + }); }); - it('crsFromMapJSON ', async () => { + it('crsFromMapJSON ', (done) => { var mapInfo = { prjCoordSys: { distanceUnit: 'METER', @@ -410,12 +446,13 @@ describe('initMap', () => { coordUnit: 'METER', overlapDisplayedOptions: false }; - var crs = await crsFromMapJSON(mapInfo); + var crs = crsFromMapJSON(mapInfo); expect(crs.code).toBe('EPSG:3857'); expect(crs.resolutions.length).toEqual(22); + done(); }); - xit('crsFromMapJSON 4490 noProjDef', async () => { + xit('crsFromMapJSON 4490 noProjDef', () => { var mapInfo = { prjCoordSys: { distanceUnit: 'METER', @@ -456,13 +493,16 @@ describe('initMap', () => { if (testUrl.includes('prjCoordSys.wkt')) { return Promise.resolve(new Response('')); } - return Promise.resolve(new Response(JSON.stringify(mapInfo))); + if(testUrl.indexOf('tilesets') === -1) { + return Promise.resolve(new Response(JSON.stringify(mapInfo))); + } + return Promise.resolve(); }); - var res = await crsFromMapJSON(mapInfo); + var res = crsFromMapJSON(mapInfo); expect(res).toBe(undefined); }); - it('crsFromMapJSON 4490', async () => { + it('crsFromMapJSON 4490', (done) => { var mapInfo = { prjCoordSys: { distanceUnit: 'METER', @@ -501,14 +541,18 @@ describe('initMap', () => { }; proj4.defs('EPSG:4490', def4490); spyOn(FetchRequest, 'get').and.callFake((testUrl) => { - return Promise.resolve(new Response(JSON.stringify(mapInfo))); + if(testUrl.indexOf('tilesets') === -1) { + return Promise.resolve(new Response(JSON.stringify(mapInfo))); + } + return Promise.resolve(); }); - var crs = await crsFromMapJSON(mapInfo); + var crs = crsFromMapJSON(mapInfo); expect(crs.code).toBe('EPSG:4490'); expect(crs.resolutions.length).toEqual(13); + done(); }); - it('crsFromMapJSON maxZoom', async () => { + it('crsFromMapJSON maxZoom', (done) => { var url = 'http:/fake:8090/iserver/services/map-Population/rest/maps/PopulationDistribution'; var mapInfo = { prjCoordSys: { @@ -546,8 +590,29 @@ describe('initMap', () => { coordUnit: 'METER', overlapDisplayedOptions: false }; - var crs = await crsFromMapJSON(mapInfo, { maxZoom: 10 }); + var crs = crsFromMapJSON(mapInfo, { maxZoom: 10 }); expect(crs.code).toBe('EPSG:3857'); expect(crs.resolutions.length).toEqual(10); + done(); + }); + + it('with tilesets', (done) => { + var tilesetServeRequest = 'http://supermapiserver:8090/iserver/services/map-world/rest/maps/Jinjing111'; + spyOn(FetchRequest, 'get').and.callFake((url) => { + if (url.indexOf('Jinjing111') > -1 && url.indexOf('tilesets') === -1) { + return Promise.resolve(new Response(mapInfo_2)); + } + if (url.indexOf('Jinjing111/tilesets') > -1) { + return Promise.resolve(new Response(tilesetInfo_1)); + } + return Promise.resolve(); + }); + initMap(tilesetServeRequest).then(({ map, layer }) => { + expect(map.options.crs.code).toBe('EPSG:4326'); + expect(map.options.maxZoom).toBe(4); + expect(map.options.crs.resolutions.length).toBe(5); + expect(map).not.toBeNull(); + done(); + }); }); }); diff --git a/test/openlayers/mapping/InitMapSpec.js b/test/openlayers/mapping/InitMapSpec.js index a952234da..928afc33a 100644 --- a/test/openlayers/mapping/InitMapSpec.js +++ b/test/openlayers/mapping/InitMapSpec.js @@ -6,6 +6,7 @@ describe('openlayers_InitMap', () => { var testDiv; var originalTimeout; var defaultServeRequest = 'http://supermapiserver:8090/iserver/services/map-world/rest/maps/World'; + var tilesetServeRequest = 'http://supermapiserver:8090/iserver/services/map-world/rest/maps/Jinjing111'; beforeEach(() => { testDiv = window.document.createElement('div'); testDiv.setAttribute('id', 'map'); @@ -18,15 +19,16 @@ describe('openlayers_InitMap', () => { jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; }); - it('initialize', () => { + it('initialize', (done) => { spyOn(FetchRequest, 'get').and.callFake((url) => { - if (url.indexOf('World') > -1) { + if (url.indexOf('World') > -1 && url.indexOf('tilesets') === -1) { return Promise.resolve(new Response(mapInfo_1)); } return Promise.resolve(); }); initMap(defaultServeRequest).then(({ map }) => { expect(map).not.toBeNull(); + done(); }); }); @@ -36,4 +38,20 @@ describe('openlayers_InitMap', () => { expect(res.center).toEqual([mapObj.center.x, mapObj.center.y]); expect(res.zoom).not.toBeNull(); }); + + it('with tilesets', (done) => { + spyOn(FetchRequest, 'get').and.callFake((url) => { + if (url.indexOf('Jinjing111') > -1 && url.indexOf('tilesets') === -1) { + return Promise.resolve(new Response(mapInfo_2)); + } + if (url.indexOf('Jinjing111/tilesets') > -1) { + return Promise.resolve(new Response(tilesetInfo_1)); + } + return Promise.resolve(); + }); + initMap(tilesetServeRequest).then(({ map }) => { + expect(map).not.toBeNull(); + done(); + }); + }); }); diff --git a/test/resources/WebMapV5.js b/test/resources/WebMapV5.js index d2c88bafa..19a8b6cb3 100644 --- a/test/resources/WebMapV5.js +++ b/test/resources/WebMapV5.js @@ -566,6 +566,241 @@ const mapInfo_1 = `{ } }`; +const mapInfo_2 = `{ + "viewBounds": { + "top": 41.25563007837713, + "left": 115.8344539060727, + "bottom": 38.82179453526931, + "leftBottom": { + "x": 115.8344539060727, + "y": 38.82179453526931 + }, + "right": 118.26828944918051, + "rightTop": { + "x": 118.26828944918051, + "y": 41.25563007837713 + } + }, + "viewer": { + "leftTop": { + "x": 0, + "y": 0 + }, + "top": 0, + "left": 0, + "bottom": 256, + "rightBottom": { + "x": 256, + "y": 256 + }, + "width": 256, + "right": 256, + "height": 256 + }, + "distanceUnit": null, + "minVisibleTextSize": 0, + "coordUnit": "DEGREE", + "scale": 2.5E-7, + "description": null, + "paintBackground": false, + "maxVisibleTextSize": 0, + "maxVisibleVertex": 0, + "clipRegionEnabled": false, + "antialias": false, + "textOrientationFixed": false, + "angle": 0, + "prjCoordSys": { + "distanceUnit": "METER", + "projectionParam": null, + "epsgCode": 4326, + "coordUnit": "DEGREE", + "name": "经纬坐标系---GCS_WGS_1984", + "projection": null, + "type": "PCS_EARTH_LONGITUDE_LATITUDE", + "coordSystem": { + "datum": { + "name": "D_WGS_1984", + "type": "DATUM_WGS_1984", + "spheroid": { + "flatten": 0.0033528107000003215, + "name": "WGS_1984", + "axis": 6378137, + "type": "SPHEROID_WGS_1984" + } + }, + "unit": "DEGREE", + "spatialRefType": "SPATIALREF_EARTH_LONGITUDE_LATITUDE", + "name": "GCS_WGS_1984", + "type": "GCS_WGS_1984", + "primeMeridian": { + "longitudeValue": 0, + "name": "Greenwich", + "type": "PRIMEMERIDIAN_GREENWICH" + } + } + }, + "minScale": 0, + "markerAngleFixed": false, + "overlapDisplayedOptions": null, + "visibleScales": [ + 2.5E-7, + 5.0E-7, + 1.0E-6, + 2.0E-6, + 4.0E-6 + ], + "dpi": 96, + "visibleScalesEnabled": true, + "customEntireBoundsEnabled": false, + "clipRegion": null, + "maxScale": 0, + "customParams": "", + "center": { + "x": 117.0513716776266, + "y": 40.03871230682322 + }, + "dynamicPrjCoordSyses": [ + { + "distanceUnit": "METER", + "projectionParam": null, + "epsgCode": 4326, + "coordUnit": "DEGREE", + "name": "经纬坐标系---GCS_WGS_1984", + "projection": null, + "type": "PCS_EARTH_LONGITUDE_LATITUDE", + "coordSystem": { + "datum": { + "name": "D_WGS_1984", + "type": "DATUM_WGS_1984", + "spheroid": { + "flatten": 0.0033528107000003215, + "name": "WGS_1984", + "axis": 6378137, + "type": "SPHEROID_WGS_1984" + } + }, + "unit": "DEGREE", + "spatialRefType": "SPATIALREF_EARTH_LONGITUDE_LATITUDE", + "name": "GCS_WGS_1984", + "type": "GCS_WGS_1984", + "primeMeridian": { + "longitudeValue": 0, + "name": "Greenwich", + "type": "PRIMEMERIDIAN_GREENWICH" + } + } + } + ], + "colorMode": null, + "textAngleFixed": false, + "overlapDisplayed": false, + "userToken": { + "userID": "" + }, + "cacheEnabled": false, + "dynamicProjection": false, + "autoAvoidEffectEnabled": true, + "customEntireBounds": null, + "name": "京津地区地图1", + "bounds": { + "top": 42.31307532235788, + "left": 114.58902605452259, + "bottom": 37.76434929128856, + "leftBottom": { + "x": 114.58902605452259, + "y": 37.76434929128856 + }, + "right": 119.51371730073062, + "rightTop": { + "x": 119.51371730073062, + "y": 42.31307532235788 + } + }, + "backgroundStyle": null +}`; + +const tilesetInfo_1 = `[ + { + "metaData": { + "scaleDenominators": [ + 4000000, + 2000000, + 1000000, + 500000, + 250000 + ], + "originalPoint": { + "x": -180, + "y": 90 + }, + "resolutions": [ + 0.009507170090264935, + 0.0047535850451324675, + 0.0023767925225662337, + 0.0011883962612831169, + 5.941981306415584E-4 + ], + "tileWidth": 256, + "mapStatusHashCode": "3B365026FIX", + "transparent": true, + "mapParameter": null, + "tileType": "Image", + "tileFormat": "WEBP", + "bounds": { + "top": 42.31307532235788, + "left": 114.58902605452259, + "bottom": 37.76434929128856, + "leftBottom": { + "x": 114.58902605452259, + "y": 37.76434929128856 + }, + "right": 119.51371730073062, + "rightTop": { + "x": 119.51371730073062, + "y": 42.31307532235788 + } + }, + "tileRuleVersion": null, + "storageType": "Original", + "prjCoordSys": { + "distanceUnit": "METER", + "projectionParam": null, + "epsgCode": 4326, + "coordUnit": "DEGREE", + "name": "经纬坐标系---GCS_WGS_1984", + "projection": null, + "type": "PCS_EARTH_LONGITUDE_LATITUDE", + "coordSystem": { + "datum": { + "name": "D_WGS_1984", + "type": "DATUM_WGS_1984", + "spheroid": { + "flatten": 0.0033528107000003215, + "name": "WGS_1984", + "axis": 6378137, + "type": "SPHEROID_WGS_1984" + } + }, + "unit": "DEGREE", + "spatialRefType": "SPATIALREF_EARTH_LONGITUDE_LATITUDE", + "name": "GCS_WGS_1984", + "type": "GCS_WGS_1984", + "primeMeridian": { + "longitudeValue": 0, + "name": "Greenwich", + "type": "PRIMEMERIDIAN_GREENWICH" + } + } + }, + "mapName": "京津地区地图1", + "tilesetName": "京津地区地图1", + "tileHeight": 256 + }, + "name": "UGCV5_tileset_京津地区地图1", + "tileVersions": null + } +]`; + var datavizWebMap_RestMap_1000 = { "title": "RestMap", "description": "restMap -1000",