此示例演示如何将自定义格式添加到坐标转换微件。在示例中,添加了两种自定义格式:
102241
描述。将此示例中的场景视图裁剪到 StatePlane California I 空间参考有用的程度。
用户定义的自定义格式需要定义一个转换函数和一个反向转换函数或一个空间参考和一个反向转换函数。如果提供了 SpatialReference,则不需要转换函数;几何服务将用于根据需要进行投影。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Regular expression to find a number
const numberSearchPattern = /-?\d+[\.]?\d*/;
const newFormat = new Format({
// The format's name should be unique with respect to other formats used by the widget
name: "XYZ",
conversionInfo: {
// Define a convert function
// Point -> Position
convert: function(point) {
const returnPoint = point.spatialReference.isWGS84
? point
: webMercatorUtils.webMercatorToGeographic(point);
const x = returnPoint.x.toFixed(4);
const y = returnPoint.y.toFixed(4);
const z = returnPoint.z.toFixed(4);
return {
location: returnPoint,
coordinate: `${x}, ${y}, ${z}`
};
},
// Define a reverse convert function
// String -> Point
reverseConvert: function(string) {
const parts = string.split(",");
return new Point({
x: parseFloat(parts[0]),
y: parseFloat(parts[1]),
z: parseFloat(parts[2]),
spatialReference: { wkid: 4326 }
});
}
},
// Define each segment of the coordinate
coordinateSegments: [
{
alias: "X",
description: "Longitude",
searchPattern: numberSearchPattern
},
{
alias: "Y",
description: "Latitude",
searchPattern: numberSearchPattern
},
{
alias: "Z",
description: "Elevation",
searchPattern: numberSearchPattern
}
],
defaultPattern: "X°, Y°, Z"
});
Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.