1
13693261870
2022-09-16 762f2fb45db004618ba099aa3c0bd89dba1eb843
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
define(["dojo/_base/declare", "esri/layers/ArcGISTiledMapServiceLayer", "esri/tasks/GeometryService", "esri/geometry/Point"], function (declare, ArcGISTiledMapServiceLayer, GeometryService, Point) {
    var clazz;
    clazz = declare("Utils", null, {
        constructor: function () {},
        createBaseMapLayer: function (layerId, layerURL, isVisible) {
            var layer = map.getLayer(layerId);
            if (!layer) {
                layer = new ArcGISTiledMapServiceLayer(layerURL, {
                    id: layerId,
                    visible: isVisible,
                    layerType: "basemap"
                })
            }
            return layer
        },
        createGeometryService: function (layerURL) {
            var service = new GeometryService(layerURL);
            return service
        },
        lonlat2mercator: function (lonlat) {
            var mercator = {
                x: 0,
                y: 0
            };
            var x = lonlat.x * 20037508.34 / 180;
            var y = Math.log(Math.tan((90 + lonlat.y) * Math.PI / 360)) / (Math.PI / 180);
            y = y * 20037508.34 / 180;
            mercator.x = x;
            mercator.y = y;
            return mercator
        },
        mercator2lonlat: function (mercator) {
            var lonlat = {
                x: 0,
                y: 0
            };
            var x = mercator.x / 20037508.34 * 180;
            var y = mercator.y / 20037508.34 * 180;
            y = 180 / Math.PI * (2 * Math.atan(Math.exp(y * Math.PI / 180)) - Math.PI / 2);
            lonlat.x = x;
            lonlat.y = y;
            return lonlat
        },
        getDistance: function (x1, y1, x2, y2) {
            var point1 = new Point(x1, y1, map.spatialReference);
            var point2 = new Point(x2, y2, map.spatialReference);
            var dis = esri.geometry.getLength(point1, point2);
            return dis
        },
        getStringGeo: function (points) {
            var pointReg;
            pointReg = /(\d+.?\d*)\s+(\d+.?\d*)/g;
            var lineReg = /\((\s?\d+\.\d*\s+\d+\.\d*\,?)+\)/g;
            var graphicReg;
            graphicReg = /(\((((\(((\d+.?\d*)\s+(\d+.?\d*),?)+\)),?)+),?\)),?/g;
            var wkid = 4326;
            if (points.indexOf("POINT") == 0) {
                var pr = [],
                    pt = [],
                    prarr = [];
                if (points.indexOf("-") > -1) {
                    points = points.replace("POINT  (", "").replace(")", "");
                    var x1 = points.split(" ")[0];
                    var y1 = points.split(" ")[1];
                    pr.push(parseFloat(x1));
                    pr.push(parseFloat(y1));
                } else {
                    var pointResult = pointReg.exec(points);
                    pr.push(parseFloat(pointResult[1]));
                    pr.push(parseFloat(pointResult[2]));
                }
                pt.push(pr);
                prarr.push(pt);
                return prarr;
            } else if (points.indexOf("LINESTRING") == 0 || points.indexOf("MULTILINESTRING") == 0) {
                var paths = new Array();
                var lineResult = lineReg.exec(points);
                while (lineResult != null) {
                    var path = new Array();
                    var pathResult = pointReg.exec(lineResult[0]);
                    while (pathResult) {
                        var pathPoint = new Array();
                        pathPoint.push(Number(pathResult[1]));
                        pathPoint.push(Number(pathResult[2]));
                        path.push(pathPoint);
                        pathResult = pointReg.exec(lineResult[0])
                    }
                    paths.push(path);
                    lineResult = lineReg.exec(points)
                }
                return paths;
            } else if (points.indexOf("POLYGON") == 0 || points.indexOf("MULTIPOLYGON") == 0) {
                var rings;
                rings = new Array();
                var polygonResult = lineReg.exec(points);
                while (polygonResult != null) {
                    var ring;
                    ring = new Array();
                    var ringResult;
                    ringResult = pointReg.exec(polygonResult[0]);
                    while (ringResult) {
                        var ringPoint = new Array();
                        ringPoint.push(Number(ringResult[1]));
                        ringPoint.push(Number(ringResult[2]));
                        ring.push(ringPoint);
                        ringResult = pointReg.exec(polygonResult[0])
                    }
                    rings.push(ring);
                    polygonResult = lineReg.exec(points)
                }
                return rings;
            }
            return null
        }
    });
    clazz.getInstance = function () {
        if (instance === null) {
            instance = new clazz()
        }
        return instance
    };
    return clazz
});