3
13693261870
2022-09-16 63ba114e70e380442fcbed4a5157ee52c9491216
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
define(["dojo/_base/declare", "esri/toolbars/draw", "esri/symbols/SimpleMarkerSymbol", "esri/symbols/SimpleLineSymbol", "esri/symbols/SimpleFillSymbol", "esri/symbols/PictureFillSymbol", "esri/symbols/CartographicLineSymbol", "esri/graphic", "esri/Color", "dojo/dom", "dojo/on", "dojo/request", "esri/InfoTemplate", "esri/symbols/PictureMarkerSymbol", "esri/graphic", "esri/layers/GraphicsLayer", "esri/geometry/Point", "esri/geometry/Multipoint", "esri/geometry/Polyline", "esri/geometry/Polygon", ], function (declare, Draw, SimpleMarkerSymbol, SimpleLineSymbol, SimpleFillSymbol, PictureFillSymbol, CartographicLineSymbol, Graphic, Color, dom, on, request, InfoTemplate, PictureMarkerSymbol, Graphic, GraphicsLayer, Point, Multipoint, Polyline, Polygon) {
    var clazz, tb;
    clazz = declare("Plot", null, {
        constructor: function () {},
        plottools: function (tool) {
            isTools = true;
            tb = new Draw(map);
            tb.on("draw-end", this.addGraphic);
            map.disableMapNavigation();
            tb.activate(tool)
        },
        createLayer: function () {
            var temp = map.getLayer("plotLayer");
            temp.clear()
        },
        addGraphic: function (evt) {
            tb.deactivate();
            map.enableMapNavigation();
            var symbol;
            switch (evt.geometry.type) {
                case "point":
                    symbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, plotPointSize, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color(plotLineColor), 1), new dojo.Color(plotPointColor));
                    break;
                case "polyline":
                    symbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color(plotLineColor), plotLineSize);
                    break;
                case "polygon":
                    symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT, new dojo.Color(plotLineColor), 2), new dojo.Color(plotPolygonColor));
                    break;
                case "extent":
                    symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT, new dojo.Color(plotLineColor), 2), new dojo.Color(plotPolygonColor));
                    break;
                case "multipoint":
                    symbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_DIAMOND, plotPointSize, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0, 0, 0]), 1), new dojo.Color(plotPointColor));
                    break
            }
            plotGraphicLayer.add(new Graphic(evt.geometry, symbol))
        },
        removeAllLayer: function () {
            var temp = map.getLayer("plotLayer");
            temp.clear();
            plotOperate = -1
        },
        revocationLayer: function () {
            var temp = map.getLayer("plotLayer");
            temp.remove(temp.graphics[temp.graphics.length - 1])
        },
        savePlotPayer: function () {
            var olddata;
            $.ajax({
                url: 'data/plotLayer.json?' + Math.random(),
                type: 'GET',
                async: false,
                success: function (result) {
                    if (result != "" && result != null) {
                        olddata = result.replace(/[\r\n]/g, "");
                        olddata = olddata.substring(1, olddata.length - 1)
                    } else {
                        olddata = ""
                    }
                },
                error: function (e) {}
            });
            if ($("#plotLayerName").val() == null || $("#plotLayerName").val() == "") {
                alert("图层名不能为空!");
                return
            }
            var data = {};
            var datalength = -1;
            showPlotLayer = new GraphicsLayer();
            var temp = map.getLayer("plotLayer");
            temp.graphics.forEach(function (item, index) {
                showPlotLayer.add(item);
                var layerData = {
                    "geometry": item.geometry,
                    "symbol": item.symbol
                };
                data[index] = layerData;
                datalength = index + 1
            });
            var json;
            if (olddata == "") {
                json = "[" + olddata + "{ \"layername\":\"" + $("#plotLayerName").val() + "\",\"layerLength\":\"" + datalength + "\",\"datalist\": " + JSON.stringify(data) + " }]"
            } else {
                json = "[" + olddata + ",{ \"layername\":\"" + $("#plotLayerName").val() + "\",\"layerLength\":\"" + datalength + "\",\"datalist\": " + JSON.stringify(data) + " }]"
            }
            var datas = eval("[{\"Name\":\"" + encodeURIComponent(json) + "\"}]")[0];
            jQuery.ajax({
                type: "POST",
                async: true,
                url: 'data/Handler.ashx?' + Math.random() + '&action=SaveLayerData',
                data: datas,
                timeout: 600000,
                success: function (result) {
                    alert("保存成功!");
                    initLoadPage()
                },
                error: function (result) {
                    alert('保存失败!')
                }
            })
        },
        getPlotPayer: function (datalist) {
            this.createLayer();
            var data = datalist;
            for (var i = 0; i < parseInt(datalist.layerLength); i++) {
                if (data.datalist[i].geometry.type == "point") {
                    var point = new Point({
                        "x": data.datalist[i].geometry.x,
                        "y": data.datalist[i].geometry.y,
                        "spatialReference": {
                            "wkid": 102100,
                            "latestWkid": 3857
                        }
                    });
                    plotPointColor = data.datalist[i].symbol.color;
                    plotLineColor = data.datalist[i].symbol.outline.color;
                    plotPointSize = data.datalist[i].symbol.size;
                    var tgraphic = new Graphic(point);
                    tb = new Draw(map);
                    map.disableMapNavigation();
                    this.addGraphic(tgraphic)
                } else if (data.datalist[i].geometry.type == "multipoint") {
                    var multipoint = new Multipoint({
                        "points": data.datalist[i].geometry.points,
                        "spatialReference": {
                            "wkid": 102100,
                            "latestWkid": 3857
                        }
                    });
                    plotPointColor = data.datalist[i].symbol.color;
                    plotLineColor = data.datalist[i].symbol.outline.color;
                    plotPointSize = data.datalist[i].symbol.size;
                    var tgraphic = new Graphic(multipoint);
                    tb = new Draw(map);
                    map.disableMapNavigation();
                    this.addGraphic(tgraphic)
                } else if (data.datalist[i].geometry.type == "polyline") {
                    var polyline = new Polyline({
                        "paths": data.datalist[i].geometry.paths,
                        "spatialReference": {
                            "wkid": 102100,
                            "latestWkid": 3857
                        }
                    });
                    plotLineColor = data.datalist[i].symbol.color;
                    plotLineSize = data.datalist[i].symbol.width;
                    var tgraphic = new Graphic(polyline);
                    tb = new Draw(map);
                    map.disableMapNavigation();
                    this.addGraphic(tgraphic)
                } else if (data.datalist[i].geometry.type == "polygon") {
                    var polygon = new Polygon({
                        "rings": data.datalist[i].geometry.rings,
                        "spatialReference": {
                            "wkid": 102100,
                            "latestWkid": 3857
                        }
                    });
                    plotPolygonColor = data.datalist[i].symbol.color;
                    plotLineColor = data.datalist[i].symbol.outline.color;
                    var tgraphic = new Graphic(polygon);
                    tb = new Draw(map);
                    map.disableMapNavigation();
                    this.addGraphic(tgraphic)
                }
            }
        },
        getPlotData: function () {
            var data;
            $.ajax({
                url: 'data/plotLayer.json?' + Math.random(),
                type: 'GET',
                async: false,
                success: function (result) {
                    if (result != "") {
                        data = result.replace(/[\r\n]/g, "")
                    } else {
                        data = "[]"
                    }
                },
                error: function (e) {}
            });
            return data
        },
        deletePlotData: function (index) {
            var data = eval(this.getPlotData());
            data.splice(index, 1);
            var datas = eval("[{\"Name\":\"" + encodeURIComponent(JSON.stringify(data)) + "\"}]")[0];
            jQuery.ajax({
                type: "POST",
                async: true,
                url: 'data/Handler.ashx?' + Math.random() + '&action=SaveLayerData',
                data: datas,
                timeout: 600000,
                success: function (result) {
                    alert("删除成功!");
                    initLoadPage()
                },
                error: function (result) {
                    alert('删除失败!')
                }
            })
        }
    });
    clazz.getInstance = function () {
        if (instance === null) {
            instance = new clazz()
        }
        return instance
    };
    return clazz
});