Skip to content

Commit 8198a08

Browse files
Merge branch 'v11.1.1' of https://github.com/SuperMap/iClient-JavaScript into v11.1.1
2 parents 9609782 + 5c73fc0 commit 8198a08

File tree

9 files changed

+143
-11
lines changed

9 files changed

+143
-11
lines changed

dist/ol/include-ol.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
inputScript(libsurl + '/openlayers/ol3-echarts/1.3.6/ol3Echarts.min.js');
9090
}
9191
if (inArray(includes, 'ol-mapbox-style')) {
92-
inputScript(libsurl + '/openlayers/plugins/ol-mapbox-style/2.11.2-5/olms.js');
92+
inputScript(libsurl + '/openlayers/plugins/ol-mapbox-style/2.11.2-6/olms.js');
9393
}
9494
if (inArray(includes, 'deck')) {
9595
inputScript(libsurl + '/deck.gl/5.1.3/deck.gl.min.js');

dist/openlayers/include-openlayers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
inputScript(libsurl + '/openlayers/ol3-echarts/1.3.6/ol3Echarts.min.js');
9090
}
9191
if (inArray(includes, 'ol-mapbox-style')) {
92-
inputScript(libsurl + '/openlayers/plugins/ol-mapbox-style/2.11.2-5/olms.js');
92+
inputScript(libsurl + '/openlayers/plugins/ol-mapbox-style/2.11.2-6/olms.js');
9393
}
9494
if (inArray(includes, 'deck')) {
9595
inputScript(libsurl + '/deck.gl/5.1.3/deck.gl.min.js');

src/common/iServer/InitMapServiceBase.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* Copyright© 2000 - 2024 SuperMap Software Co.Ltd. All rights reserved.
22
* This program are made available under the terms of the Apache License, Version 2.0
33
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
4-
import { scaleToResolution, getZoomByResolution } from '../util/MapCalculateUtil';
4+
import { scaleToResolution, getZoomByResolution } from '../util/MapCalculateUtil';
55

66
/**
77
* @private
@@ -113,9 +113,15 @@ export function getEpsgCode(prjCoordSys) {
113113
* @description mapboxgl maplibregl 获取地图resolutions。
114114
* @returns {Array} resolutions
115115
*/
116-
export function scalesToResolutions(bounds, maxZoom = 22, tileSize = 512) {
116+
export function extentToResolutions(bounds, maxZoom = 22, tileSize = 512) {
117117
var resolutions = [];
118-
const maxReolution = Math.abs(bounds.left - bounds.right) / tileSize;
118+
var left = bounds.left;
119+
var right = bounds.right;
120+
if (Array.isArray(bounds)) {
121+
left = bounds[0];
122+
right = bounds[2];
123+
}
124+
const maxReolution = Math.abs(left - right) / tileSize;
119125
for (let i = 0; i < maxZoom; i++) {
120126
resolutions.push(maxReolution / Math.pow(2, i));
121127
}
@@ -135,7 +141,7 @@ export function getEpsgCode(prjCoordSys) {
135141
* @param {Object} extent - extent。
136142
* @returns {number} zoom
137143
*/
138-
export function getZoom({ scale, dpi, coordUnit }, extent) {
139-
const resolutions = scalesToResolutions(extent);
144+
export function getZoom({ scale, dpi, coordUnit }, extent) {
145+
const resolutions = extentToResolutions(extent);
140146
return getZoomByResolution(scaleToResolution(scale, dpi, coordUnit), resolutions);
141147
}

src/openlayers/mapping/WebMap.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -4818,11 +4818,24 @@ export class WebMap extends Observable {
48184818
const envelope = this.getEnvelope(indexbounds, layerInfo.bounds);
48194819
const styleResolutions = this.getStyleResolutions(envelope);
48204820
// const origin = [envelope.left, envelope.top];
4821-
let baseUrl = layerInfo.url && layerInfo.url.split('?')[0];
4821+
let baseUrl = layerInfo.url;
4822+
let paramUrl = baseUrl.split('?')[1];
48224823
let spriteUrl = styles.sprite;
48234824
if (!CommonUtil.isAbsoluteURL(styles.sprite)) {
48244825
spriteUrl = CommonUtil.relative2absolute(styles.sprite, baseUrl);
48254826
}
4827+
if (layerInfo.dataSource.type === 'ARCGIS_VECTORTILE') {
4828+
Object.keys(styles.sources).forEach(function (key) {
4829+
Object.keys(styles.sources[key]).forEach(function(fieldName) {
4830+
if (fieldName === 'url') {
4831+
if (typeof styles.sources[key][fieldName] === 'string' && !CommonUtil.isAbsoluteURL(styles.sources[key][fieldName])) {
4832+
styles.sources[key][fieldName] = CommonUtil.relative2absolute(styles.sources[key][fieldName], baseUrl);
4833+
}
4834+
styles.sources[key][fieldName] = styles.sources[key][fieldName] + (paramUrl ? '?' + paramUrl + '&f=json' : '?f=json');
4835+
}
4836+
});
4837+
});
4838+
}
48264839
let withCredentials = this.isIportalProxyServiceUrl(spriteUrl);
48274840
// 创建MapBoxStyle样式
48284841
let mapboxStyles = new MapboxStyles({

src/openlayers/overlay/VectorTileSuperMapRest.js

+8
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ export class VectorTileSuperMapRest extends VectorTile {
309309
const response = await FetchRequest.get(url, null, {
310310
withCredentials: options.withCredentials
311311
});
312+
this.baseUrl = url;
312313
style = await response.json();
313314
}
314315
await this._fillByStyleJSON(style, options.source);
@@ -323,11 +324,15 @@ export class VectorTileSuperMapRest extends VectorTile {
323324
}
324325
if (style.sources && style.sources[source]) {
325326
let newUrl;
327+
let paramUrl = this.baseUrl && this.baseUrl.split('?')[1];
326328
if (style.sources[source].tiles) {
327329
newUrl = style.sources[source].tiles[0];
328330
if (!CommonUtil.isAbsoluteURL(newUrl)) {
329331
newUrl = CommonUtil.relative2absolute(newUrl, this.baseUrl);
330332
}
333+
if (paramUrl) {
334+
newUrl = CommonUtil.urlAppend(newUrl, paramUrl);
335+
}
331336
} else if (style.sources[source].url) {
332337
let tiles = style.sources[source].url;
333338
if (!CommonUtil.isAbsoluteURL(tiles)) {
@@ -340,6 +345,9 @@ export class VectorTileSuperMapRest extends VectorTile {
340345
tileUrl = CommonUtil.relative2absolute(tileUrl, tiles);
341346
}
342347
newUrl = SecurityManager.appendCredential(tileUrl);
348+
if (paramUrl) {
349+
newUrl = CommonUtil.urlAppend(newUrl, paramUrl);
350+
}
343351
}
344352
this._tileUrl = SecurityManager.appendCredential(newUrl);
345353
}

src/openlayers/overlay/vectortile/MapboxStyles.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -377,26 +377,34 @@ export class MapboxStyles extends Observable {
377377
return parts ? parts[1] + extension + (parts.length > 2 ? parts[2] : '') : url + extension;
378378
}
379379

380-
_handleRelativeUrl(styles, baseUrl) {
381-
if (!baseUrl) {
380+
_handleRelativeUrl(styles, url) {
381+
if (!url) {
382382
return styles;
383383
}
384+
const baseUrl = url.split('?')[0];
385+
const paramUrl = url.split('?')[1] || '';
384386
Object.keys(styles).forEach((fieldName) => {
385387
if (fieldName === 'sources') {
386388
Object.keys(styles[fieldName]).forEach((sourceName) => {
387-
this._handleRelativeUrl(styles[fieldName][sourceName], baseUrl);
389+
this._handleRelativeUrl(styles[fieldName][sourceName], url);
388390
})
389391
}
390392
if (fieldName === 'sprite' || fieldName === 'glyphs' || fieldName === 'url') {
391393
if (styles[fieldName] && typeof styles[fieldName] === 'string' && !CommonUtil.isAbsoluteURL(styles[fieldName])) {
392394
styles[fieldName] = CommonUtil.relative2absolute(styles[fieldName], baseUrl);
393395
}
396+
if (paramUrl && !styles[fieldName].includes(paramUrl)) {
397+
styles[fieldName] = styles[fieldName] + (paramUrl ? (styles[fieldName].includes('?') ? '&' + paramUrl : '?' + paramUrl) : '');
398+
}
394399
}
395400
if (fieldName === 'tiles' && Array.isArray(styles[fieldName])) {
396401
styles[fieldName].forEach((tile) => {
397402
if (!CommonUtil.isAbsoluteURL(tile)) {
398403
tile = CommonUtil.relative2absolute(tile, baseUrl);
399404
}
405+
if (paramUrl && !tile.includes(paramUrl)) {
406+
tile = tile + (paramUrl ? (styles[fieldName].includes('?') ? '&' + paramUrl : '?' + paramUrl) : '');
407+
}
400408
})
401409
}
402410
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { extentToResolutions } from '../../../src/common/iServer/InitMapServiceBase';
2+
3+
describe('extentToResolutions', () => {
4+
it('should calculate resolutions for a given bounding box', () => {
5+
const bounds = { left: -180, right: 180 };
6+
const resolutions = extentToResolutions(bounds);
7+
expect(resolutions.length).toBe(22);
8+
expect(resolutions[0]).toBeCloseTo(0.703125);
9+
expect(resolutions[21]).toBeCloseTo(0.00000686328125);
10+
});
11+
12+
it('should handle array bounds input', () => {
13+
const bounds = [-180, -90, 180, 90];
14+
const resolutions = extentToResolutions(bounds);
15+
expect(resolutions.length).toBe(22);
16+
expect(resolutions[0]).toBeCloseTo(0.703125);
17+
expect(resolutions[21]).toBeCloseTo(0.00000686328125);
18+
});
19+
20+
it('should handle custom maxZoom and tileSize', () => {
21+
const bounds = { left: -180, right: 180 };
22+
const resolutions = extentToResolutions(bounds, 10, 256);
23+
expect(resolutions.length).toBe(10);
24+
expect(resolutions[0]).toBeCloseTo(1.40625);
25+
expect(resolutions[9]).toBeCloseTo(0.00146484375);
26+
});
27+
28+
it('should handle zero width bounds', () => {
29+
const bounds = { left: 0, right: 0 };
30+
const resolutions = extentToResolutions(bounds);
31+
expect(resolutions.length).toBe(22);
32+
expect(resolutions[0]).toBe(0);
33+
});
34+
35+
it('should handle negative width bounds', () => {
36+
const bounds = { left: 180, right: -180 };
37+
const resolutions = extentToResolutions(bounds);
38+
expect(resolutions.length).toBe(22);
39+
expect(resolutions[0]).toBeCloseTo(0.703125);
40+
expect(resolutions[21]).toBeCloseTo(0.00000686328125);
41+
});
42+
});

test/openlayers/overlay/vectortile/MapboxStylesSpec.js

+54
Original file line numberDiff line numberDiff line change
@@ -309,4 +309,58 @@ describe("openlayers_MapboxStyles", () => {
309309
}
310310
});
311311
});
312+
313+
it("handle relative url with param", done => {
314+
spyOn(XMLHttpRequest.prototype, 'send').and.callThrough();
315+
spyOn(XMLHttpRequest.prototype, 'setRequestHeader').and.callThrough();
316+
var style = {
317+
"version" : 8,
318+
"sprite" : "../sprites/sprite",
319+
"glyphs" : "../fonts/{fontstack}/{range}.pbf",
320+
"sources": {
321+
"esri": {
322+
"type": "vector",
323+
"url": "../../"
324+
}
325+
},
326+
"layers" : [{
327+
"id" : "Contour_11_main/0",
328+
"type" : "line",
329+
"source" : "esri",
330+
"source-layer" : "Contour",
331+
"filter" : ["all", ["==", "Index3", 1], ["==", "Index5", 1]],
332+
"minzoom" : 11,
333+
"maxzoom" : 12,
334+
"paint" : {
335+
"line-color" : "#61674a",
336+
"line-opacity" : 0.5,
337+
"line-width" : {
338+
"base" : 1.2,
339+
"stops" : [[11, 0.7], [16, 1.1]]
340+
}
341+
}
342+
}]
343+
}
344+
mapboxStyles = new MapboxStyles({
345+
style: style,
346+
baseUrl: 'http://localhost:9876?tkk=ddddssss',
347+
map: map,
348+
source: "California",
349+
headers:{'appToken':'test'}
350+
});
351+
mapboxStyles.on("styleloaded", () => {
352+
try {
353+
style = mapboxStyles.getStyleFunction();
354+
expect(style).not.toBeNull();
355+
expect(mapboxStyles._mbStyle.glyphs).toBe('http://localhost:9876/fonts/{fontstack}/{range}.pbf?tkk=ddddssss');
356+
expect(mapboxStyles._mbStyle.sprite).toBe('http://localhost:9876/sprites/sprite?tkk=ddddssss');
357+
expect(mapboxStyles._mbStyle.sources['esri']['url']).toBe('http://localhost:9876/?tkk=ddddssss');
358+
done();
359+
} catch (e) {
360+
console.log("'init_Style_headers'案例失败" + e.name + ":" + e.message);
361+
expect(false).toBeTruthy();
362+
done();
363+
}
364+
});
365+
});
312366
});

test/test-main-common.js

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import './common/iServer/GetLayersInfoServiceSpec.js';
4646
import './common/iServer/GetLayersLegendInfoServiceSpec.js';
4747
import './common/iServer/GridSpec.js';
4848
import './common/iServer/ImageSpec.js';
49+
import './common/iServer/InitMapServiceBaseSpec.js';
4950
import './common/iServer/InterpolationAnalystServiceSpec.js';
5051
import './common/iServer/LabelImageCellSpec.js';
5152
import './common/iServer/LabelMixedStyleSpec.js';

0 commit comments

Comments
 (0)