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
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
define(["dojo/_base/declare", "esri/toolbars/draw", "esri/graphic", "esri/tasks/query", "esri/tasks/QueryTask", "esri/graphic", "esri/symbols/SimpleLineSymbol", "esri/symbols/SimpleFillSymbol", "esri/symbols/SimpleMarkerSymbol", "esri/symbols/PictureFillSymbol", "esri/Color", "esri/layers/FeatureLayer", "esri/geometry/Point", "esri/geometry/Polygon", "esri/geometry/Circle", "esri/layers/GraphicsLayer"], function (declare, Draw, Graphic, Query, QueryTask, Graphic, SimpleLineSymbol, SimpleFillSymbol, SimpleMarkerSymbol, PictureFillSymbol, Color, FeatureLayer, Point, Polygon, Circle, GraphicsLayer) {
    var clazz, tb;
    clazz = declare("Draw", null, {
        constructor: function () { },
        drawtools: function (tool) {
            isTools = true;
            tb = new Draw(map);
            tb.on("draw-end", this.addGraphic);
            map.disableMapNavigation();
            tb.activate(tool);
            map.graphics.clear();
            var removeTempLayer = map.getLayer(10086);
            if (removeTempLayer != undefined) {
                map.removeLayer(removeTempLayer)
            }
        },
        addGraphic: function (evt) {
            tb.deactivate();
            map.enableMapNavigation();
            var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0, 0, 0]), 1), new dojo.Color([169, 169, 169, 0.2]));
            map.graphics.add(new Graphic(evt.geometry, symbol));
            var query = new Query();
            query.geometry = evt.geometry;
            query.outFields = ["*"];
            query.spatialRelationship = Query.SPATIAL_REL_INTERSECTS;
            query.returnGeometry = true;
            setRegionUrl("http://71.3.110.202:6080/arcgis/rest/services/HYHD/HD/MapServer/1");
            if (drawRegionUrl == "") {
                alert("请先选择要查询的图层");
                map.graphics.clear();
                return
            }
            var tempLayer = new FeatureLayer(drawRegionUrl, {
                id: "10086",
                visible: true
            });
            var queryTask = new QueryTask(drawRegionUrl);
            queryTask.execute(query, function (result) {
                var objectids = "";
                for (var i = 0; i < result.features.length; i++) {
                    objectids += result.features[i].attributes.OBJECTID.toString() + ","
                }
                drawRegion(evt.geometry, result.features);
                tempLayer.setDefinitionExpression("OBJECTID in (" + objectids.substring(0, objectids.length - 1) + ")");
                map.addLayer(tempLayer)
            });
            isTools = false
        },
        selectForParam: function (rings, center, radiu) {
            if (rings != null) {
                var polygon = new Polygon({
                    rings: [rings],
                    spatialReference: {
                        "wkid": 4326
                    }
                });
                var tgraphic = new Graphic(polygon);
                tb = new Draw(map);
                map.disableMapNavigation();
                this.addGraphic(tgraphic)
            } else if (center != null && radiu != null) {
                var circle = new Circle({
                    center: center,
                    radius: radius
                });
                var tgraphic = new Graphic(circle);
                tb = new Draw(map);
                map.disableMapNavigation();
                this.addGraphic(tgraphic)
            }
        },
        getCoordsByDraw: function (tool) {
            isTools = true;
            tb = new Draw(map);
            tb.on("draw-end", this.addEmptyGraphic);
            map.disableMapNavigation();
            tb.activate(tool);
            map.graphics.clear()
        },
        addEmptyGraphic: function (evt) {
            tb.deactivate();
            map.enableMapNavigation();
            symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 1), new dojo.Color([169, 169, 169, 0.2]));
            map.graphics.add(new Graphic(evt.geometry, symbol));
            isTools = false;
            callbackCoords(evt.geometry)
        },
        showRegionByCoords: function (tool, geometry, radius) {
            if (tool == "rectangle" || tool == "polygon") {
                var polygon = new Polygon({
                    rings: [eval(geometry)],
                    spatialReference: map.spatialReference
                });
                var tgraphic = new Graphic(polygon);
                tb = new Draw(map);
                map.disableMapNavigation();
                this.addEmptyGraphic(tgraphic)
            } else if (tool == "circle") {
                var point = new Point({
                    x: eval(geometry)[0][0],
                    y: eval(geometry)[0][1],
                    spatialReference: {
                        wkid: 102100,
                        latestWkid: 3857
                    }
                });
                var circle = new Circle({
                    center: point,
                    geodesic: false,
                    radius: parseFloat(radius)
                });
                var tgraphic = new Graphic(circle);
                tb = new Draw(map);
                map.disableMapNavigation();
                this.addEmptyGraphic(tgraphic)
            }
        },
        addEmptyGraphicToLayer: function (evt, layer) {
            tb.deactivate();
            map.enableMapNavigation();
            symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0, 100, 255]), 1), new dojo.Color([0, 169, 169, 0.9]));
            layer.add(new Graphic(evt.geometry, symbol));
            isTools = false;
            callbackCoords(evt.geometry)
        },
        showRegionByCoordsToLayer: function (tool, geometry, radius, layerId) {
 
            var tempLayer;
            if (map.graphicsLayerIds.indexOf(layerId) >= 0) {
                tempLayer = map.getLayer(layerId);
            } else {
                tempLayer = new GraphicsLayer({
                    id: layerId
                })
                map.addLayer(tempLayer);
            }
 
            if (tool == "rectangle" || tool == "polygon") {
                var polygon = new Polygon({
                    rings: [eval(geometry)],
                    spatialReference: map.spatialReference
                });
                var tgraphic = new Graphic(polygon);
                tb = new Draw(map);
                map.disableMapNavigation();
                this.addEmptyGraphicToLayer(tgraphic, tempLayer)
            } else if (tool == "circle") {
                var point = new Point({
                    x: eval(geometry)[0][0],
                    y: eval(geometry)[0][1],
                    spatialReference: {
                        wkid: 102100,
                        latestWkid: 3857
                    }
                });
                var circle = new Circle({
                    center: point,
                    geodesic: false,
                    radius: parseFloat(radius)
                });
                var tgraphic = new Graphic(circle);
                tb = new Draw(map);
                map.disableMapNavigation();
                this.addEmptyGraphicToLayer(tgraphic, tempLayer)
            }
        }
    });
    clazz.getInstance = function () {
        if (instance === null) {
            instance = new clazz()
        }
        return instance
    };
    return clazz
});