Skip to content

Commit 0367cb4

Browse files
common mapcalculateutil 新增方法 review by luox
1 parent 95e922f commit 0367cb4

File tree

4 files changed

+105
-47
lines changed

4 files changed

+105
-47
lines changed

src/common/format/JSON.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ export class JSONFormat extends Format {
234234
object = JSON.parse(json, filter);
235235
} catch (e) {
236236
// Fall through if the regexp test fails.
237+
return { data: json}
237238
}
238239
}
239240

src/common/iServer/CommonServiceBase.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export class CommonServiceBase {
143143
options.crossOrigin = options.crossOrigin != undefined ? options.crossOrigin : me.crossOrigin;
144144
options.headers = options.headers || me.headers;
145145
options.isInTheSameDomain = me.isInTheSameDomain;
146+
options.withoutFormatSuffix = options.scope.withoutFormatSuffix || false;
146147
//为url添加安全认证信息片段
147148
options.url = SecurityManager.appendCredential(options.url);
148149

@@ -277,6 +278,7 @@ export class CommonServiceBase {
277278
}
278279
FetchRequest.commit(options.method, options.url, options.params, {
279280
headers: options.headers,
281+
withoutFormatSuffix: options.withoutFormatSuffix,
280282
withCredentials: options.withCredentials,
281283
crossOrigin: options.crossOrigin,
282284
timeout: options.async ? 0 : null,

src/common/util/MapCalculateUtil.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,42 @@ export function conversionDegree(degrees) {
111111
second = parseInt(second / 10) === 0 ? `0${second}` : second;
112112
return `${degree}°${fraction}'${second}`;
113113
}
114+
115+
export function scalesToResolutions(scales, bounds, dpi, unit, level = 22) {
116+
var resolutions = [];
117+
if (scales && scales.length > 0) {
118+
for (let i = 0; i < scales.length; i++) {
119+
resolutions.push(scaleToResolution(scales[i], dpi, unit));
120+
}
121+
} else {
122+
const maxReolution = Math.abs(bounds.left - bounds.right) / 256;
123+
for (let i = 0; i < level; i++) {
124+
resolutions.push(maxReolution / Math.pow(2, i));
125+
}
126+
}
127+
return resolutions.sort(function (a, b) {
128+
return b - a;
129+
});
130+
}
131+
132+
export function getZoomByResolution(resolution, resolutions) {
133+
let zoom = 0;
134+
let minDistance;
135+
for (let i = 0; i < resolutions.length; i++) {
136+
if (i === 0) {
137+
minDistance = Math.abs(resolution - resolutions[i]);
138+
}
139+
if (minDistance > Math.abs(resolution - resolutions[i])) {
140+
minDistance = Math.abs(resolution - resolutions[i]);
141+
zoom = i;
142+
}
143+
}
144+
return zoom;
145+
}
146+
147+
export function scaleToResolution(scale, dpi, mapUnit) {
148+
const inchPerMeter = 1 / 0.0254;
149+
const meterPerMapUnitValue = getMeterPerMapUnit(mapUnit);
150+
const resolution = 1 / (scale * dpi * inchPerMeter * meterPerMapUnitValue);
151+
return resolution;
152+
}

src/openlayers/services/MapService.js

Lines changed: 63 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
/* Copyright© 2000 - 2022 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 {ServiceBase} from './ServiceBase';
4+
import { ServiceBase } from './ServiceBase';
55
import { MapService as CommonMapService } from '@supermap/iclient-common/iServer/MapService';
66
import { TilesetsService } from '@supermap/iclient-common/iServer/TilesetsService';
7-
87
/**
98
* @class MapService
109
* @category iServer Map
@@ -23,52 +22,69 @@ import { TilesetsService } from '@supermap/iclient-common/iServer/TilesetsServic
2322
* @usage
2423
*/
2524
export class MapService extends ServiceBase {
25+
constructor(url, options) {
26+
super(url, options);
27+
}
2628

27-
constructor(url, options) {
28-
super(url, options);
29-
}
29+
/**
30+
* @function MapService.prototype.getMapInfo
31+
* @description 地图信息查询服务。
32+
* @param {RequestCallback} callback - 回调函数。
33+
* @returns {MapService} 获取服务信息。
34+
*/
35+
getMapInfo(callback) {
36+
var me = this;
37+
var getMapStatusService = new CommonMapService(me.url, {
38+
proxy: me.options.proxy,
39+
withCredentials: me.options.withCredentials,
40+
crossOrigin: me.options.crossOrigin,
41+
headers: me.options.headers,
42+
eventListeners: {
43+
scope: me,
44+
processCompleted: callback,
45+
processFailed: callback
46+
},
47+
projection: me.options.projection
48+
});
49+
getMapStatusService.processAsync();
50+
}
3051

31-
/**
32-
* @function MapService.prototype.getMapInfo
33-
* @description 地图信息查询服务。
34-
* @param {RequestCallback} callback - 回调函数。
35-
* @returns {MapService} 获取服务信息。
36-
*/
37-
getMapInfo(callback) {
38-
var me = this;
39-
var getMapStatusService = new CommonMapService(me.url, {
40-
proxy: me.options.proxy,
41-
withCredentials: me.options.withCredentials,
42-
crossOrigin: me.options.crossOrigin,
43-
headers: me.options.headers,
44-
eventListeners: {
45-
scope: me,
46-
processCompleted: callback,
47-
processFailed: callback
48-
}, projection: me.options.projection
49-
});
50-
getMapStatusService.processAsync();
51-
}
52+
getWkt(callback) {
53+
var me = this;
54+
var getMapStatusService = new CommonMapService(`${me.url}/prjCoordSys.wkt`, {
55+
proxy: me.options.proxy,
56+
withCredentials: me.options.withCredentials,
57+
withoutFormatSuffix: true,
58+
crossOrigin: me.options.crossOrigin,
59+
headers: me.options.headers,
60+
eventListeners: {
61+
scope: me,
62+
processCompleted: callback,
63+
processFailed: callback
64+
}, projection: me.options.projection
65+
});
66+
getMapStatusService.processAsync();
67+
}
5268

53-
/**
54-
* @function MapService.prototype.getTilesets
55-
* @description 切片列表信息查询服务。
56-
* @param {RequestCallback} callback - 回调函数。
57-
* @returns {MapService} 获取服务信息。
58-
*/
59-
getTilesets(callback) {
60-
var me = this;
61-
var tilesetsService = new TilesetsService(me.url, {
62-
proxy: me.options.proxy,
63-
withCredentials: me.options.withCredentials,
64-
crossOrigin: me.options.crossOrigin,
65-
headers: me.options.headers,
66-
eventListeners: {
67-
scope: me,
68-
processCompleted: callback,
69-
processFailed: callback
70-
}
71-
});
72-
tilesetsService.processAsync();
73-
}
69+
/**
70+
* @function MapService.prototype.getTilesets
71+
* @description 切片列表信息查询服务。
72+
* @param {RequestCallback} callback - 回调函数。
73+
* @returns {MapService} 获取服务信息。
74+
*/
75+
getTilesets(callback) {
76+
var me = this;
77+
var tilesetsService = new TilesetsService(me.url, {
78+
proxy: me.options.proxy,
79+
withCredentials: me.options.withCredentials,
80+
crossOrigin: me.options.crossOrigin,
81+
headers: me.options.headers,
82+
eventListeners: {
83+
scope: me,
84+
processCompleted: callback,
85+
processFailed: callback
86+
}
87+
});
88+
tilesetsService.processAsync();
89+
}
7490
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy