55import { GeoJSON as GeoJSONFormat } from '@supermap/iclient-common/format/GeoJSON' ;
66import { getMeterPerMapUnit as MeterPerMapUnit } from '@supermap/iclient-common/util/MapCalculateUtil' ;
77
8- /**
9- *@name Util
10- *@namespace
8+ /**
9+ *@function toGeoJSON
1110 *@category BaseTypes Util
12- *@description 工具类。
11+ *@description 将传入对象转为 GeoJSON 格式。
12+ *@param {Object } feature - 待转参数。
1313 *@usage
1414 * ```
1515 * // 浏览器
1616 * <script type="text/javascript" src="{cdn}"></script>
1717 * <script>
18- *const util = {namespace}.Util;
18+ * {namespace}.Util.toGeoJSON(feature) ;
1919 *
2020 * </script>
21+ *
2122 * // ES6 Import
22- * import {Util } from '{npm}';
23+ * import {toGeoJSON } from '{npm}';
2324 *
25+ * toGeoJSON(feature);
2426 * ```
2527 */
26- export var toGeoJSON = function ( feature ) {
28+ export var toGeoJSON = function ( feature ) {
2729if ( ! feature ) {
2830return feature ;
2931}
3032return new GeoJSONFormat ( ) . toGeoJSON ( feature ) ;
3133} ;
34+
35+ /**
36+ *@function toSuperMapGeometry
37+ *@category BaseTypes Util
38+ *@description 将 GeoJSON 对象转为 SuperMap 几何图形。
39+ *@param {GeoJSONObject } geometry - GeoJSON 对象。
40+ *@usage
41+ * ```
42+ * // 浏览器
43+ * <script type="text/javascript" src="{cdn}"></script>
44+ * <script>
45+ * {namespace}.Util.toSuperMapGeometry(geometry);
46+ *
47+ * </script>
48+ *
49+ * // ES6 Import
50+ * import { toSuperMapGeometry } from '{npm}';
51+ *
52+ * toSuperMapGeometry(geometry);
53+ * ```
54+ */
3255export var toSuperMapGeometry = function ( geometry ) {
3356if ( ! geometry ) {
3457return geometry ;
@@ -59,6 +82,30 @@ export var toSuperMapGeometry = function(geometry) {
5982} ;
6083export var getMeterPerMapUnit = MeterPerMapUnit ;
6184
85+
86+ /**
87+ *@function resolutionToScale
88+ *@category BaseTypes Util
89+ *@description 通过分辨率计算比例尺。
90+ *@param {number } resolution - 分辨率。
91+ *@param {number } dpi - 屏幕分辨率。
92+ *@param {string } mapUnit - 地图单位。
93+ *@returns {number } 比例尺。
94+ *@usage
95+ * ```
96+ * // 浏览器
97+ * <script type="text/javascript" src="{cdn}"></script>
98+ * <script>
99+ * {namespace}.Util.resolutionToScale(resolution, dpi, mapUnit);
100+ *
101+ * </script>
102+ *
103+ * // ES6 Import
104+ * import { resolutionToScale } from '{npm}';
105+ *
106+ * resolutionToScale(resolution, dpi, mapUnit);
107+ * ```
108+ */
62109export var resolutionToScale = function ( resolution , dpi , mapUnit ) {
63110var inchPerMeter = 1 / 0.0254 ;
64111// 地球半径。
@@ -67,6 +114,30 @@ export var resolutionToScale = function(resolution, dpi, mapUnit) {
67114scale = 1 / scale ;
68115return scale ;
69116} ;
117+
118+ /**
119+ *@function scaleToResolution
120+ *@category BaseTypes Util
121+ *@description 通过比例尺计算分辨率。
122+ *@param {number } scale - 比例尺。
123+ *@param {number } dpi - 屏幕分辨率。
124+ *@param {string } mapUnit - 地图单位。
125+ *@returns {number } 分辨率。
126+ *@usage
127+ * ```
128+ * // 浏览器
129+ * <script type="text/javascript" src="{cdn}"></script>
130+ * <script>
131+ * {namespace}.Util.scaleToResolution(scale, dpi, mapUnit);
132+ *
133+ * </script>
134+ *
135+ * // ES6 Import
136+ * import { scaleToResolution } from '{npm}';
137+ *
138+ * scaleToResolution(scale, dpi, mapUnit);
139+ * ```
140+ */
70141export var scaleToResolution = function ( scale , dpi , mapUnit ) {
71142var inchPerMeter = 1 / 0.0254 ;
72143var meterPerMapUnitValue = getMeterPerMapUnit ( mapUnit ) ;
@@ -75,10 +146,55 @@ export var scaleToResolution = function(scale, dpi, mapUnit) {
75146return resolution ;
76147} ;
77148
149+ /**
150+ *@function NormalizeScale
151+ *@category BaseTypes Util
152+ *@description 转换比例尺。
153+ *@param {number } scale - 比例尺。
154+ *@returns {number } 正常的 scale 值。
155+ *@usage
156+ * ```
157+ * // 浏览器
158+ * <script type="text/javascript" src="{cdn}"></script>
159+ * <script>
160+ * {namespace}.Util.NormalizeScale(scale);
161+ *
162+ * </script>
163+ *
164+ * // ES6 Import
165+ * import { NormalizeScale } from '{npm}';
166+ *
167+ * NormalizeScale(scale);
168+ * ```
169+ */
78170export var NormalizeScale = function ( scale ) {
79171return scale > 1.0 ?1.0 / scale :scale ;
80172} ;
81173
174+ /**
175+ *@function GetResolutionFromScaleDpi
176+ *@category BaseTypes Util
177+ *@description 根据比例尺和 dpi 计算屏幕分辨率。
178+ *@param {number } scale - 比例尺。
179+ *@param {number } dpi - 图像分辨率,表示每英寸内的像素个数。
180+ *@param {string } [coordUnit] - 投影坐标系统的地图单位。
181+ *@param {number } [datumAxis=6378137] - 地理坐标系统椭球体长半轴。用户自定义地图的 Options 时,若未指定该参数的值,则 DPI 默认按照 WGS84 参考系的椭球体长半轴 6378137 来计算。
182+ *@returns {number } 当前比例尺下的屏幕分辨率。
183+ *@usage
184+ * ```
185+ * // 浏览器
186+ * <script type="text/javascript" src="{cdn}"></script>
187+ * <script>
188+ * {namespace}.Util.GetResolutionFromScaleDpi(scale, dpi, coordUnit, datumAxis);
189+ *
190+ * </script>
191+ *
192+ * // ES6 Import
193+ * import { GetResolutionFromScaleDpi } from '{npm}';
194+ *
195+ * GetResolutionFromScaleDpi(scale, dpi, coordUnit, datumAxis);
196+ * ```
197+ */
82198export var GetResolutionFromScaleDpi = function ( scale , dpi , coordUnit , datumAxis ) {
83199var resolution = null ,
84200ratio = 10000 ;