function toFullExtent() {
    goToZoom(0,0);
    m_view.zoom = 1
}
function btFullExtent_Click() {
    toFullExtent()
}

function ZoomIn(level) {

    if (level) {
        m_view.goTo({
            zoom: level
        });
    } else if (level == 0) {
        m_view.goTo({
            zoom: 0
        });
    } else {
        m_zoom.zoomIn();
    }

}
function ChangerExtent(xmax,xmin,ymax,ymin) {
	viewxmax=xmax;
	viewxmin=xmin;
	viewymin=ymin;
	viewymax=ymax;
     require(["esri/geometry/Extent", "Extent"],
        function (Extent) {
            m_view.extent = new Extent({
                xmin: xmin,
                ymin: ymin,
                xmax: xmax,
                ymax: ymax,
                spatialReference: m_view.spatialReference
            });
        });
	m_view.goTo({
            zoom: 0
        });
};
function btZoomIn_Click() {
    ZoomIn()
}
function btZoomOut_Click() {
    ZoomOut()
}
function ZoomOut(level) {

    if (level) {
        m_view.goTo({
            zoom: level
        });
    } else if (level == 0) {
        m_view.goTo({
            zoom: 0
        });
    } else {
        m_zoom.zoomOut();
    }


}
function btDrawPolygon_Click() {
    measureSquare()
}
function measureSquare() {
    measurePolygon(m_drawtool, m_view)
}
function measureLength() {
    if (currentMapMode == "2D") {
        measurePolyline(m_drawtool, m_view)
    } else {
        if (lengthMeasureWidget) {
            if (!lengthMeasureWidget.destroyed) {
                lengthMeasureWidget.destroy();
                return
            }
        }
        createLengthMeasureWidget()
    }
}
function goToCar(x,y) {
    require([
        "esri/geometry/Point"
    ], function (  Point ) {
        var point = new Point({
            x: x-0,
            y: y-0,
            spatialReference: m_view.spatialReference
        });
        m_view.goTo({
            target: point,
            zoom: 8
        })
    })

}
function btDrawPolyline_Click() {
    measureLength()
}
function createLengthMeasureWidget() {
    require(["esri/widgets/DirectLineMeasurement3D", "dojo/domReady!"],
        function (DirectLineMeasurement3D) {
            lengthMeasureWidget = new DirectLineMeasurement3D({
                view: m_view
            });
            m_view.ui.add(lengthMeasureWidget, "top-right");
        });
}

function measurePolylineByPoint(x, y, x1, y1) {
    var length;
    require(["esri/Map", "esri/views/MapView", "esri/layers/MapImageLayer", "esri/layers/TileLayer", "esri/geometry/Geometry", "esri/geometry/Extent", "esri/tasks/GeometryService", "esri/layers/GraphicsLayer", "esri/widgets/ScaleBar", "esri/WebMap", "esri/geometry/SpatialReference", "esri/Graphic", "esri/views/2d/draw/Draw", "esri/geometry/Polyline", "esri/geometry/geometryEngine"],
        function (Map, MapView, MapImageLayer, TileLayer, Geometry, Extent, GeometryService, GraphicsLayer, ScaleBar, WebMap, SpatialReference, Graphic, Draw, Polyline, geometryEngine) {
            var polyline = new Polyline({
                paths: [[x, y], [x1, y1]],
                spatialReference: 2379
            });
            length = geometryEngine.planarLength(polyline, "kilometers");
        });
    return length;
}

function measurePolyline(draw, view) {
    require(["esri/Map", "esri/views/MapView", "esri/layers/MapImageLayer", "esri/layers/TileLayer", "esri/geometry/Geometry", "esri/geometry/Extent", "esri/tasks/GeometryService", "esri/layers/GraphicsLayer", "esri/widgets/ScaleBar", "esri/WebMap", "esri/geometry/SpatialReference", "esri/Graphic", "esri/views/2d/draw/Draw", "esri/geometry/Polyline", "esri/geometry/geometryEngine"],
        function (Map, MapView, MapImageLayer, TileLayer, Geometry, Extent, GeometryService, GraphicsLayer, ScaleBar, WebMap, SpatialReference, Graphic, Draw, Polyline, geometryEngine) {
            var action = draw.create("polyline");
            view.focus();
            action.on("vertex-add", drawPolyline);
            action.on("cursor-update", drawPolyline);
            action.on("vertex-remove", drawPolyline);
            action.on("draw-complete", drawPolyline);
            function drawPolyline(evt) {
                var vertices = evt.vertices;
                btClear_Click();
                var polyline = createPolyline(vertices);
                var graphic = createGraphic(polyline);
                GraphicsLayer_DrawLayer.add(graphic);
                var length = geometryEngine.planarLength(polyline, "kilometers");
                if (length < 0) {
                    var simplifiedPolyline = geometryEngine.simplify(polyline);
                    if (simplifiedPolyline) {
                        if (currentMapMode == "2D") {
                            length = geometryEngine.planarLength(simplifiedPolyline, "kilometers")
                        } else {
                            length = geometryEngine.geodesicLength(simplifiedPolyline, "kilometers")
                        }
                    }
                }
                labelLength(polyline, length)
            }

            function createPolyline(vertices) {
                return new Polyline({
                    paths: vertices,
                    spatialReference: m_view.spatialReference
                })
            }

            function createGraphic(polyline) {
                graphic = new Graphic({
                    geometry: polyline,
                    symbol: {
                        type: "simple-line",
                        color: [178, 102, 234, .8],
                        width: 2
                    }
                });
                return graphic
            }

            function labelLength(geom, area) {
                var graphic = new Graphic({
                    geometry: geom.extent.center,
                    symbol: {
                        type: "text",
                        color: "black",
                        haloColor: "black",
                        haloSize: "1px",
                        text: area.toFixed(2) + " km",
                        xoffset: 3,
                        yoffset: 3,
                        font: {
                            size: 14,
                            family: "sans-serif"
                        }
                    }
                });
                GraphicsLayer_DrawLayer.add(graphic)
            }
        })
}
function measurePolygon(draw, view) {
    require(["esri/Map", "esri/views/MapView", "esri/layers/MapImageLayer", "esri/layers/TileLayer", "esri/geometry/Geometry", "esri/geometry/Extent", "esri/tasks/GeometryService", "esri/layers/GraphicsLayer", "esri/widgets/ScaleBar", "esri/WebMap", "esri/geometry/SpatialReference", "esri/Graphic", "esri/views/2d/draw/Draw", "esri/geometry/Polygon", "esri/geometry/geometryEngine"],
        function (Map, MapView, MapImageLayer, TileLayer, Geometry, Extent, GeometryService, GraphicsLayer, ScaleBar, WebMap, SpatialReference, Graphic, Draw, Polygon, geometryEngine) {
            var action = draw.create("polygon");
            view.focus();
            action.on("vertex-add", drawPolygon);
            action.on("cursor-update", drawPolygon);
            action.on("vertex-remove", drawPolygon);
            action.on("draw-complete", drawPolygon);
            function drawPolygon(evt) {
                var vertices = evt.vertices;
                btClear_Click();
                var polygon = createPolygon(vertices);
                var graphic = createGraphic(polygon);
                GraphicsLayer_DrawLayer.add(graphic);
                var area = geometryEngine.planarArea(polygon, "square-kilometers");
                if (area < 0) {
                    var simplifiedPolygon = geometryEngine.simplify(polygon);
                    if (simplifiedPolygon) {
                        if (currentMapMode == "2D") {
                            area = geometryEngine.planarArea(simplifiedPolygon, "square-kilometers")
                        } else {
                            area = geometryEngine.geodesicArea(simplifiedPolygon, "square-kilometers")
                        }
                    }
                }
                labelAreas(polygon, area)
            }

            function createPolygon(vertices) {
                return new Polygon({
                    rings: vertices,
                    spatialReference: m_view.spatialReference
                })
            }

            function createGraphic(polygon) {
                graphic = new Graphic({
                    geometry: polygon,
                    symbol: {
                        type: "simple-fill",
                        color: [178, 102, 234, .8],
                        style: "solid",
                        outline: {
                            color: [255, 255, 255],
                            width: 2
                        }
                    }
                });
                return graphic
            }

            function labelAreas(geom, area) {
                var graphic = new Graphic({
                    geometry: geom.centroid,
                    symbol: {
                        type: "text",
                        color: "black",
                        haloColor: "black",
                        haloSize: "1px",
                        text: area.toFixed(2) + " 平方千米",
                        xoffset: 3,
                        yoffset: 3,
                        font: {
                            size: 14,
                            family: "sans-serif"
                        }
                    }
                });
                GraphicsLayer_DrawLayer.add(graphic)
            }
        })
}
function btPrintPicture_Click() {
    downLoadPicture()
}
function downLoadPicture() {
    if (m_printTool) {
        if (!m_printTool.destroyed) {
            m_printTool.destroy();
            return
        }
    }
    require(["esri/widgets/Print"],
        function (Print) {
            m_printTool = new Print({
                view: m_view,
                printServiceUrl: GetConfigDataByName("PrintTaskURL")
            });
            m_view.ui.add(m_printTool, "top-right")
        })
}
function btPrintPicture_Click2() {
    require(["esri/tasks/PrintTask", "esri/tasks/support/PrintParameters", "esri/tasks/support/PrintTemplate"],
        function (PrintTask, PrintParameters, PrintTemplate) {
            var printTask = new PrintTask(GetConfigDataByName("PrintTaskURL"));
            var template = new PrintTemplate;
            template.exportOptions = {
                width: 1200,
                height: 700,
                dpi: 96
            };
            template.format = "JPG";
            template.layout = "MAP_ONLY";
            template.preserveScale = true;
            var params = new PrintParameters;
            params.view = m_view;
            params.template = template;
            printTask.execute(params).then(function (evt) {
                window.open(evt.url, "_blank")
            })
        })
}
function btGetGraphicByJson() {
    var jsonStr = '{"ExChangeRoot": {"Features": [' + ' { "type": "polygon", "featureName": "用地",  "Feature":[ {"Geometry": { "Rings": [{ "Ring": "1000,-1000|0,-1500|-1000,-1000|-1000,1000|1000,1000|2000,0" } ]},"Attribute": { "ID": "1", "地块面积": "100", "建筑限高": "20" }, "ToolTip": "用地地块","Color": "yellow", "Style": "solid"  } ] },' + '{ "type": "polyline", "featureName": "道路", "Feature": [{"ShowInfo":"yes", "Geometry": {"Paths": [{ "Path": "3778,-2008|2777,-2816|3777,-3021|3777,-3529|3772,-3928|3774,-4405|3777,-5206" }] }, "Attribute": {"ID": "2","道路名": "人民大道",  "道路长度": "10000", "道路宽度": "25" }, "ToolTip": "人民大道", "Color": [225,0,0,0.5], "Size": "5" }] },' + '{ "type": "point", "featureName": "兴趣点", "Feature":[ { "Geometry": { "Points":[ { "Point": "2600,900" } ]},"Attribute": { "ID": "3","名称": "东方明珠" }, "ToolTip": "东方明珠","Color": "blue", "Size": "10", "Style": "square"}]}]}}';
    doGetGraphicByJson(jsonStr)
}
function jsontagUndefined(firstChild) {
    if (firstChild != undefined) {
        return firstChild
    }
    return null
}
function attributesToHTMLStr(att) {
    var str = "";
    for (var name in att) {
        str += name + ":" + att[name] + "<br>"
    }
    return str
}
function polygonxmlToArray(xmlStr) {
    var end = [];
    var strs = xmlStr.split("|");
    for (var i = 0; i < strs.length; i++) {
        var s = strs[i].split(",");
        if (currentMapMode == "2D") {
            var aa = [parseFloat(s[0]), parseFloat(s[1])];
            end.push(aa)
        } else {
            var aa = [parseFloat(s[0]), parseFloat(s[1]), parseFloat(s[2])];
            end.push(aa)
        }
        end.push(aa)
    }
    end.push([parseFloat(strs[0].split(",")[0]), parseFloat(strs[0].split(",")[1])]);
    return end
}
function polylinexmlToArray(xmlStr) {
    var end = [];
    var strs = xmlStr.split("|");
    for (var i = 0; i < strs.length; i++) {
        var s = strs[i].split(",");
        if (currentMapMode == "2D") {
            var aa = [parseFloat(s[0]), parseFloat(s[1])];
            end[i] = aa
        } else {
            var aa = [parseFloat(s[0]), parseFloat(s[1]), parseFloat(s[2])];
            end[i] = aa
        }
    }
    return end
}
var imgSizeList = [];
function doGetGraphicByJson(jsons, isGoTo) {

    var jsonStr = eval("(" + jsons + ")");
    btClear_Click();
    var features = jsonStr.ExChangeRoot.Features;
    if (features.length < 1) {
        alert("无查询结果")
    }
    for (var k = 0; k < features.length; k++) {
        switch (features[k].type) {
            case "polygon":
            {
                var polygonFeature = features[k].Feature;
                for (var i = 0; i < polygonFeature.length; i++) {
                    var rings = polygonFeature[i].Geometry.Rings;
                    for (var j = 0; j < rings.length; j++) {
                        var ring = rings[j].Ring;
                        var polygonAttribute = polygonFeature[i].Attribute;
                        var polygonToolTip = jsontagUndefined(polygonFeature[i].ToolTip);
                        var polygonColor = jsontagUndefined(polygonFeature[i].Color);
                        var polygonSize = jsontagUndefined(polygonFeature[i].Size);
                        var polygonStyle = jsontagUndefined(polygonFeature[i].Style);
                        xmlAddPolygon(ring, polygonToolTip, polygonColor, polygonSize, polygonStyle, polygonAttribute)
                    }
                }
                break;
            }
            case "polyline":
            {
                var polylineFeature = features[k].Feature;
                for (var i = 0; i < polylineFeature.length; i++) {
                    var paths = polylineFeature[i].Geometry.Paths;
                    for (var j = 0; j < paths.length; j++) {
                        var path = paths[j].Path;
                        var polylineAttribute = polylineFeature[i].Attribute;
                        var polylineToolTip = jsontagUndefined(polylineFeature[i].ToolTip);
                        var polylineColor = jsontagUndefined(polylineFeature[i].Color);
                        var polylineSize = jsontagUndefined(polylineFeature[i].Size);
                        var polylineStyle = jsontagUndefined(polylineFeature[i].Style);
                        xmlAddPolyline(path, polylineToolTip, polylineColor, polylineSize, polylineStyle, polylineAttribute)
                    }
                }
                break;
            }
            case "point":
            {
                var pointFeature = features[k].Feature;
                for (var i = 0; i < pointFeature.length; i++) {
                    var points = pointFeature[i].Geometry.Points;
                    for (var j = 0; j < points.length; j++) {
                        var point = points[j].Point;
                        var pointAttribute = pointFeature[i].Attribute;
                        var pointToolTip = jsontagUndefined(pointFeature[i].ToolTip);
                        var imgUrl = jsontagUndefined(pointFeature[i].ImgUrl);
                        var ImgWidth = jsontagUndefined(pointFeature[i].ImgWidth);
                        var ImgHeight = jsontagUndefined(pointFeature[i].ImgHeight);
                        var color = jsontagUndefined(pointFeature[i].Color);
                        var size = jsontagUndefined(pointFeature[i].Size);
                        var style = jsontagUndefined(pointFeature[i].Style);
			var TextSize = jsontagUndefined(pointFeature[i].TextSize);
                        var TextColor = jsontagUndefined(pointFeature[i].TextColor);
                        xmlAddPoint(point, pointToolTip, imgUrl, ImgWidth, ImgHeight, color, size, style, pointAttribute,TextSize,TextColor)
                    }
                }
                break;
            }
        }
    }
    m_view.zoom=10;
    if (isGoTo == undefined || isGoTo == null)
        isGoTo = true;
    if (isGoTo) {
        m_view.goTo(xmlQueryExtend.expand(2))
    }
}
function doDeletePointById(id) {
    var list = GraphicsLayer_DrawLayer.graphics.items;
    for (var i = 0; i < list.length; i++) {
        if (list[i].attributes.id == id) {
            GraphicsLayer_DrawLayer.remove(list[i]);

        }
    }
}

function doShowAreaName(layerName, fieldName, bool, size, color) {
    if (!bool) {
        GraphicsLayer_areaNameLayer.removeAll();
        return;
    }
    if (!color) {
        color = "black";
    }
    if (!size) {
        size = 14;
    }
    var layerId = GetFeatureLayerIdbyName(layerName);

    var where = "1=1";

    if (layerId == -1)
        return;
    require(["esri/tasks/QueryTask", "esri/tasks/support/Query", "esri/layers/FeatureLayer", "dojo/_base/array", "dojo/dom", "esri/Graphic",
            "esri/geometry/Point"],
        function (QueryTask, Query, FeatureLayer, arrayUtils, dom, Graphic, Point) {
            var pointGraphicArray = [];
            var urlI = dyLayer.url + "/" + layerId;
            var qTask = new QueryTask({
                url: urlI
            });
            var params = new Query({
                returnGeometry: true,
                outFields: ["*"]
            });
            params.where = where;
            qTask.execute(params).then(getResults).catch(promiseRejected);
            function getResults(response) {
                $.each(response.features, function (index, feature) {
                    var geometry = feature.geometry;
                    var text = feature.attributes[fieldName];
                    var point = {
                        type: "point",
                        x: geometry.extent.center.x,
                        y: geometry.extent.center.y,
                        spatialReference: m_view.spatialReference
                    };
                    var textSymbol = {
                        type: "text",  // autocasts as new TextSymbol()
                        color: color,
                        text: text,
                        font: {  // autocasts as new Font()
                            size: size,
                            weight: "bold"
                        }
                    };
                    var pointGraphic = new Graphic({
                        geometry: point,
                        symbol: textSymbol
                    });
                    pointGraphicArray.push(pointGraphic);
                });

                GraphicsLayer_areaNameLayer.addMany(pointGraphicArray);

            }

            function promiseRejected(err) {
                console.error("错误信息: ", err.message);
            }

        });
}

function xmlAddPolygon(ring, polygonToolTip, polygonColor, polygonSize, polygonStyle, polygonAttribute) {
    require(["esri/Graphic", "esri/geometry/SpatialReference"],
        function (Graphic, SpatialReference) {
            if (!polygonColor) {
                polygonColor = [227, 139, 79, .8]
            }
            if (!polygonSize) {
                polygonSize = 2
            }
            switch (polygonStyle) {
                case "backwarddiagonal":
                    polygonStyle = "backward-diagonal";
                    break;
                case "cross":
                    polygonStyle = "cross";
                    break;
                case "diagonalcross":
                    polygonStyle = "diagonal-cross";
                    break;
                case "forwarddiagonal":
                    polygonStyle = "forward-diagonal";
                    break;
                case "horizontal":
                    polygonStyle = "horizontal";
                    break;
                case "vertical":
                    polygonStyle = "vertical";
                    break;
                case "solid":
                    polygonStyle = "solid";
                    break;
                default:
                    polygonStyle = "none";
                    break
            }
            var ringsarray = polygonxmlToArray(ring);
            var polygon = {
                type: "polygon",
                rings: ringsarray,
                spatialReference: m_view.spatialReference
            };
            var fillSymbol = {
                type: "simple-fill",
                color: polygonColor,
                style: polygonStyle,
                outline: {
                    color: [255, 255, 255],
                    width: polygonSize
                }
            };
            var polygonGraphic = new Graphic({
                geometry: polygon,
                symbol: fillSymbol,
                attributes: polygonAttribute
            });
            GraphicsLayer_DrawLayer.add(polygonGraphic);
            var popupTemplate = {
                title: polygonToolTip,
                content: attributesToHTMLStr(polygonAttribute)
            };
            // polygonGraphic.popupTemplate = popupTemplate;
            var extent = polygonGraphic.geometry.extent;
            extent.spatialReference = m_view.spatialReference;
            if (xmlQueryExtend) {
                xmlQueryExtend = xmlQueryExtend.union(extent)
            } else {
                xmlQueryExtend = extent
            }
        })
}
function xmlAddPolyline(path, polylineToolTip, polylineColor, polylineSize, polylineStyle, polylineAttribute) {
    require(["esri/Graphic"],
        function (Graphic) {
            if (polylineSize == null) {
                polylineSize = 1
            }
            if (polylineColor == null) {
                polylineColor = [226, 119, 40]
            }
            switch (polylineStyle) {
                case "dash":
                    polylineStyle = "dash";
                    break;
                case "dashdot":
                    polylineStyle = "dash-dot";
                    break;
                case "none":
                    polylineStyle = "none";
                    break;
                case "dot":
                    polylineStyle = "dot";
                    break;
                default:
                    polylineStyle = "solid"
            }
            var polyline = {
                type: "polyline",
                paths: polylinexmlToArray(path),
                spatialReference: m_view.spatialReference
            };
            var lineSymbol = {
                type: "simple-line",
                color: polylineColor,
                style: polylineStyle,
                width: polylineSize
            };
            var polylineGraphic = new Graphic({
                geometry: polyline,
                symbol: lineSymbol,
                attributes: polylineAttribute
            });
            GraphicsLayer_DrawLayer.add(polylineGraphic);
            var popupTemplate = {
                title: polylineToolTip,
                content: attributesToHTMLStr(polylineAttribute)
            };
            // polylineGraphic.popupTemplate = popupTemplate;
            var extent = polylineGraphic.geometry.extent;
            extent.spatialReference = m_view.spatialReference;
            if (xmlQueryExtend) {
                xmlQueryExtend = xmlQueryExtend.union(extent)
            } else {
                xmlQueryExtend = extent
            }
        })
}
function xmlAddPoint(points, pointToolTip, imgUrl, imgWidth, imgHeight, color, size, style, pointAttribute,TextSize,TextColor) {
    require(["esri/geometry/Extent", "esri/Graphic"],
        function (Extent, Graphic) {
            var xy = points.split(",");
            var point;
            if (currentMapMode == "2D") {
                point = {
                    type: "point",
                    x: xy[0],
                    y: xy[1],
                    spatialReference: m_view.spatialReference
                }
            } else {
		var z=0;
		if(xy.length==3){
			z=xy[2];
		}else{	
			z=10;
		}
                point = {
                    type: "point",
                    x: xy[0],
                    y: xy[1],
                    z: z,
                    spatialReference: m_view.spatialReference
                }
            }
            var markerSymbol;
            if (imgUrl != null) {
                imgSizeList = [imgWidth.split("px")[0], imgHeight.split("px")[0]];
                pointAttribute.newImgWidth=imgSizeList[0];
                pointAttribute.newImgHeight=imgSizeList[1];

                var newImgWidth = imgSizeList[0] - (imgSizeList[0] * (14 - m_view.zoom) * 0.05);//zoom每级差5%
                var newImgHeight = imgSizeList[1] - (imgSizeList[1] * (14 - m_view.zoom) * 0.05)
		 if(currentMapMode=="2D"){
                    markerSymbol = {
                        type: "picture-marker",
                        url: imgUrl,
                        width: newImgWidth + "px",
                        height: newImgHeight + "px"
                    };
                }else {
                markerSymbol =
                {
                    type: "point-3d", // autocasts as new PointSymbol3D()
                        symbolLayers: [
                    {
                        type: "icon", // autocasts as new IconSymbol3DLayer()
                        resource: {
                            href: imgUrl
                        },
                        size: newImgWidth,
                        outline: {
                            color: "white",
                            size: 2
                        }
                    }
                ],
                    verticalOffset:{
                    screenLength: 20,
                        maxWorldLength: 200,
                        minWorldLength: 10
                },
                    callout: {
                        type: "line", // autocasts as new LineCallout3D()
                            color: "#36B1E8",
                            size: 0,
                            border: {
                            color:  "#36B1E8"
                        }
                    }
                }
		}
            } else {

                if (color == null) {
                    color = [226, 119, 40]
                }
                if (size == null) {
                    size = 2
                }
                switch (style) {
                    case "x":
                        style = "x";
                        break;
                    case "diamond":
                        style = "diamond";
                        break;
                    case "cross":
                        style = "cross";
                        break;
                    case "square":
                        style = "square";
                        break;
                    default:
                        style = "circle"
                }
                markerSymbol = {
                    type: "simple-marker",
                    color: color,
                    style: style,
                    size: size
                }
            }
            // debugger;
            var pointGraphic = new Graphic({
                geometry: point,
                symbol: markerSymbol,
                attributes: pointAttribute
            });
           if(TextSize==null){
                TextSize=14;
            }
            if(TextColor==null){
                TextColor=[254, 238, 175];
            }
            var textSymbol = {
                type: "text",  // autocasts as new TextSymbol()
                color: TextColor,
                text: pointAttribute.名称,
                yoffset: "-35px",
                font: {  // autocasts as new Font()
                    size: TextSize
                }
            };
            var textGraphic = new Graphic({
                geometry: point,
                symbol: textSymbol

            });
            GraphicsLayer_DrawLayer.add(textGraphic);
            GraphicsLayer_DrawLayer.add(pointGraphic);
            var popupTemplate = {
                title: pointToolTip,
                content: attributesToHTMLStr(pointAttribute)
            };
            // pointGraphic.popupTemplate = popupTemplate;
            var extent = new Extent({
                xmax: pointGraphic.geometry.x - 0 + 250,
                ymax: pointGraphic.geometry.y - 0 + 250,
                xmin: pointGraphic.geometry.x - 250,
                ymin: pointGraphic.geometry.y - 250,
                spatialReference: m_view.spatialReference
            });
            if (xmlQueryExtend) {
                xmlQueryExtend = xmlQueryExtend.union(extent)
            } else {
                xmlQueryExtend = extent
            }
        })
}
function xmlAddPointJCZ(x,y, pointToolTip, imgUrl, imgWidth, imgHeight, color, size, style, pointAttribute,radius) {
    require(["esri/geometry/Extent", "esri/Graphic","esri/geometry/Circle"],
        function (Extent, Graphic,Circle) {
            var point;
                point = {
                    type: "point",
                    x: x,
                    y: y,
                    spatialReference: m_view.spatialReference
                }

                var markerSymbol;
                if (color == null) {
                    color = [0, 0, 0]
                }
                if (size == null) {
                    size = 10
                }
                /*switch (style) {
                    case "x":
                        style = "x";
                        break;
                    case "diamond":
                        style = "diamond";
                        break;
                    case "cross":
                        style = "cross";
                        break;
                    case "square":
                        style = "square";
                        break;
                    default:
                        style = "circle"
                }*/
                markerSymbol = {
                    type: "simple-marker",
                    color: color,
                    style: "circle",
                    size: size
                };

            // debugger;
            var pointGraphic = new Graphic({
                geometry: point,
                symbol: markerSymbol,
                attributes: pointAttribute
            });
            var polygon =new Circle( {
                type: "circle",
                center:point,
                radius: radius,
                spatialReference: m_view.spatialReference
            });
            var fillSymbol = {
                type: "simple-fill",
                color:[255, 0, 0,0.3],
                style: "solid",
                outline: {
                    color: [255, 255, 255,0.3],
                    width: 1
                }
            };
            var circle = new Graphic({
                geometry: polygon,
                symbol: fillSymbol
            });
            //蓝[0,0,255]  绿[0,255,0] 黄[255,255,0]
            GraphicsLayer_DrawLayer.add(pointGraphic);
            GraphicsLayer_DrawLayer.add(circle);
        })
}

function btnCircle_Click() {
    drawSquare()
}
function drawSquare() {
    require(["esri/Map", "esri/views/MapView", "esri/layers/MapImageLayer", "esri/layers/TileLayer", "esri/geometry/Geometry", "esri/geometry/Extent", "esri/tasks/GeometryService", "esri/layers/GraphicsLayer", "esri/widgets/ScaleBar", "esri/WebMap", "esri/geometry/SpatialReference", "esri/Graphic", "esri/views/2d/draw/Draw", "esri/geometry/Polygon", "esri/geometry/geometryEngine"],
        function (Map, MapView, MapImageLayer, TileLayer, Geometry, Extent, GeometryService, GraphicsLayer, ScaleBar, WebMap, SpatialReference, Graphic, Draw, Polygon, geometryEngine) {
            var action = m_drawtool.create("polygon");
            m_view.focus();
            action.on("vertex-add", drawPolygon);
            action.on("cursor-update", drawPolygon);
            action.on("vertex-remove", drawPolygon);
            action.on("draw-complete", drawPolygon);
            function drawPolygon(evt) {
                var vertices = evt.vertices;
                btClear_Click();
                var polygon = createPolygon(vertices);
                var graphic = createGraphic(polygon);
                GraphicsLayer_DrawLayer.add(graphic);
                queryExtent = polygon
            }

            function createPolygon(vertices) {
                return new Polygon({
                    rings: vertices,
                    spatialReference: m_view.spatialReference
                })
            }

            function createGraphic(polygon) {
                graphic = new Graphic({
                    geometry: polygon,
                    symbol: {
                        type: "simple-fill",
                        color: [178, 102, 234, .8],
                        style: "solid",
                        outline: {
                            color: [255, 255, 255],
                            width: 2
                        }
                    }
                });
                return graphic
            }
        })
}
function btQuery_Click() {
    var Str = document.getElementById("txtQueryStr").value;
    var layerName = document.getElementById("txtQueryLayerName").value;
    query(Str, layerName)
}
function query(Str, layerName) {
    queryGraphicByDylayer();
    var whereStr = "";
    if (Str == "") {
        whereStr = "  1=1 "
    } else {
        whereStr = "  1=2 ";
        var xmlDoc1 = xmlUtil.loadXmlFromFile("config/layerQueryName.xml");
        var layerXml = xmlDoc1.getElementsByTagName(layerName);
        var mapNodes = layerXml[0].childNodes;
        for (var i = 0; i < mapNodes.length; i++) {
            if (xmlUtil.getNodeTagName(mapNodes[i]) == "name") {
                whereStr += " or " + xmlUtil.getNodeValue(mapNodes[i]) + " like '%" + Str + "%' "
            }
        }
    }
    var layerId = GetLayerIdbyName(layerName);
    if (layerId == -1) {
        alert("没有此图层")
    } else {
        queryGraphicByDylayer(layerId, whereStr)
    }
}
function queryGraphicByDylayer(layerId, whereStr, geo) {
    require(["esri/tasks/QueryTask", "esri/tasks/support/Query", "esri/layers/FeatureLayer", "dojo/_base/array", "dojo/dom"],
        function (QueryTask, Query, FeatureLayer, arrayUtils, dom) {
            btClear_Click();
            var urlI = dyLayer.url + "/" + layerId;
            var qTask = new QueryTask({
                url: urlI
            });
            var params = new Query({
                geometry: queryExtent,
                returnGeometry: true,
                outFields: ["*"]
            });
            params.geometry = geo || null;
            params.where = whereStr;
            qTask.execute(params).then(getResults).otherwise(promiseRejected);
            function getResults(response) {
                var peakResults = arrayUtils.map(response.features,
                    function (feature) {
                        var obj = eval("(" + symble[layerId] + ")");
                        var symbolJson = obj.drawingInfo.renderer.symbol;
                        if (currentMapMode == "2D") {
                            if (symbolJson) {
                                if (symbolJson.type == "esriSFS") {
                                    feature.symbol = {
                                        type: "simple-fill",
                                        style: changeStyle(symbolJson.style),
                                        color: symbolJson.color,
                                        outline: {
                                            style: changeStyle(symbolJson.outline.style),
                                            color: symbolJson.outline.color,
                                            width: symbolJson.outline.width
                                        }
                                    }
                                } else if (symbolJson.type == "esriPMS") {
                                    feature.symbol = {
                                        type: "picture-marker",
                                        url: "data:image/png;base64," + symbolJson.imageData,
                                        width: symbolJson.width,
                                        height: symbolJson.height
                                    }
                                } else if (symbolJson.type == "esriSMS") {
                                    feature.symbol = {
                                        type: "simple-marker",
                                        size: symbolJson.size,
                                        color: symbolJson.color,
                                        outline: symbolJson.outline
                                    }
                                }
                            } else {
                                feature.symbol = {
                                    type: "simple-marker",
                                    color: rgba(255, 0, 0, 1),
                                    outline: {
                                        color: [0, 0, 0, 1],
                                        width: 1
                                    }
                                }
                            }
                        } else {
                            var verticalOffset = {
                                screenLength: 40,
                                maxWorldLength: 200,
                                minWorldLength: 35
                            };
                            if (symbolJson.type == "esriSFS") {
                                feature.symbol = {
                                    type: "polygon-3d",
                                    symbolLayers: [{
                                        type: "fill",
                                        material: {
                                            color: symbolJson.color
                                        }
                                    }],
                                    outline: {
                                        color: symbolJson.outline.color,
                                        size: symbolJson.outline.size
                                    }
                                }
                            } else if (symbolJson.type == "esriPMS") {
                                feature.symbol = {
                                    type: "point-3d",
                                    symbolLayers: [{
                                        type: "icon",
                                        resource: {
                                            href: "data:image/png;base64," + symbolJson.imageData
                                        },
                                        size: 20,
                                        outline: {
                                            color: "white",
                                            size: 2
                                        }
                                    }],
                                    verticalOffset: verticalOffset,
                                    callout: {
                                        type: "line",
                                        color: "white",
                                        size: 2,
                                        border: {
                                            color: "#40C2B4"
                                        }
                                    }
                                }
                            } else if (symbolJson.style == "esriSMSCircle") {
                                feature.symbol = {
                                    type: "point-3d",
                                    symbolLayers: [{
                                        type: "icon",
                                        resource: {
                                            primitive: "circle"
                                        },
                                        size: symbolJson.size * 2,
                                        material: {
                                            color: symbolJson.color
                                        },
                                        outline: {
                                            color: symbolJson.outline.color,
                                            size: symbolJson.outline.size
                                        }
                                    }],
                                    verticalOffset: verticalOffset,
                                    callout: {
                                        type: "line",
                                        color: "white",
                                        size: 2,
                                        border: {
                                            color: "#40C2B4"
                                        }
                                    }
                                }
                            }
                        }
                        feature.geometry.spatialReference = m_view.spatialReference;
                        var popupTemplate = {
                            title: "详细信息",
                            content: attributesToHTMLStr(feature.attributes)
                        };
                        feature.popupTemplate = popupTemplate;
                        return feature
                    });
                GraphicsLayer_myLayer.addMany(peakResults);
                m_view.goTo(peakResults)
            }

            function promiseRejected(err) {
                console.error("错误信息: ", err.message)
            }
        })
}
function changeStyle(oldStyle) {
    switch (oldStyle) {
        case "esriSFSBackwardDiagonal":
            oldStyle = "backward-diagonal";
            break;
        case "esriSFSCross":
            oldStyle = "cross";
            break;
        case "esriSFSDiagonalCross":
            oldStyle = "diagonal-cross";
            break;
        case "esriSFSForwardDiagonal":
            oldStyle = "forward-diagonal";
            break;
        case "esriSFSHorizontal":
            oldStyle = "horizontal";
            break;
        case "esriSFSNull":
            oldStyle = "none";
            break;
        case "esriSFSSolid":
            oldStyle = "solid";
            break;
        case "esriSFSVertical":
            oldStyle = "vertical";
            break;
        case "esriSLSDash":
            oldStyle = "dash";
            break;
        case "esriSLSDashDotDot":
            oldStyle = "short-dash-dot-dot";
            break;
        case "esriSLSDot":
            oldStyle = "dot";
            break;
        case "esriSLSNull":
            oldStyle = "none";
            break;
        case "esriSLSDashDot":
            oldStyle = "dash-dot";
            break;
        case "esriSLSSolid":
            oldStyle = "solid";
            break
    }
    return oldStyle
}
function openQuickQueryClick() {
    document.getElementById("openQuickQuery").style.display = "none";
    document.getElementById("quickQuery").style.display = "";
    createSelect()
}
function closeQuickQueryClick() {
    document.getElementById("openQuickQuery").style.display = "";
    document.getElementById("quickQuery").style.display = "none"
}
function createSelect() {
    var areaId = GetLayerIdbyName("特色街区");
    var streetId = GetLayerIdbyName("街道乡镇");
    queryOption(areaId, "areaName");
    queryOption(streetId, "streetName")
}
function queryOption(layerId, selectId) {
    require(["esri/tasks/QueryTask", "esri/tasks/support/Query", "esri/layers/FeatureLayer", "dojo/_base/array", "dojo/dom"],
        function (QueryTask, Query, FeatureLayer, arrayUtils, dom) {
            var urlI = dyLayer.url + "/" + layerId;
            var qTask = new QueryTask({
                url: urlI
            });
            var params = new Query({
                geometry: queryExtent,
                returnGeometry: true,
                outFields: ["*"]
            });
            params.where = "1=1";
            qTask.execute(params).then(getResults).otherwise(promiseRejected);
            function getResults(response) {
                var peakResults = arrayUtils.map(response.features,
                    function (feature) {
                        return feature.attributes["名称"]
                    });
                var option = "<option value='-1'>全部</option>";
                for (var i = 0; i < peakResults.length; i++) {
                    option += "<option value='" + peakResults[i] + "'>" + peakResults[i] + "</option>"
                }
                document.getElementById(selectId).innerHTML = option
            }

            function promiseRejected(err) {
                console.error("错误信息: ", err.message)
            }
        })
}
function changeAreaNameSelect() {
    var optionValue = areaName.value;
    if (optionValue == -1) {
        GraphicsLayer_DrawLayer.removeAll();
        queryExtent = null
    } else {
        var areaId = GetLayerIdbyName("特色街区");
        queryGraphicBySelect(areaId, optionValue)
    }
}
function changeStreetNameSelect() {
    var optionValue = streetName.value;
    if (optionValue == -1) {
        GraphicsLayer_DrawLayer.removeAll();
        queryExtent = null
    } else {
        var streetId = GetLayerIdbyName("街道乡镇");
        queryGraphicBySelect(streetId, optionValue)
    }
}
function queryGraphicBySelect(layerId, name) {
    require(["esri/tasks/QueryTask", "esri/tasks/support/Query", "esri/layers/FeatureLayer", "dojo/_base/array", "esri/Graphic", "dojo/dom"],
        function (QueryTask, Query, FeatureLayer, arrayUtils, Graphic, dom) {
            GraphicsLayer_DrawLayer.removeAll();
            queryExtent = null;
            var urlI = dyLayer.url + "/" + layerId;
            var qTask = new QueryTask({
                url: urlI
            });
            var params = new Query({
                geometry: queryExtent,
                returnGeometry: true,
                outFields: ["*"]
            });
            params.where = "名称 = '" + name + "'";
            qTask.execute(params).then(getResults).otherwise(promiseRejected);
            function getResults(response) {
                var peakResults = arrayUtils.map(response.features,
                    function (feature) {
                        if (currentMapMode == "2D") {
                            feature.symbol = {
                                type: "simple-fill",
                                style: "none",
                                color: null,
                                outline: {
                                    style: "solid",
                                    color: "red",
                                    width: 2
                                }
                            };
                            feature.geometry.spatialReference = m_view.spatialReference;
                            queryExtent = feature.geometry;
                            feature.geometry.spatialReference = m_view.spatialReference;
                            return feature
                        } else {
                            for (var i = 0; i < feature.geometry.rings[0].length; i++) {
                                feature.geometry.rings[0][i].push(1)
                            }
                            var polygon = {
                                type: "polygon",
                                rings: feature.geometry.rings
                            };
                            var polygonGraphic = new Graphic({
                                geometry: polygon
                            });
                            polygonGraphic.symbol = {
                                type: "polygon-3d",
                                symbolLayers: [{
                                    type: "fill",
                                    material: {
                                        color: [0, 0, 0, 0]
                                    },
                                    outline: {
                                        color: "red",
                                        size: "4px"
                                    }
                                }]
                            }
                        }
                        queryExtent = feature.geometry;
                        polygonGraphic.geometry.spatialReference = m_view.spatialReference;
                        return polygonGraphic
                    });
                GraphicsLayer_DrawLayer.addMany(peakResults);
                m_view.goTo(peakResults[0].geometry.extent.expand(2))
            }

            function promiseRejected(err) {
                console.error("错误信息: ", err.message)
            }
        })
}
function Polygon_Click() {
    queryExtent = null;
    require(["esri/Map", "esri/views/MapView", "esri/layers/MapImageLayer", "esri/layers/TileLayer", "esri/geometry/Geometry", "esri/geometry/Extent", "esri/tasks/GeometryService", "esri/layers/GraphicsLayer", "esri/widgets/ScaleBar", "esri/WebMap", "esri/geometry/SpatialReference", "esri/Graphic", "esri/views/2d/draw/Draw", "esri/geometry/Polygon", "esri/geometry/geometryEngine"],
        function (Map, MapView, MapImageLayer, TileLayer, Geometry, Extent, GeometryService, GraphicsLayer, ScaleBar, WebMap, SpatialReference, Graphic, Draw, Polygon, geometryEngine) {
            var action = m_drawtool.create("polygon");
            m_view.focus();
            action.on("vertex-add", drawPolygon);
            action.on("cursor-update", drawPolygon);
            action.on("vertex-remove", drawPolygon);
            action.on("draw-complete", drawPolygon);
            function drawPolygon(evt) {
                var vertices = evt.vertices;
                GraphicsLayer_DrawLayer.removeAll();
                var polygon = createPolygon(vertices);
                var graphic = createGraphic(polygon);
                GraphicsLayer_DrawLayer.add(graphic);
                queryExtent = polygon
            }

            function createPolygon(vertices) {
                return new Polygon({
                    rings: vertices,
                    spatialReference: m_view.spatialReference
                })
            }

            function createGraphic(polygon) {
                graphic = new Graphic({
                    geometry: polygon,
                    symbol: {
                        type: "simple-fill",
                        style: "none",
                        color: null,
                        outline: {
                            style: "solid",
                            color: "red",
                            width: 2
                        }
                    }
                });
                return graphic
            }
        })
}
function btnQuickQuery() {
    queryList.splice(0, queryList.length);
    var layerName = select_zylx.value;
    var zymc = txt_zymc.value;
    var keyStr = txt_keyStr.value;
    dynamicLayerURL = GetConfigDataByName("QueryLayer");
    var layerId = GetLayerIdbyName(layerName);
    var whereStr = " 1=1 ";
    var optgroup = select_zylx.options[select_zylx.selectedIndex].parentNode.attributes;
    if (optgroup["label"]) {
        if (zymc) {
            switch (layerName) {
                case "ETPS":
                    whereStr += " and ETPS_NAME like '%" + zymc + "%' ";
                    break;
                case "PE":
                    whereStr += " and NAME like '%" + zymc + "%' ";
                    break;
                case "CORP":
                    whereStr += " and CORP_NAME  like '%" + zymc + "%' ";
                    break
            }
        }
        if (keyStr) {
            whereStr += "and ADDRESS  like '%" + keyStr + "%'"
        }
    } else {
        if (layerName == "YDYZ") {
            if (zymc) {
                whereStr += "and MDNAME like '%" + zymc + "%'"
            }
            if (keyStr) {
                whereStr += "and ADDRESS like '%" + keyStr + "%'"
            }
        } else {
            if (zymc) {
                whereStr += "and 载体名称 like '%" + zymc + "%'"
            }
            if (keyStr) {
                whereStr += "and 载体地址 like '%" + keyStr + "%'"
            }
        }
    }
    doQuickQuery(layerId, whereStr)
}
function doQuickQuery(layerId, whereStr) {
    require(["esri/tasks/QueryTask", "esri/tasks/support/Query", "esri/layers/FeatureLayer", "dojo/_base/array", "dojo/dom"],
        function (QueryTask, Query, FeatureLayer, arrayUtils, dom) {
            var layerStr = "";
            var layerName = select_zylx.value;
            var optgroup = select_zylx.options[select_zylx.selectedIndex].parentNode.attributes;
            if (optgroup["label"]) {
                switch (layerName) {
                    case "ETPS":
                        layerStr = "ETPS_NAME";
                        break;
                    case "PE":
                        layerStr = "NAME";
                        break;
                    case "CORP":
                        layerStr = "CORP_NAME";
                        break
                }
            } else {
                if (layerName == "YDYZ") {
                    layerStr = "MDNAME"
                } else {
                    layerStr = "载体名称"
                }
            }
            GraphicsLayer_fickerLayer.removeAll();
            GraphicsLayer_myLayer.removeAll();
            if (!dynamicLayerURL) {
                dynamicLayerURL = GetConfigDataByName("QueryLayer")
            }
            var urlI = dynamicLayerURL + "/" + layerId;
            var qTask = new QueryTask({
                url: urlI
            });
            var params = new Query({
                geometry: queryExtent,
                returnGeometry: true,
                outFields: ["*"]
            });
            params.where = whereStr;
            qTask.execute(params).then(getResults).otherwise(promiseRejected);
            function getResults(response) {
                var peakResults = arrayUtils.map(response.features,
                    function (feature) {
                        if (currentMapMode == "2D") {
                            var obj = eval("(" + symble[layerId] + ")");
                            var symbolJson = obj.drawingInfo.renderer.symbol;
                            if (symbolJson.type == "esriSFS") {
                                feature.symbol = {
                                    type: "simple-fill",
                                    style: changeStyle(symbolJson.style),
                                    color: symbolJson.color,
                                    outline: {
                                        style: changeStyle(symbolJson.outline.style),
                                        color: symbolJson.outline.color,
                                        width: symbolJson.outline.width
                                    }
                                }
                            } else if (symbolJson.type == "esriPMS") {
                                feature.symbol = {
                                    type: "picture-marker",
                                    url: "data:image/png;base64," + symbolJson.imageData,
                                    width: symbolJson.width,
                                    height: symbolJson.height
                                }
                            } else if (symbolJson.style == "esriSMSCircle") {
                                feature.symbol = {
                                    type: "simple-marker",
                                    style: "circle",
                                    color: symbolJson.color,
                                    size: symbolJson.size,
                                    outline: {
                                        color: symbolJson.outline.color,
                                        width: symbolJson.outline.width
                                    }
                                }
                            }
                        } else {
                            var verticalOffset = {
                                screenLength: 40,
                                maxWorldLength: 200,
                                minWorldLength: 35
                            };
                            var obj = eval("(" + symble[layerId] + ")");
                            var symbolJson = obj.drawingInfo.renderer.symbol;
                            if (symbolJson.type == "esriSFS") {
                            } else if (symbolJson.type == "esriPMS") {
                                feature.symbol = {
                                    type: "point-3d",
                                    symbolLayers: [{
                                        type: "icon",
                                        resource: {
                                            href: "data:image/png;base64," + symbolJson.imageData
                                        },
                                        size: 20,
                                        outline: {
                                            color: "white",
                                            size: 2
                                        }
                                    }],
                                    verticalOffset: verticalOffset,
                                    callout: {
                                        type: "line",
                                        color: "white",
                                        size: 2,
                                        border: {
                                            color: "#40C2B4"
                                        }
                                    }
                                }
                            } else if (symbolJson.style == "esriSMSCircle") {
                                feature.symbol = {
                                    type: "point-3d",
                                    symbolLayers: [{
                                        type: "icon",
                                        resource: {
                                            primitive: "circle"
                                        },
                                        size: symbolJson.size * 2,
                                        material: {
                                            color: symbolJson.color
                                        },
                                        outline: {
                                            color: symbolJson.outline.color,
                                            size: symbolJson.outline.size
                                        }
                                    }],
                                    verticalOffset: verticalOffset,
                                    callout: {
                                        type: "line",
                                        color: "white",
                                        size: 2,
                                        border: {
                                            color: "#40C2B4"
                                        }
                                    }
                                }
                            }
                        }
                        feature.geometry.spatialReference = m_view.spatialReference;
                        var popupTemplate = {
                            title: "资源信息",
                            content: openInfoWin(feature.attributes)
                        };
                        feature.popupTemplate = popupTemplate;
                        var list = {
                            "名称": feature.attributes[layerStr],
                            "几何": feature
                        };
                        queryList.push(list);
                        return feature
                    });
                GraphicsLayer_myLayer.addMany(peakResults);
                m_view.goTo(peakResults);
                dom.byId("printResults").innerHTML = "资产数：<a onclick='openResultTable()'> " + peakResults.length + "</a>"
            }

            function promiseRejected(err) {
                console.error("错误信息: ", err.message)
            }
        })
}
function openResultTable() {
    document.getElementById("resultList").style.display = "";
    dyCretateTableByArray("resultListTable", queryList, ["名称"], ["名称"], false)
}
function closeResultList() {
    document.getElementById("resultList").style.display = "none"
}
function openInfoWin(att) {
    var str = "";
    switch (select_zylx.value) {
        case "CORP":
        {
            str = quickQueryAttributesToHTMLStr(att);
            break
        }
        case "ETPS":
        {
            str = quickQueryAttributesToHTMLStr(att);
            break
        }
        case "PE":
        {
            str = quickQueryAttributesToHTMLStr(att);
            break
        }
        case "PARK":
        {
            str = quickQueryIFrameToHTMLStr(att);
            break
        }
        case "BUILDING":
        {
            str = quickQueryIFrameToHTMLStr(att);
            break
        }
        case "YDYZ":
        {
            str = quickQueryAttributesToHTMLStr(att);
            break
        }
    }
    return str
}
function quickQueryAttributesToHTMLStr(att) {
    var arList = [];
    var linkURL = "";
    var id;
    var username;
    var pwd;
    switch (select_zylx.value) {
        case "CORP":
        {
            arList = [{
                cname: "CORP_NAME",
                showname: "组织名称"
            },
                {
                    cname: "ADDRESS",
                    showname: "地址"
                }];
            id = String(att.CORP_INFO_ID);
            username = "wdzc";
            pwd = "68cf63c62bc68d71fc41c028375e2f6e";
            linkURL = "http://10.214.3.195:8001/coop/syn/detail_register_view_out?ifEncrypt=0&userName=" + username + "&passWord=" + pwd + "&entyId=" + id + "&type=06";
            break
        }
        case "ETPS":
        {
            arList = [{
                cname: "UNISC_ID",
                showname: "统一社会信用代码"
            },
                {
                    cname: "REG_NO",
                    showname: "注册号"
                },
                {
                    cname: "ETPS_NAME",
                    showname: "企业名称"
                },
                {
                    cname: "ADDRESS",
                    showname: "住所"
                }];
            id = String(att.ETPS_ID);
            username = "wdzc";
            pwd = "68cf63c62bc68d71fc41c028375e2f6e";
            linkURL = "http://10.214.3.195:8001/coop/syn/detail_register_view_out?ifEncrypt=0&userName=" + username + "&passWord=" + pwd + "&entyId=" + id + "&type=02";
            break
        }
        case "PE":
        {
            arList = [{
                cname: "UNISC_ID",
                showname: "统一社会信用代码"
            },
                {
                    cname: "REG_NO",
                    showname: "注册号"
                },
                {
                    cname: "NAME",
                    showname: "个体名称"
                },
                {
                    cname: "ADDRESS",
                    showname: "地址"
                }];
            id = String(att.PE_ID);
            username = "wdzc";
            pwd = "68cf63c62bc68d71fc41c028375e2f6e";
            linkURL = "http://10.214.3.195:8001/coop/syn/detail_register_view_out?ifEncrypt=0&userName=" + username + "&passWord=" + pwd + "&entyId=" + id + "&type=05";
            break
        }
        case "YDYZ":
        {
            arList = [{
                cname: "MDNAME",
                showname: "门店名称"
            },
                {
                    cname: "ADDRESS",
                    showname: "详细地址"
                },
                {
                    cname: "STREET",
                    showname: "街道"
                },
                {
                    cname: "ROAD",
                    showname: "道路"
                },
                {
                    cname: "JYZLENUMITEM",
                    showname: "经营种类"
                },
                {
                    cname: "JYZL",
                    showname: "经营种类（其他）"
                },
                {
                    cname: "FW_SX",
                    showname: "房屋属性"
                },
                {
                    cname: "MZDW_BZ",
                    showname: "备注(基本信息)"
                },
                {
                    cname: "ZZ_QK",
                    showname: "证照情况"
                },
                {
                    cname: "JYZ",
                    showname: "经营者"
                },
                {
                    cname: "JYZ_IDCARD",
                    showname: "身份证（经营者）"
                },
                {
                    cname: "JYZ_LXDZ",
                    showname: "联系地址(经营者)"
                },
                {
                    cname: "JYZ_JG",
                    showname: "籍贯（经营者）"
                },
                {
                    cname: "JYZ_ZZDZ",
                    showname: "暂住地址（经营者）"
                },
                {
                    cname: "ZZ_BZ",
                    showname: "备注(证照情况)"
                },
                {
                    cname: "FD_NAME",
                    showname: "房东姓名/单位"
                },
                {
                    cname: "FD_JG",
                    showname: "籍贯（房东）"
                },
                {
                    cname: "FD_LXDZ",
                    showname: "联系地址（房东）"
                },
                {
                    cname: "FD_LXFS",
                    showname: "联系方式（房东）"
                },
                {
                    cname: "FD_BZ",
                    showname: "备注（房东）"
                },
                {
                    cname: "JYZ_LXFS",
                    showname: "联系方式(经营者)"
                },
                {
                    cname: "FW_BZ",
                    showname: "备注（房屋）"
                },
                {
                    cname: "JYMJ",
                    showname: "经营面积"
                },
                {
                    cname: "QT_ZRDY",
                    showname: "责任队员"
                },
                {
                    cname: "ORGAN",
                    showname: "部门"
                },
                {
                    cname: "QT_SSGD",
                    showname: "所属岗段"
                },
                {
                    cname: "JW_LD",
                    showname: "居委领导"
                },
                {
                    cname: "ROADTYPE",
                    showname: "道路类型"
                },
                {
                    cname: "NUM",
                    showname: "门牌号"
                },
                {
                    cname: "GRIDCENTER",
                    showname: "网格中心"
                },
                {
                    cname: "QT_WG",
                    showname: "网格"
                },
                {
                    cname: "ZZ_SX",
                    showname: "证照属性"
                },
                {
                    cname: "JW_NAME",
                    showname: "居委名称"
                },
                {
                    cname: "JW_LXDH",
                    showname: "联系电话（居委）"
                },
                {
                    cname: "ZXZTSJ",
                    showname: "注销状态时间"
                },
                {
                    cname: "CFAJH",
                    showname: "曾经是否处罚过"
                },
                {
                    cname: "JE",
                    showname: "金额（处罚）"
                },
                {
                    cname: "OPTIME",
                    showname: "操作时间"
                },
                {
                    cname: "ISZY",
                    showname: "是否重要"
                },
                {
                    cname: "QT_LXFS",
                    showname: "联系方式"
                },
                {
                    cname: "OPUSER",
                    showname: "操作人"
                },
                {
                    cname: "JYZ_BZ",
                    showname: "备注"
                },
                {
                    cname: "ZXZT",
                    showname: "注销状态"
                },
                {
                    cname: "BZ",
                    showname: "备注"
                },
                {
                    cname: "LONG1",
                    showname: "经度gps"
                },
                {
                    cname: "LAT",
                    showname: "纬度gps"
                }];
            id = String(att.ROWGUID);
            username = "wdzc";
            pwd = "68cf63c62bc68d71fc41c028375e2f6e";
            linkURL = "http://10.214.3.195:8001/coop/syn/detail_register_view_out?ifEncrypt=0&userName=" + username + "&passWord=" + pwd + "&entyId=" + id + "&type=05";
            break
        }
    }
    var str = "";
    for (var name in att) {
        for (var i = 0; i < arList.length; i++) {
            if (name == arList[i].cname) {
                str += arList[i].showname + ":" + att[name] + "<br>"
            }
        }
    }
    str += "<br><a href='" + linkURL + "' target='blank'>[点击详情信息]</a>";
    return str
}
function quickQueryIFrameToHTMLStr(att) {
    var sourceid = String(att.主键);
    var url = "";
    switch (select_zylx.value) {
        case "PARK":
        {
            url = "http://10.214.4.162:8080/parkms/tj/parksysSuperviseCD_SSLDL.action?systemsign=408080a758f26bb00158f26f13f30001&is_Park=1&buildingInfosId=" + sourceid;
            break
        }
        case "BUILDING":
        {
            url = "http://10.214.4.162:8080/parkms/tj/parksysSuperviseCD_SSLDL.action?systemsign=408080a758f26bb00158f26f13f30001&is_Park=2&buildingInfosId=" + sourceid;
            break
        }
    }
    var str = " <div style='width:600px;height:500px;'><iframe src='" + url + "' width='100%' height='100%' frameborder='1' scrolling='yes'></iframe></div>";
    return str
}
function openQuery() {
    document.getElementById("query").style.display = "";
    document.getElementById("queryReult1").style.display = "";
    document.getElementById("queryReult2").style.display = "none";
    document.getElementById("return").style.display = "none";
    document.getElementById("barcon1").style.display = "";
    document.getElementById("barcon2").style.display = "none";
    document.getElementById("name").value = "";
    document.getElementById("queryTable1").innerHTML = "";
    document.getElementById("barcon1").innerHTML = "";
    createLayerSelect("quertLayerSelect")
}
function closeQuery() {
    document.getElementById("query").style.display = "none"
}
function returnQueryList() {
    document.getElementById("queryReult1").style.display = "";
    document.getElementById("queryReult2").style.display = "none";
    document.getElementById("return").style.display = "none";
    document.getElementById("barcon1").style.display = "";
    document.getElementById("barcon2").style.display = "none"
}
function queryByWhere() {
    document.getElementById("queryReult1").style.display = "";
    document.getElementById("queryReult2").style.display = "none";
    var name = document.getElementById("name").value;
    if (name == "") {
        alert("请输入查询内容");
        return
    }
    queryExtent = null;
    btClear_Click();
    queryAll()
}

function newOpenLayer(layerName, type, name, isGoTo, isOpen) {
    if (type == 1) {
        type = "街道乡镇";
    }
    else if (type == 2) {
        type = "区县边界";
    }
    else {
        return;
    }
    var layerId = GetFeatureLayerIdbyName(type);
    var where = "";
    var attributename = "";
    var layerCondition = "";
    if (type == "街道乡镇") {
        where = "街道名称 = '" + name + "'";
        attributename = "街道代码";
        layerCondition = "街道代码";
    }
    else {
        where = "区县名称 = '" + name + "'";
        attributename = "区县代码";
        layerCondition = "区代码";
    }
    if (layerId == -1) {
        window.parent.postMessage(
            {
                method: "newOpenLayer",
                data: ["参数type填写错误"]
            },
            '*'
        );
    }
    else {
        require(["esri/tasks/QueryTask", "esri/tasks/support/Query", "esri/layers/FeatureLayer", "dojo/_base/array", "dojo/dom"],
            function (QueryTask, Query, FeatureLayer, arrayUtils, dom) {
                var urlI = dyLayer.url + "/" + layerId;

                var restUrl = urlI + "?f=pjson";
                var xmlHttpRest = GetXmlHttpObject();
                xmlHttpRest.open("GET", restUrl, true);
                xmlHttpRest.send();
                xmlHttpRest.onreadystatechange = function () {
                    if (xmlHttpRest.readyState == 4) {
                        var responseText = xmlHttpRest.responseText;
                        var LayerJsonData = JSON.parse(responseText);
                        var qTask = new QueryTask({
                            url: urlI
                        });
                        var params = new Query({
                            geometry: queryExtent,
                            returnGeometry: true,
                            outFields: ["*"]
                        });
                        //params.spatialRelationship = "intersects";
                        //params.geometry = geo || null;
                        params.where = where;
                        qTask.execute(params).then(getResults).otherwise(promiseRejected);
                        function getResults(response) {
                            if (response.features.length == 0) {
                                window.parent.postMessage(
                                    {
                                        method: "newOpenLayer",
                                        data: ["参数name填写错误"]
                                    },
                                    '*'
                                );
                                return;
                            }
                            var feature = response.features[0];
                            var attributewhere = response.features[0].attributes[attributename];
                            var layerwhere = layerCondition + "='" + attributewhere + "'";
                            // var symbolJson = LayerJsonData.drawingInfo.renderer;
                            newOpenLayerbyWhere(layerName, isOpen, layerCondition, attributewhere);
                            if (isGoTo) {
                                m_view.goTo(feature.geometry);
                            }
                        }

                        function promiseRejected(err) {
                            //console.error("错误信息: ", err.message);
                        }
                    }
                };
            });
    }
}
function newOpenLayerbyWhere(layerName, layerVisible, layerCondition, attributewhere) {

    if (!layerVisible) {
        var layerId = GetFeatureLayerIdbyName(layerName);
        // var qxlayerId = GetQXFeatureLayerIdbyName(layerName);
        for (var i = 0; i < m_map.layers.length; i++) {
            var BaseLayer = m_map.layers.getItemAt(i);
            if (BaseLayer.declaredClass == "esri.layers.FeatureLayer") {
                var layer = m_map.layers.getItemAt(i);
                if (layer.id == layerId) {
                    // m_map.layers.getItemAt(i).renderer = layerRenerer;
                    m_map.layers.getItemAt(i).visible = layerVisible;
                    m_map.remove(m_map.layers.getItemAt(i));
                }
                if (layer.id == layerId + "_qx") {
                    // m_map.layers.getItemAt(i).renderer = layerRenerer;
                    m_map.layers.getItemAt(i).visible = layerVisible;
                    m_map.remove(m_map.layers.getItemAt(i));
                }
            }
        }
        return;
    }

    require(["esri/layers/FeatureLayer", "dojo/on"], function (FeatureLayer, on) {
        var serverUrl = GetConfigDataByName("MYFeatureLayerLayer");
        var layerId = GetFeatureLayerIdbyName(layerName);
        var qxserverUrl = GetConfigDataByName("MYQXFeatureLayer");
        var qxlayerId = GetQXFeatureLayerIdbyName(layerName);
        var isnewFeatureLayer = true;
        for (var i = 0; i < m_map.layers.length; i++) {
            var BaseLayer = m_map.layers.getItemAt(i);
            if (BaseLayer.declaredClass == "esri.layers.FeatureLayer") {
                var layer = m_map.layers.getItemAt(i);
                if (layer.id == layerId) {
                    // m_map.layers.getItemAt(i).renderer = layerRenerer;
                    m_map.layers.getItemAt(i).visible = layerVisible;
                    isnewFeatureLayer = false;
                }
                if (layer.id == layerId + "_qx") {
                    m_map.layers.getItemAt(i).visible = layerVisible;
                    isnewFeatureLayer = false;
                }
            }
        }

        if (isnewFeatureLayer) {
            var dyLayer = new FeatureLayer({
                url: serverUrl + "/" + layerId,
                id: layerId,
                definitionExpression: layerCondition + "=" + attributewhere
            });
            var qxdyLayer;
            if (qxlayerId != -1) {
                qxdyLayer = new FeatureLayer({
                    url: qxserverUrl + "/" + qxlayerId,
                    id: layerId + "_qx",
                    definitionExpression: layerCondition + "=" + attributewhere
                });
                qxdyLayer.visible = layerVisible;
                qxdyLayer.outFields = ["*"];
                m_map.add(qxdyLayer, 1);
            }

            var clusterConfig = {
                type: "cluster",
                clusterRadius: "50px"
            };
            // dyLayer.renderer = layerRenerer;
            // dyLayer.featureReduction = clusterConfig;
            dyLayer.visible = layerVisible;
            dyLayer.outFields = ["*"];
            m_map.add(dyLayer, 2);
        }
    });

    // require([
    //     "esri/layers/FeatureLayer",
    //     "dojo/on"
    // ], function ( FeatureLayer,on) {
    //     var layerId = GetFeatureLayerIdbyName(layerName);
    //     var urlI = dyLayer.url + "/" + layerId;
    //     var restUrl = urlI + "?f=pjson";
    //     var xmlHttpRest = GetXmlHttpObject();
    //     xmlHttpRest.open("GET", restUrl, true);
    //     xmlHttpRest.send();
    //     xmlHttpRest.onreadystatechange = function() {
    //         if (xmlHttpRest.readyState == 4) {
    //             var responseText = xmlHttpRest.responseText;
    //             var LayerJsonData = JSON.parse(responseText);
    //             var renderer = LayerJsonData.drawingInfo.renderer;
    //             var  newsymbol;
    //             var symbol = LayerJsonData.drawingInfo.renderer.symbol;
    //             if (LayerJsonData) {
    //                 if (symbol.type == "esriSFS") {
    //                     newsymbol = {
    //                         type: "simple-fill",
    //                         style: changeStyle(symbol.style),
    //                         color: symbol.color,
    //                         outline: {
    //                             style: changeStyle(symbol.outline.style),
    //                             color: symbol.outline.color,
    //                             width: symbol.outline.width
    //                         }
    //                     }
    //                 } else if (symbol.type == "esriPMS") {
    //                     newsymbol = {
    //                         type: "picture-marker",
    //                         url: "data:image/png;base64," + symbol.imageData,
    //                         width: symbol.width,
    //                         height: symbol.height
    //                     }
    //                 } else if (symbol.type == "esriSMS") {
    //                     newsymbol = {
    //                         type: "simple-marker",
    //                         size: symbol.size,
    //                         color: symbol.color,
    //                         outline: symbol.outline
    //                     }
    //                 }
    //             }
    //
    //
    //             var layerRenerer = {
    //                 type: "unique-value",
    //                 field: layerCondition,
    //                 uniqueValueInfos: [{
    //                     value: attributewhere,
    //                     symbol: newsymbol
    //                 }]
    //             };
    //
    //
    //             var serverUrl = GetConfigDataByName("MYFeatureLayerLayer");
    //
    //             var isnewFeatureLayer = true;
    //             for (var i = 0; i < m_map.layers.length; i++) {
    //                 var BaseLayer = m_map.layers.getItemAt(i);
    //                 if (BaseLayer.declaredClass == "esri.layers.FeatureLayer") {
    //                     var layer = m_map.layers.getItemAt(i);
    //                     if (layer.id == layerId) {
    //                         m_map.layers.getItemAt(i).renderer = layerRenerer;
    //                         m_map.layers.getItemAt(i).visible = layerVisible;
    //                         isnewFeatureLayer = false;
    //                         break;
    //                     }
    //                 }
    //             }
    //             if(isnewFeatureLayer){
    //                 var dyLayer = new FeatureLayer({
    //                     url: serverUrl+"/"+layerId,
    //                     id: layerId,
    //                     definitionExpression: layerCondition+"="+attributewhere
    //                 });
    //                 var clusterConfig={
    //                     type: "cluster",
    //                     clusterRadius: "50px"
    //                 };
    //                 // dyLayer.renderer = layerRenerer;
    //                 dyLayer.visible = layerVisible;
    //                 dyLayer.outFields = ["*"];
    //                 m_map.add(dyLayer,1);
    //                 dyLayer.featureReduction = clusterConfig;
    //             }
    //         }
    //     };
    // });
}

function setLayerCluster(layerName, iscluster) {
    var layerId = GetFeatureLayerIdbyName(layerName);
    for (var i = 0; i < m_map.layers.length; i++) {
        var BaseLayer = m_map.layers.getItemAt(i);
        if (BaseLayer.declaredClass == "esri.layers.FeatureLayer") {
            var layer = m_map.layers.getItemAt(i);
            if (layer.id == layerId) {
                // m_map.layers.getItemAt(i).visible = layerVisible;
                if (iscluster) {
                    m_map.layers.getItemAt(i).featureReduction = {
                        type: "cluster",
                        clusterRadius: "50px"
                    };
                }
                else {
                    m_map.layers.getItemAt(i).featureReduction = null;
                }
                break;
            }
        }
    }
}

function newQuerybyWhereStr(whereStr, layerName, url, geo, isshow, isGoTo) {

    if (whereStr == "")
        whereStr = "1=1";
    if (isshow == undefined || isshow == null)
        isshow = true;
    if (isGoTo == undefined || isGoTo == null)
        isGoTo = true;
    var layerId = GetFeatureLayerIdbyName(layerName);
    if (layerId == -1) {
        // alert("没有此图层");
        window.parent.postMessage(
            {
                method: "queryByGeometryAndLayer",
                data: ["没有此图层"]
            },
            '*'
        );
    } else {
        newQueryGraphicByDylayer(layerId, whereStr, url, geo, isshow, isGoTo);
    }
}
function newQueryGraphicByDylayer(layerId, whereStr, url, geo, isshow, isGoTo) {
    require(["esri/tasks/QueryTask", "esri/tasks/support/Query", "esri/layers/FeatureLayer", "dojo/_base/array", "dojo/dom"],
        function (QueryTask, Query, FeatureLayer, arrayUtils, dom) {
            btClear_Click();
            var urlI = dyLayer.url + "/" + layerId;

            var restUrl = urlI + "?f=pjson";
            var xmlHttpRest = GetXmlHttpObject();
            xmlHttpRest.open("GET", restUrl, true);
            xmlHttpRest.send();
            xmlHttpRest.onreadystatechange = function () {
                var responseText = xmlHttpRest.responseText;
                if (xmlHttpRest.readyState == 4) {
                    var LayerJsonData = JSON.parse(responseText);
                    var qTask = new QueryTask({
                        url: urlI
                    });
                    var params = new Query({
                        geometry: queryExtent,
                        returnGeometry: true,
                        outFields: ["*"]
                    });
                    params.spatialRelationship = "intersects";
                    params.geometry = geo || null;
                    params.where = whereStr;
                    qTask.execute(params).then(getResults).otherwise(promiseRejected);
                    function getResults(response) {
                        if (response.features.length == 0) {
                            window.parent.postMessage(
                                {
                                    method: "queryByGeometryAndLayer",
                                    data: []
                                },
                                '*'
                            );
                            return;
                        }
                        var attributesArr = [];
                        var peakResults = arrayUtils.map(response.features,
                            function (feature) {
                                var obj = LayerJsonData;
                                attributesArr.push(feature.attributes);
                                var symbolJson = obj.drawingInfo.renderer.symbol;
                                if (currentMapMode == "2D") {
                                    if (symbolJson) {
                                        if (symbolJson.type == "esriSFS") {
                                            feature.symbol = {
                                                type: "simple-fill",
                                                style: changeStyle(symbolJson.style),
                                                color: symbolJson.color,
                                                outline: {
                                                    style: changeStyle(symbolJson.outline.style),
                                                    color: symbolJson.outline.color,
                                                    width: symbolJson.outline.width
                                                }
                                            }
                                        } else if (symbolJson.type == "esriPMS") {
                                            feature.symbol = {
                                                type: "picture-marker",
                                                url: "data:image/png;base64," + symbolJson.imageData,
                                                width: symbolJson.width,
                                                height: symbolJson.height
                                            }
                                        } else if (symbolJson.type == "esriSMS") {
                                            feature.symbol = {
                                                type: "simple-marker",
                                                size: symbolJson.size,
                                                color: symbolJson.color,
                                                outline: symbolJson.outline
                                            }
                                        }
                                    } else {
                                        feature.symbol = {
                                            type: "simple-marker",
                                            color: rgba(255, 0, 0, 1),
                                            outline: {
                                                color: [0, 0, 0, 1],
                                                width: 1
                                            }
                                        }
                                    }
                                } else {
                                    var verticalOffset = {
                                        screenLength: 40,
                                        maxWorldLength: 200,
                                        minWorldLength: 35
                                    };
                                    if (symbolJson.type == "esriSFS") {
                                        feature.symbol = {
                                            type: "polygon-3d",
                                            symbolLayers: [{
                                                type: "fill",
                                                material: {
                                                    color: symbolJson.color
                                                }
                                            }],
                                            outline: {
                                                color: symbolJson.outline.color,
                                                size: symbolJson.outline.size
                                            }
                                        }
                                    } else if (symbolJson.type == "esriPMS") {
                                        feature.symbol = {
                                            type: "point-3d",
                                            symbolLayers: [{
                                                type: "icon",
                                                resource: {
                                                    href: "data:image/png;base64," + symbolJson.imageData
                                                },
                                                size: 20,
                                                outline: {
                                                    color: "white",
                                                    size: 2
                                                }
                                            }],
                                            verticalOffset: verticalOffset,
                                            callout: {
                                                type: "line",
                                                color: "white",
                                                size: 2,
                                                border: {
                                                    color: "#40C2B4"
                                                }
                                            }
                                        }
                                    } else if (symbolJson.style == "esriSMSCircle") {
                                        feature.symbol = {
                                            type: "point-3d",
                                            symbolLayers: [{
                                                type: "icon",
                                                resource: {
                                                    primitive: "circle"
                                                },
                                                size: symbolJson.size * 2,
                                                material: {
                                                    color: symbolJson.color
                                                },
                                                outline: {
                                                    color: symbolJson.outline.color,
                                                    size: symbolJson.outline.size
                                                }
                                            }],
                                            verticalOffset: verticalOffset,
                                            callout: {
                                                type: "line",
                                                color: "white",
                                                size: 2,
                                                border: {
                                                    color: "#40C2B4"
                                                }
                                            }
                                        }
                                    }
                                }
                                feature.geometry.spatialReference = m_view.spatialReference;
                                var popupTemplate = {
                                    title: "详细信息",
                                    content: attributesToHTMLStr(feature.attributes)
                                };
                                // feature.popupTemplate = popupTemplate;
                                return feature
                            });
                        if (isshow) {
                            GraphicsLayer_myLayer.addMany(peakResults);
                            if (isGoTo) {
                                m_view.goTo(peakResults);
                            }

                        }

                        window.parent.postMessage(
                            {
                                method: "queryByGeometryAndLayer",
                                data: [attributesArr]
                            },
                            '*'
                        );
                    }

                    function promiseRejected(err) {
                        console.error("错误信息: ", err.message);
                    }
                }
            }

        });
}
function querybyWhereStr(whereStr, layerName) {
    if (whereStr == "") {
        whereStr = "  1=1 "
    }
    var layerId = GetFeatureLayerIdbyName(layerName);
    if (layerId == -1) {
        alert("没有此图层")
    } else {
        queryGraphicByDylayer(layerId, whereStr, "http://10.101.35.46:6080/arcgis/rest/services/WJJBH/FeatureServer")
    }
}
function GetFeatureLayerIdbyName(layerName) {
    var layerId = -1;
    if (extraLayerJsonData != "") {
        var layers = extraLayerJsonData.layers;
        if (layers.length > 0) {
            for (var i = 0; i < layers.length; i++) {
                // if (layers[i].name == layerName && layers[i].subLayerIds == null) {
                //     layerId = layers[i].id;
                //     break;
                // }
                if (layers[i].name == layerName) {
                    if (layers[i].subLayerIds == null) {
                        layerId = layers[i].id;
                    }
                    else {
                        if (layers[i].subLayerIds.length == 1)
                            layerId = layers[i].subLayerIds[0];
                        else
                            layerId = layers[i].subLayerIds[1];
                    }
                    break;
                }
            }
        }
    }
    return layerId;
}
function GetQXFeatureLayerIdbyName(layerName) {
    var layerId = -1;
    if (qxLayerJsonData != "") {
        var layers = qxLayerJsonData.layers;
        if (layers.length > 0) {
            for (var i = 0; i < layers.length; i++) {
                // if (layers[i].name == layerName && layers[i].subLayerIds == null) {
                //     layerId = layers[i].id;
                //     break;
                // }
                if (layers[i].name == layerName) {
                    if (layers[i].subLayerIds == null) {
                        layerId = layers[i].id;
                    }
                    else {
                        if (layers[i].subLayerIds.length == 1)
                            layerId = layers[i].subLayerIds[0];
                        else
                            layerId = layers[i].subLayerIds[1];
                    }
                    break;
                }
            }
        }
    }
    return layerId;
}
function queryAll() {
    queryList.splice(0, queryList.length);
    if (currentMapMode == "3D") {
        var select = document.getElementById("quertLayerSelect");
        queryRecursive(select.value)
    } else {
        queryRecursive(0);
        progress("0%")
    }
}
function queryRecursive(j) {
    var layerInfo = GetDynamicServiceLayer();
    if (currentMapMode == "2D") {
        if (j == Math.ceil(layerInfo.length / 4)) {
            progress("30%")
        }
        if (j === Math.ceil(layerInfo.length / 2)) {
            progress("60%")
        }
        if (j === Math.ceil(layerInfo.length * 3 / 4)) {
            progress("90%")
        }
        if (j >= layerInfo.length) {
            progress("100%")
        }
    }
    var name = document.getElementById("name").value;
    if (j == layerInfo.length) {
        if (queryList.length == 0) {
            alert("没有结果");
            return
        }
        m_view.goTo(GraphicsLayer_myLayer.graphics);
        dyCretateTableByArray("queryTable1", queryList, ["名称", "图层名"], ["名称", "图层名"], false, true);
        goPage(1, "queryTable1");
        return
    }
    var layerField = "";
    var xmlDoc1 = xmlUtil.loadXmlFromFile("config/layerQueryName.xml");
    var layerXml = xmlDoc1.getElementsByTagName(GetLayerNamebyId(j));
    var mapNodes = layerXml[0].childNodes;
    for (var i = 0; i < mapNodes.length; i++) {
        if (xmlUtil.getNodeTagName(mapNodes[i]) == "name") {
            layerField = xmlUtil.getNodeValue(mapNodes[i])
        }
    }
    if (j < layerInfo.length) {
        require(["esri/tasks/QueryTask", "esri/tasks/support/Query", "esri/layers/FeatureLayer", "dojo/_base/array", "esri/Graphic", "dojo/dom"],
            function (QueryTask, Query, FeatureLayer, arrayUtils, Graphic, dom) {
                var urlI = dyLayer.url + "/" + j;
                var qTask = new QueryTask({
                    url: urlI
                });
                var params = new Query({
                    geometry: queryExtent,
                    returnGeometry: true,
                    outFields: ["*"]
                });
                var where;
                if (name == null || name == "") {
                    where = "1=1"
                } else {
                    where = layerField + " like '%" + name + "%' "
                }
                params.where = where;
                qTask.execute(params).then(getResults).otherwise(promiseRejected);
                function getResults(response) {
                    var peakResults = arrayUtils.map(response.features,
                        function (feature) {
                            var obj = eval("(" + symble[j] + ")");
                            var symbolJson = obj.drawingInfo.renderer.symbol;
                            if (currentMapMode == "2D") {
                                if (symbolJson.type == "esriSFS") {
                                    feature.symbol = {
                                        type: "simple-fill",
                                        style: changeStyle(symbolJson.style),
                                        color: symbolJson.color,
                                        outline: {
                                            style: changeStyle(symbolJson.outline.style),
                                            color: symbolJson.outline.color,
                                            width: symbolJson.outline.width
                                        }
                                    }
                                } else if (symbolJson.type == "esriPMS") {
                                    feature.symbol = {
                                        type: "picture-marker",
                                        url: "data:image/png;base64," + symbolJson.imageData,
                                        width: symbolJson.width,
                                        height: symbolJson.height
                                    }
                                }
                            } else {
                                var verticalOffset = {
                                    screenLength: 40,
                                    maxWorldLength: 200,
                                    minWorldLength: 35
                                };
                                if (symbolJson.type == "esriSFS") {
                                    for (var i = 0; i < feature.geometry.rings[0].length; i++) {
                                        feature.geometry.rings[0][i].push(20)
                                    }
                                    var polygon = {
                                        type: "polygon",
                                        rings: feature.geometry.rings
                                    };
                                    var polygonGraphic = new Graphic({
                                        geometry: polygon
                                    });
                                    polygonGraphic.symbol = {
                                        type: "polygon-3d",
                                        symbolLayers: [{
                                            type: "fill",
                                            material: {
                                                color: symbolJson.color
                                            },
                                            outline: {
                                                color: symbolJson.outline.color,
                                                size: symbolJson.outline.size
                                            }
                                        }]
                                    }
                                } else if (symbolJson.type == "esriPMS") {
                                    feature.symbol = {
                                        type: "point-3d",
                                        symbolLayers: [{
                                            type: "icon",
                                            resource: {
                                                href: "data:image/png;base64," + symbolJson.imageData
                                            },
                                            size: 20,
                                            outline: {
                                                color: "white",
                                                size: 2
                                            }
                                        }],
                                        verticalOffset: verticalOffset,
                                        callout: {
                                            type: "line",
                                            color: "white",
                                            size: 2,
                                            border: {
                                                color: "#40C2B4"
                                            }
                                        }
                                    }
                                } else if (symbolJson.style == "esriSMSCircle") {
                                    feature.symbol = {
                                        type: "point-3d",
                                        symbolLayers: [{
                                            type: "icon",
                                            resource: {
                                                primitive: "circle"
                                            },
                                            size: symbolJson.size * 2,
                                            material: {
                                                color: symbolJson.color
                                            },
                                            outline: {
                                                color: symbolJson.outline.color,
                                                size: symbolJson.outline.size
                                            }
                                        }],
                                        verticalOffset: verticalOffset,
                                        callout: {
                                            type: "line",
                                            color: "white",
                                            size: 2,
                                            border: {
                                                color: "#40C2B4"
                                            }
                                        }
                                    }
                                }
                            }
                            feature.geometry.spatialReference = m_view.spatialReference;
                            var popupTemplate = {
                                title: "详细信息",
                                content: "所在图层：" + GetLayerNamebyId(j) + "<br>" + attributesToHTMLStr(feature.attributes)
                            };
                            feature.popupTemplate = popupTemplate;
                            var attInfo = [];
                            for (var name in feature.attributes) {
                                attInfo.push({
                                    "属性": name,
                                    "值": feature.attributes[name]
                                })
                            }
                            var list = {
                                "名称": feature.attributes[layerField],
                                "图层名": GetLayerNamebyId(j),
                                "详情": attInfo,
                                "几何": feature
                            };
                            queryList.push(list);
                            if (currentMapMode == "3D") {
                                if (symbolJson.type == "esriSFS") {
                                    polygonGraphic.geometry.spatialReference = m_view.spatialReference;
                                    polygonGraphic.popupTemplate = popupTemplate;
                                    return polygonGraphic
                                }
                            }
                            return feature
                        });
                    GraphicsLayer_myLayer.addMany(peakResults);
                    if (currentMapMode == "3D") {
                        if (queryList.length == 0) {
                            alert("没有结果");
                            return
                        }
                        m_view.goTo(GraphicsLayer_myLayer.graphics);
                        dyCretateTableByArray("queryTable1", queryList, ["名称", "图层名"], ["名称", "图层名"], false, true);
                        goPage(1, "queryTable1")
                    } else {
                        queryRecursive(j + 1)
                    }
                }

                function promiseRejected(err) {
                    console.error("图层：" + j + "错误信息: ", err.message)
                }
            })
    }
}
function queryBySquare() {
    queryExtent = null;
    require(["esri/Map", "esri/views/MapView", "esri/layers/MapImageLayer", "esri/layers/TileLayer", "esri/geometry/Geometry", "esri/geometry/Extent", "esri/tasks/GeometryService", "esri/layers/GraphicsLayer", "esri/widgets/ScaleBar", "esri/WebMap", "esri/geometry/SpatialReference", "esri/Graphic", "esri/views/2d/draw/Draw", "esri/geometry/Polygon", "esri/geometry/geometryEngine"],
        function (Map, MapView, MapImageLayer, TileLayer, Geometry, Extent, GeometryService, GraphicsLayer, ScaleBar, WebMap, SpatialReference, Graphic, Draw, Polygon, geometryEngine) {
            var action = m_drawtool.create("polygon");
            m_view.focus();
            action.on("vertex-add", drawPolygon);
            action.on("cursor-update", drawPolygon);
            action.on("vertex-remove", drawPolygon);
            action.on("draw-complete", drawPolygonEnd);
            function drawPolygon(evt) {
                var vertices = evt.vertices;
                btClear_Click();
                var polygon = createPolygon(vertices);
                var graphic = createGraphic(polygon);
                GraphicsLayer_DrawLayer.add(graphic);
                queryExtent = polygon
            }

            function drawPolygonEnd(evt) {
                drawPolygon(evt);
                queryAll()
            }

            function createPolygon(vertices) {
                return new Polygon({
                    rings: vertices,
                    spatialReference: m_view.spatialReference
                })
            }

            function createGraphic(polygon) {
                graphic = new Graphic({
                    geometry: polygon,
                    symbol: {
                        type: "simple-fill",
                        color: [178, 102, 234, .8],
                        style: "solid",
                        outline: {
                            color: [255, 255, 255],
                            width: 2
                        }
                    }
                });
                return graphic
            }
        })
}
function queryByStreet() {
    document.getElementById("name").value = "";
    queryExtent = null;
    btClear_Click();
    var action = m_drawtool.create("point");
    action.on("draw-complete",
        function (evt) {
            createPointGraphic(evt.coordinates, "街道乡镇")
        })
}
function queryByCommittees() {
    document.getElementById("name").value = "";
    queryExtent = null;
    btClear_Click();
    var action = m_drawtool.create("point");
    action.on("draw-complete",
        function (evt) {
            createPointGraphic(evt.coordinates, "村居委会")
        })
}
function createPointGraphic(coordinates, layerName) {
    require(["esri/geometry/Point"],
        function (Point) {
            m_view.graphics.removeAll();
            var point = new Point({
                x: coordinates[0],
                y: coordinates[1],
                spatialReference: m_view.spatialReference
            });
            queryExtent = point;
            queryExtentByPoint(layerName)
        })
}
function queryExtentByPoint(layerName) {
    var id = GetLayerIdbyName(layerName);
    require(["esri/tasks/QueryTask", "esri/tasks/support/Query", "esri/layers/FeatureLayer", "dojo/_base/array", "dojo/dom"],
        function (QueryTask, Query, FeatureLayer, arrayUtils, dom) {
            var urlI = dyLayer.url + "/" + id;
            var qTask = new QueryTask({
                url: urlI
            });
            var params = new Query({
                geometry: queryExtent,
                returnGeometry: true,
                outFields: ["*"]
            });
            params.where = "1=1";
            qTask.execute(params).then(getResults).otherwise(promiseRejected);
            function getResults(response) {
                var peakResults = arrayUtils.map(response.features,
                    function (feature) {
                        feature.geometry.spatialReference = m_view.spatialReference;
                        queryExtent = null;
                        queryExtent = feature.geometry;
                        return feature
                    });
                if (peakResults.length == 0) {
                    alert("无此范围" + layerName)
                } else {
                    queryAll()
                }
            }

            function promiseRejected(err) {
                console.error("错误信息: ", err.message)
            }
        })
}
function createLayerSelect(selectId) {
    var select = document.getElementById(selectId);
    select.innerHTML = "";
    var layerInfo;
    layerInfo = GetDynamicServiceLayer();
    if (layerInfo != null) {
        for (var j = layerInfo.length; j > 0; j--) {
            var option = document.createElement("option");
            var currnetLayer = layerInfo.getItemAt(j - 1);
            option.innerHTML = currnetLayer.title;
            option.value = currnetLayer.id;
            select.append(option)
        }
    }
}
function openStatistics() {
    document.getElementById("statistics").style.display = "";
    document.getElementById("statistics1").style.display = "";
    document.getElementById("statistics2").style.display = "none";
    document.getElementById("statistics3").style.display = "none";
    document.getElementById("statistics4").style.display = "none";
    createLayerSelect("statistics1LayerSelect");
    createStreetCheck("statistics1CheckTable", "街道乡镇")
}
function closeStatistics() {
    document.getElementById("statistics").style.display = "none"
}
function returnTostatistic1() {
    document.getElementById("statistics1").style.display = "";
    document.getElementById("statistics2").style.display = "none"
}
function returnTostatistic2() {
    document.getElementById("statistics2").style.display = "";
    document.getElementById("statistics3").style.display = "none"
}
function returnTostatistic3() {
    document.getElementById("statistics3").style.display = "";
    document.getElementById("statistics4").style.display = "none"
}
function createStreetCheck(tableId, layerName) {
    require(["esri/tasks/QueryTask", "esri/tasks/support/Query", "esri/layers/FeatureLayer", "dojo/_base/array", "dojo/dom"],
        function (QueryTask, Query, FeatureLayer, arrayUtils, dom) {
            var urlI = dyLayer.url + "/" + GetLayerIdbyName(layerName);
            var qTask = new QueryTask({
                url: urlI
            });
            var params = new Query({
                returnGeometry: true,
                outFields: ["*"]
            });
            params.where = "1=1";
            qTask.execute(params).then(getResults).otherwise(promiseRejected);
            function getResults(response) {
                var peakResults = arrayUtils.map(response.features,
                    function (feature) {
                        return feature
                    });
                var tbody = document.getElementById(tableId);
                tbody.innerHTML = "";
                for (var j = 0; j < peakResults.length; j++) {
                    if (j % 2 == 1) {
                        var tr = document.createElement("tr");
                        var td1 = document.createElement("td");
                        td1.setAttribute("style", "width:230px;height:30px");
                        td1.setAttribute("align", "left");
                        var input1 = document.createElement("input");
                        input1.setAttribute("type", "checkbox");
                        input1.setAttribute("name", "statistics1CheckBox");
                        input1.value = peakResults[j - 1].attributes.名称;
                        td1.append(input1);
                        td1.append(peakResults[j - 1].attributes.名称);
                        var td2 = document.createElement("td");
                        td2.setAttribute("style", "width:230px;height:30px");
                        td2.setAttribute("align", "left");
                        var input2 = document.createElement("input");
                        input2.setAttribute("type", "checkbox");
                        input2.setAttribute("name", "statistics1CheckBox");
                        input2.value = peakResults[j].attributes.名称;
                        td2.append(input2);
                        td2.append(peakResults[j].attributes.名称);
                        tr.append(td1);
                        tr.append(td2);
                        tbody.append(tr)
                    } else if (j == peakResults.length - 1) {
                        var tr = document.createElement("tr");
                        var td1 = document.createElement("td");
                        td1.setAttribute("style", "width:230px;height:30px");
                        td1.setAttribute("align", "left");
                        var input1 = document.createElement("input");
                        input1.setAttribute("type", "checkbox");
                        input1.setAttribute("name", "statistics1CheckBox");
                        input1.value = peakResults[j - 1].attributes.名称;
                        td1.append(input1);
                        td1.append(peakResults[j - 1].attributes.名称);
                        var td2 = document.createElement("td");
                        tr.append(td1);
                        tr.append(td2);
                        tbody.append(tr)
                    }
                }
            }

            function promiseRejected(err) {
                console.error("错误信息: ", err.message)
            }
        })
}
function statistic() {
    var checks = document.getElementsByName("statistics1CheckBox");
    statisticCheckBoxArray.splice(0, statisticCheckBoxArray.length);
    for (var i = 0; i < checks.length; i++) {
        if (checks[i].checked) {
            statisticCheckBoxArray.push(checks[i].value)
        }
    }
    if (statisticCheckBoxArray.length < 1) {
        alert("请至少选择一个街道");
        return
    }
    statisticResultList.splice(0, statisticResultList.length);
    btClear_Click();
    document.getElementById("statistics1").style.display = "none";
    document.getElementById("statistics2").style.display = "";
    recursive(0)
}
function recursive(value) {
    if (value < statisticCheckBoxArray.length) {
        var options = document.getElementById("statistics1LayerSelect").options;
        queryPolygonByStatistic(statisticCheckBoxArray[value], options[options.selectedIndex].value, value)
    }
}
function queryPolygonByStatistic(name, urlid, value) {
    require(["esri/tasks/QueryTask", "esri/tasks/support/Query", "esri/layers/FeatureLayer", "dojo/_base/array", "dojo/dom"],
        function (QueryTask, Query, FeatureLayer, arrayUtils, dom) {
            var url = dyLayer.url + "/" + GetLayerIdbyName("街道乡镇");
            var qTask = new QueryTask({
                url: url
            });
            var params = new Query({
                returnGeometry: true,
                outFields: ["*"]
            });
            params.where = "名称='" + name + "'";
            qTask.execute(params).then(getResults).otherwise(promiseRejected);
            function getResults(response) {
                var peakResults = arrayUtils.map(response.features,
                    function (feature) {
                        return feature
                    });
                queryPointByStatistic(peakResults[0].geometry, urlid, value)
            }

            function promiseRejected(err) {
                console.error("错误信息: ", err.message)
            }
        })
}
function queryPointByStatistic(geometry, urlid, value) {
    require(["esri/tasks/QueryTask", "esri/tasks/support/Query", "esri/layers/FeatureLayer", "dojo/_base/array", "dojo/dom"],
        function (QueryTask, Query, FeatureLayer, arrayUtils, dom) {
            var url = dyLayer.url + "/" + urlid;
            var qTask = new QueryTask({
                url: url
            });
            var params = new Query({
                geometry: geometry,
                returnGeometry: true,
                outFields: ["*"]
            });
            params.where = "1=1";
            qTask.execute(params).then(getResults).otherwise(promiseRejected);
            function getResults(response) {
                var peakResults = arrayUtils.map(response.features,
                    function (feature) {
                        if (currentMapMode == "2D") {
                            var obj = eval("(" + symble[urlid] + ")");
                            var symbolJson = obj.drawingInfo.renderer.symbol;
                            if (symbolJson.type == "esriSFS") {
                                feature.symbol = {
                                    type: "simple-fill",
                                    style: changeStyle(symbolJson.style),
                                    color: symbolJson.color,
                                    outline: {
                                        style: changeStyle(symbolJson.outline.style),
                                        color: symbolJson.outline.color,
                                        width: symbolJson.outline.width
                                    }
                                }
                            } else if (symbolJson.type == "esriPMS") {
                                feature.symbol = {
                                    type: "picture-marker",
                                    url: "data:image/png;base64," + symbolJson.imageData,
                                    width: symbolJson.width,
                                    height: symbolJson.height
                                }
                            } else if (symbolJson.style == "esriSMSCircle") {
                                feature.symbol = {
                                    type: "simple-marker",
                                    style: "circle",
                                    color: symbolJson.color,
                                    size: symbolJson.size,
                                    outline: {
                                        color: symbolJson.outline.color,
                                        width: symbolJson.outline.width
                                    }
                                }
                            }
                        } else {
                            var verticalOffset = {
                                screenLength: 40,
                                maxWorldLength: 200,
                                minWorldLength: 35
                            };
                            var obj = eval("(" + symble[urlid] + ")");
                            var symbolJson = obj.drawingInfo.renderer.symbol;
                            if (symbolJson.type == "esriSFS") {
                                for (var i = 0; i < feature.geometry.rings[0].length; i++) {
                                    feature.geometry.rings[0][i].push(20)
                                }
                                var polygon = {
                                    type: "polygon",
                                    rings: feature.geometry.rings
                                };
                                var polygonGraphic = new Graphic({
                                    geometry: polygon
                                });
                                polygonGraphic.symbol = {
                                    type: "polygon-3d",
                                    symbolLayers: [{
                                        type: "fill",
                                        material: {
                                            color: symbolJson.color
                                        },
                                        outline: {
                                            color: symbolJson.outline.color,
                                            size: symbolJson.outline.size
                                        }
                                    }]
                                }
                            } else if (symbolJson.type == "esriPMS") {
                                feature.symbol = {
                                    type: "point-3d",
                                    symbolLayers: [{
                                        type: "icon",
                                        resource: {
                                            href: "data:image/png;base64," + symbolJson.imageData
                                        },
                                        size: 20,
                                        outline: {
                                            color: "white",
                                            size: 2
                                        }
                                    }],
                                    verticalOffset: verticalOffset,
                                    callout: {
                                        type: "line",
                                        color: "white",
                                        size: 2,
                                        border: {
                                            color: "#40C2B4"
                                        }
                                    }
                                }
                            } else if (symbolJson.style == "esriSMSCircle") {
                                feature.symbol = {
                                    type: "point-3d",
                                    symbolLayers: [{
                                        type: "icon",
                                        resource: {
                                            primitive: "circle"
                                        },
                                        size: symbolJson.size * 2,
                                        material: {
                                            color: symbolJson.color
                                        },
                                        outline: {
                                            color: symbolJson.outline.color,
                                            size: symbolJson.outline.size
                                        }
                                    }],
                                    verticalOffset: verticalOffset,
                                    callout: {
                                        type: "line",
                                        color: "white",
                                        size: 2,
                                        border: {
                                            color: "#40C2B4"
                                        }
                                    }
                                }
                            }
                        }
                        var popupTemplate = {
                            title: "详细信息",
                            content: attributesToHTMLStr(feature.attributes)
                        };
                        if (currentMapMode == "3D") {
                            if (symbolJson.type == "esriSFS") {
                                polygonGraphic.geometry.spatialReference = m_view.spatialReference;
                                polygonGraphic.popupTemplate = popupTemplate;
                                return polygonGraphic
                            }
                        }
                        feature.geometry.spatialReference = m_view.spatialReference;
                        feature.popupTemplate = popupTemplate;
                        return feature
                    });
                statisticResultList.push({
                    "名称": statisticCheckBoxArray[statisticResultList.length],
                    "数量": peakResults.length,
                    "图形集": peakResults
                });
                GraphicsLayer_myLayer.addMany(peakResults);
                if (statisticResultList.length == statisticCheckBoxArray.length) {
                    m_view.goTo(GraphicsLayer_myLayer.graphics);
                    dyCretateTableByArray("statistics2Table", statisticResultList, ["名称", "数量"], ["名称", "数量"], false, true);
                    creatPie(statisticResultList, "statistics2Div2");
                    createBar(statisticResultList, "statistics2Div3")
                }
                recursive(value + 1)
            }

            function promiseRejected(err) {
                console.error("错误信息: ", err.message)
            }
        })
}
function openRoadQuery() {
    document.getElementById("roadQuery").style.display = ""
}
function closeRoadQuery() {
    document.getElementById("roadQuery").style.display = "none"
}
function searchRoadByName() {
    var address = document.getElementById("addressName").value;
    if (address == "") {
        alert("请输入要检索的关键字！");
        return
    }
    openRoadQuery();
    searchRoadName = address;
    searchRoadPage(1)
}
function showRoadPoint(x, y, name) {
    require(["esri/Graphic"],
        function (Graphic) {
            var point = {
                type: "point",
                x: x,
                y: y,
                spatialReference: m_view.spatialReference
            };
            var markerSymbol;
            if (currentMapMode == "2D") {
                markerSymbol = {
                    type: "picture-marker",
                    url: "QPimage/top/layerPopup.png",
                    width: "20px",
                    height: "30px"
                }
            } else {
                var verticalOffset = {
                    screenLength: 40,
                    maxWorldLength: 200,
                    minWorldLength: 35
                };
                markerSymbol = {
                    type: "point-3d",
                    symbolLayers: [{
                        type: "icon",
                        resource: {
                            href: "QPimage/top/layerPopup.png"
                        },
                        size: 20
                    }],
                    verticalOffset: verticalOffset,
                    callout: {
                        type: "line",
                        color: "white",
                        size: 2,
                        border: {
                            color: "#40C2B4"
                        }
                    }
                }
            }
            var pointGraphic = new Graphic({
                geometry: point,
                symbol: markerSymbol
            });
            pointGraphic.attributes = {
                roadname: name
            };
            GraphicsLayer_myLayer.add(pointGraphic)
        })
}
function showRoad(x, y) {
    require(["esri/geometry/Point"],
        function (Point) {
            var point = new Point({
                x: x,
                y: y,
                spatialReference: m_view.spatialReference
            });
            m_view.goTo(point)
        })
}
function doToolTip() {

    m_view.on("pointer-move", eventHandler);
    function eventHandler(event) {
        m_view.hitTest(event).then(getGraphics)
    }

    function getGraphics(response) {
        if (response.results.length) {
            var graphic = response.results.filter(function (result) {
                return result.graphic.layer === GraphicsLayer_myLayer
            })[0].graphic;
            var attributes = graphic.attributes;
            var roadname = attributes.roadname;
            if (roadname != null) {
                document.getElementById("info").style.visibility = "visible";
                document.getElementById("info").innerHTML = roadname
            }
        }
    }
}
function createInfoDiv() {
    var dom = document.createElement("div");
    dom.setAttribute("id", "info");
    dom.setAttribute("style", "background-color: black;opacity: 0.75;color: orange; font-size: 18pt; padding: 8px;visibility: hidden;");
    document.body.appendChild(dom)
}
function showLoadingDiv(message) {
    var loadingDiv = document.createElement("div");
    loadingDiv.setAttribute("id", "divLoading");
    loadingDiv.innerHTML = message;
    var iWidth = 200;
    var iHeight = 50;
    var iTop = (window.screen.height - 30 - iHeight) / 2;
    var iLeft = (window.screen.width - 10 - iWidth) / 2;
    loadingDiv.setAttribute("style", "position: absolute;height:" + iHeight + "px;width:" + iWidth + "px;top:" + iTop + "px;left:" + iLeft + "px;");
    document.body.appendChild(loadingDiv)
}
function removeLoadingDiv() {
    var loadingDiv = document.getElementById("divLoading");
    if (loadingDiv) {
        document.body.removeChild(loadingDiv)
    }
}
function postToParentPageMethed(methedName, data, backFun) {//传数据给父窗口
    window.parent.postMessage(JSON.stringify({method: methedName, data: data, backfun: backFun}), '*');
}
function OpenMapImageLayerByName(layerName, layerVisible, whereStr) {
    if (whereStr == null) {
        whereStr = "1=1"
    }
    if (whereStr == "") {
        whereStr = "1=1"
    }
    if (layerName == "非法行医") {
        var layer = getLayerByLayerId("动态数据");
        var layerId = GetLayerIdbyName("存量点");

        var symbol1 = {
            type: "picture-marker",
            url: "http://10.101.35.46/zhwj/assets/image/ffxyPoint.png",
            width: "20px",
            height: "20px"
        }

        var renderer1 = {
            type: "simple",
            symbol: symbol1
        };
        layer.findSublayerById(layerId).renderer = renderer1
        layer.findSublayerById(layerId).definitionExpression = whereStr;
        layer.findSublayerById(layerId).visible = layerVisible;
    } else if (layerName == "六月内存量零") {
        queryNoFFXYPointArea(6, layerVisible, whereStr)
    } else if (layerName == "十二月内存量零") {
        queryNoFFXYPointArea(12, layerVisible, whereStr)
    } else if (layerName == "街道乡镇") {
        var layer = getLayerByLayerId("动态数据");
        var id = getSubLayerIdbyName(layer, "街道乡镇");
        
        if (layer.findSublayerById(id).sublayers) {
            var subLayer = layer.findSublayerById(id).sublayers.items;
            for (var i = 0; i < subLayer.length; i++) {
                layer.findSublayerById(subLayer[i].id).definitionExpression = whereStr;
            }
        } else {
            layer.findSublayerById(id).definitionExpression = whereStr;
        }
        layer.findSublayerById(id).visible = layerVisible;
         
        layer.findSublayerById(id).renderer ={
            type: "simple",  // autocasts as new PointSymbol3D()
            symbol:{
                type: "simple-fill",
                color: [0,0,0,0],
                style: "solid",
                outline: {
                    color: [168, 168, 0, 255],
                    width: 1
                }
            }
        }
    } else {
        var layer = getLayerByLayerId("density_1");
        var id = getSubLayerIdbyName(layer, layerName);
        if (layer.findSublayerById(id).sublayers) {
            var subLayer = layer.findSublayerById(id).sublayers.items;
            for (var i = 0; i < subLayer.length; i++) {
                layer.findSublayerById(subLayer[i].id).definitionExpression = whereStr;
            }
        } else {
            layer.findSublayerById(id).definitionExpression = whereStr;
        }
        layer.findSublayerById(id).visible = layerVisible;

    }

}
function addZero(num) {
    if (num < 10) {
        return "0" + num;
    } else {
        return num;
    }
}
function HeatMap(type) {
	/*var name="监管对象103_20230829";
	if(type==1){
	name="监管对象103_20230829_1";	
	}else if(type==2){
	name="监管对象103_20230829";	
	}else if(type==3){
	name="监管对象103_20230829_3";	
	}*/
	if(type=='clear'){
	 m_map.remove(getLayerByLayerId("heatLayer"));
	return;
	}else{
	  m_map.remove(getLayerByLayerId("heatLayer"));
	}
    require([ "esri/layers/TileLayer"],
        function ( TileLayer) {
        
            var layer = getLayerByLayerId("heatMap");
            var dyLayer = new TileLayer({
                url: "https://10.101.35.50/arcgis/rest/services/监管对象103_20230829/MapServer",
                id: "heatLayer"
            });
            dyLayer.visible = true;
            m_map.add(dyLayer);
        })
}
function createWZXYFeature() {
    require(["esri/tasks/QueryTask", "esri/tasks/support/StatisticDefinition", "esri/tasks/support/Query", "esri/layers/FeatureLayer", "dojo/_base/array", "dojo/dom", "esri/Graphic",
            "esri/geometry/Point"],
        function (QueryTask, StatisticDefinition, Query, FeatureLayer, arrayUtils, dom, Graphic, Point) {
            var layer2 = getLayerByLayerId("density_1"); 
            var id = getSubLayerIdbyName(layer2, "街道乡镇"); 
            var qTask = new QueryTask({
                url:layer2.url+"/"+id
            });
            var query = new Query();
            query.returnGeometry = true;
            query.outFields = ["*"];
            query.where = "1=1";
            qTask.execute(query).then(getResults).catch(promiseRejected);
            function getResults(response) { 
                const layer = new FeatureLayer({
                    id:"WZXYFeature",
                    source:  response.features,
                    fields: [{
                        name: "ObjectID",
                        alias: "ObjectID",
                        type: "oid"
                    }, {
                        name: "街道名称",
                        alias: "街道名称",
                        type: "string"
                    }],
                    outFields : ["ObjectID","街道名称"],
                    visible:false,
                    objectIdField: "ObjectID",
                    geometryType: "polygon"
                });
                layer.renderer={
                    type: "simple",  // autocasts as new PointSymbol3D()
                    symbol:{
                        type: "simple-fill",  // autocasts as new SimpleFillSymbol()
                        color:  [168, 168, 0, 0.3],
                        style: "solid",
                        outline: {  // autocasts as new SimpleLineSymbol()
                            color: [168, 168, 0, 255],
                            width: 2
                        }
                    }
                }
                m_map.add(layer)
            };
            function promiseRejected(e) {
                console.log(e)
            }
        })
}
 
function queryNoFFXYPointArea(month, layerVisible, whereStr) {// 零无证行医区域
    var layer2 = getLayerByLayerId("density_1");

    if (layerVisible == false) {
        var WZXYFeature = getLayerByLayerId("WZXYFeature");
        WZXYFeature.definitionExpression = "1=1";
        WZXYFeature.visible = false;
        return
    }

    var dt = new Date();
    dt.setMonth(dt.getMonth() - month);
    var where = " 创建日期1 >'" + dt.getFullYear() + "/" + addZero(dt.getMonth() + 1) + "/" + addZero(dt.getDate()) + "'";
    var layerId = GetLayerIdbyName("存量点");
    if (layerId == -1)
        return;
    require(["esri/tasks/QueryTask", "esri/tasks/support/StatisticDefinition", "esri/tasks/support/Query", "esri/layers/FeatureLayer", "dojo/_base/array", "dojo/dom", "esri/Graphic",
            "esri/geometry/Point"],
        function (QueryTask, StatisticDefinition, Query, FeatureLayer, arrayUtils, dom, Graphic, Point) {
		
            var layer = getLayerByLayerId("动态数据");

            var urlI = layer.url + "/" + layerId;
            var qTask = new QueryTask({
                url: urlI
            });
            var query = new Query();
            var levelCount = new StatisticDefinition({
                statisticType: "count",
                onStatisticField: "ID",
                outStatisticFieldName: "level_count"
            });
	    query.outFields = ["*"];
            query.returnGeometry = false;
            query.groupByFieldsForStatistics = ["街道"];
            query.outStatistics = [levelCount];
            query.where = where;

            qTask.execute(query).then(getResults).catch(promiseRejected);
            function getResults(response) {

                var graphiics = response.features;
                var areaWhere = "街道名称 not in (''  ";
                for (var i = 0; i < graphiics.length; i++) {
                    if (i % 10 == 0 && i != 0) {
                        areaWhere += " ) and 街道名称 not in (''"
                    } else {
                        areaWhere += ",'" + graphiics[i].attributes.街道 + "'";
                    }
                }
                areaWhere += ")";

                if (whereStr) {
                    areaWhere += " and " + whereStr;
                }
                var WZXYFeature = getLayerByLayerId("WZXYFeature");
                WZXYFeature.definitionExpression = areaWhere;
                WZXYFeature.visible = layerVisible;


                //  layer2.findSublayerById(id2).definitionExpression = areaWhere;
                // // layer2.findSublayerById(id3).definitionExpression = areaWhere;
                // layer2.findSublayerById(id4).definitionExpression = areaWhere;
                // // layer2.findSublayerById(id5).definitionExpression = areaWhere;
                // layer2.findSublayerById(id2).visible = layerVisible;
                // layer2.findSublayerById(id4).renderer={
                //     type: "simple",  // autocasts as new PointSymbol3D()
                //     symbol:{
                //         type: "simple-fill",  // autocasts as new SimpleFillSymbol()
                //         color:  [168, 168, 0, 0.3],
                //         style: "solid",
                //         outline: {  // autocasts as new SimpleLineSymbol()
                //             color: [168, 168, 0, 255],
                //             width: 2
                //         }
                //     }
                // }
            }

            function promiseRejected(err) {
                console.error("错误信息: ", err.message);
            }

        });
}
function queryNoFFXYPointJCZ(month, layerVisible, radius) {// 零无证行医区域

    var layerId = GetLayerIdbyName("固定监测站");
    if (layerId == -1)
        return;
    require(["esri/tasks/QueryTask", "esri/tasks/support/StatisticDefinition", "esri/tasks/support/Query", "esri/layers/FeatureLayer", "dojo/_base/array", "dojo/dom", "esri/Graphic",
            "esri/geometry/Point"],
        function (QueryTask, StatisticDefinition, Query, FeatureLayer, arrayUtils, dom, Graphic, Point) {

            var layer = getLayerByLayerId("动态数据");
            var urlI = layer.url + "/" + layerId;
            var qTask = new QueryTask({
                url: urlI
            });
            var query = new Query();

            query.returnGeometry = true;
            query.outFields=["*"];
            query.where = "1=1";
            qTask.execute(query).then(getResults).catch(promiseRejected);
            function getResults(response) {
                var graphiics = response.features;
                for (var i = 0; i < graphiics.length; i++) {
                    var x = graphiics[i].geometry.x;
                    var y = graphiics[i].geometry.y;
                        xmlAddPointJCZ(x,y, null, null, null, null, null, null, null, null,radius)
                }
            }

            function promiseRejected(err) {
                console.error("错误信息: ", err.message);
            }

        });
}
function doCorrugatedPointByOid(idLlist) {
    var where = "ORGANIZATION_ID1  in ("
    for (var i = 0; i < idLlist.length; i++) {
        where += "'" + idLlist[i] + "', "
    }
    where += "'0')";


    var layerId = GetLayerIdbyName("医疗机构");

    m_map.remove(corrugatedPointlayer);
    if (layerId == -1)
        return;
    require(["esri/tasks/QueryTask", "esri/tasks/support/Query", "esri/layers/FeatureLayer", "dojo/_base/array", "dojo/dom", "esri/Graphic",
            "esri/geometry/Point"],
        function (QueryTask, Query, FeatureLayer, arrayUtils, dom, Graphic, Point) {
            var layer = getLayerByLayerId("动态数据");
            var urlI = layer.url + "/" + layerId;
            var qTask = new QueryTask({
                url: urlI
            });
            var params = new Query({
                returnGeometry: true,
                outFields: ["*"]
            });
            params.where = where;
            qTask.execute(params).then(getResults).catch(promiseRejected);
            function getResults(response) {
                var graphicArray = []
                if (response.features.length == 0) {
                    return;
                }
                $.each(response.features, function (index, feature) {

                    var point = {
                        type: "point", // autocasts as new Point()
                        x: parseFloat(x),
                        y: parseFloat(y),
                        spatialReference: m_view.spatialReference
                    };

                    var pointGraphic = new Graphic({
                        geometry: feature.geometry,
                        attributes: feature.attributes
                    });
                    graphicArray.push(pointGraphic);
                });
                createCorrugatedPoint(null, graphicArray, m_map);
            }

            function promiseRejected(err) {
                console.error("错误信息: ", err.message);
            }

        });
}
function doClearCorrugatedPoint() {
    m_map.remove(corrugatedPointlayer);
}
function goToGraphic(type,list) {
    require(["esri/tasks/QueryTask", "esri/tasks/support/Query", "esri/layers/FeatureLayer", "dojo/_base/array", "dojo/dom", "esri/Graphic",
            "esri/geometry/Point"],
        function (QueryTask, Query, FeatureLayer, arrayUtils, dom, Graphic, Point) {

            if(type=="点"){
                var pointList=[];
                for(var i=0;i<list.length;i++){
                    var point = {
                        type: "point",
                        x: list[i][0],
                        y:list[i][1],
                        spatialReference: m_view.spatialReference
                    };
                    var markerSymbol = {
                        type: "simple-marker", // autocasts as new SimpleMarkerSymbol()
                        color: [226, 119, 40]
                    };

                    // Create a graphic and add the geometry and symbol to it
                    const pointGraphic = new Graphic({
                        geometry: point,
                        symbol: markerSymbol
                    });
                    pointList.push(pointGraphic)
                }
                m_view.goTo(pointList)
            }else if(type=="街道乡镇"){
                var layer = getLayerByLayerId("动态数据");
                var layerId = getSubLayerIdbyName(layer, "街道乡镇");
                var urlI = layer.url + "/" + layerId;
                var qTask = new QueryTask({
                    url: urlI
                });

                var params = new Query({
                    returnGeometry: true,
                    outFields: ["*"]
                });
                params.where = list;
                qTask.execute(params).then(getResults) ;
                function getResults(response) {

                    m_view.goTo(response.features)
                }
            }else{
                var layer = getLayerByLayerId("density_1");
                var layerId = getSubLayerIdbyName(layer, type);
                var urlI = layer.url + "/" + layerId;
                var qTask = new QueryTask({
                    url: urlI
                });
                var params = new Query({
                    returnGeometry: true,
                    outFields: ["*"]
                }); 
                params.where = list;
                qTask.execute(params).then(getResults) ;
                function getResults(response) {

                    m_view.goTo(response.features)
                }
            }
        })
  
}
function doXyToStreetId(x, y) {

    var layer = getLayerByLayerId("density_1");
    var layerId = getSubLayerIdbyName(layer, "街道乡镇");

    if (layerId == -1) {
        return;
    }
    require(["esri/tasks/QueryTask", "esri/tasks/support/Query", "esri/layers/FeatureLayer", "dojo/_base/array", "dojo/dom", "esri/Graphic",
            "esri/geometry/Point"],
        function (QueryTask, Query, FeatureLayer, arrayUtils, dom, Graphic, Point) {

            var urlI = layer.url + "/" + layerId;
            var qTask = new QueryTask({
                url: urlI
            });
            var params = new Query({
                returnGeometry: true,
                outFields: ["*"]
            });
            var point = {
                type: "point",
                x: x,
                y: y,
                spatialReference: m_view.spatialReference
            };
            params.geometry = point;

            qTask.execute(params).then(getResults).catch(promiseRejected);
            function getResults(response) {

                postToParentPageMethed("doXyToStreetIdReturn", [response.features[0].attributes.街道代码]);
            }

            function promiseRejected(err) {
                console.error("错误信息: ", err.message);
            }

        });
}
function queryResetNumByType(whereStr) {
    var url = xmlUtil.getNodeValue(xmlDoc.getElementsByTagName("WebServiceURL")[0]);
    var sql = "select t.water_source_name,t.water_work_name,t.area_name," +
        "t.water_source_gps_x_cd x1,t.water_source_gps_y_cd y1," +
        "t.water_work_gps_x_cd x2,t.water_work_gps_y_cd y2" +
        ",t.area_gps_x_cd x3,t.area_gps_y_cd y3 from dwd_water_source_tracing t   where  " + whereStr;
    WsCommonClass("QueryDataBaseJson", ["sql"], [sql], sqlReturn, "queryResetNumByType", url);
}
function ShowBuildlayer(where){
	var layer=getLayerByLayerId("建筑物");
	layer.visible=where;
}
function ShowBuildlayerSX(where){
	var layer=getLayerByLayerId("水箱");
	layer.visible=where;
}
function ResettingMap() {
    require(["esri/geometry/Point"],
        function (Point) {
            var centerPoint = new Point({
                //x: 43184,
                //y: -37270,
                x:0,
                y:0,
                z: 258000,
                spatialReference: m_view.spatialReference
            });
            setCameraBypoint(0, centerPoint, 0, 0, currentScale);
        });

}
function consoleXYZ() {
    console.log(m_view.camera.position)
}
function queryWaterTank(id) {
    var url = xmlUtil.getNodeValue(xmlDoc.getElementsByTagName("WebServiceURL")[0]);
    var sql="select t.near_x,t.near_y,t.二次供水设,t.关联二次供 from sxd t where t.objectid="+id;
    WsCommonClass("QueryDataBaseJson", ["sql"], [sql], sqlReturnWater, "queryWaterTank", url);
}
function sqlReturnWater(evt, keyValue) {
            var allCount;
            var pageIndex;
            var jsonArray;
            if (evt[0] != null) {
                allCount = JSON.parse(evt[0].textContent)[0].AllCount;
                pageIndex = JSON.parse(evt[0].textContent)[0].pageIndex;
                jsonArray = JSON.parse(evt[0].textContent)[0].data;
            } else {
                jsonArray = []
            }
            switch (keyValue) {
                case "queryWaterTank":{
                    var arr={"sbh":jsonArray[0].二次供水设,"x":jsonArray[0].near_x,"y":jsonArray[0].near_y,"xq":jsonArray[0].关联二次供};
                    postToParentPageMethed("clickWaterTankReturn", [arr]);
                    break;
                }
            }
        }


function clusterByJson(list,img) {
    require(["esri/layers/FeatureLayer", "esri/Graphic","esri/widgets/Legend"], function(FeatureLayer, Graphic,Legend) {
        m_map.remove(m_map.findLayerById("clusterByJsonLayer"));
       var clusterConfig = {
            type: "cluster",
            clusterRadius: "50px",//多少范围聚合
            labelsVisible: true,
           clusterMinSize:img[1].imgwidth,
           clusterMaxSize:img[1].imgwidth,
           labelingInfo: [
               {
                   symbol: {
                       type: "text",
                       color:"white",
                       font: {
                           size: "12px"
                       }
                   },
                   labelPlacement: "above-center",
                   labelExpressionInfo: {
                       expression: "Text($feature.cluster_count, '#,### ')"
                   },
                   where: '1=1'
               }
           ]
        };

       var graphics=[];
        for(var i=0;i<list.length;i++){
            var point = { // 点坐标
                type: "point",
                x: parseFloat(list[i].cjX),
                y: parseFloat(list[i].cjY),
                spatialReference: m_view.spatialReference
            };
            var Graphics2 = new Graphic({
                geometry: point,
                attributes:{name:list[i].name,id:list[i].id,cameraIndexCode:list[i].cameraIndexCode,
                    cjX:list[i].cjX,cjY:list[i].cjY,latitude:list[i].latitude,longitude:list[i].longitude}
            });
            graphics.push(Graphics2);
        }
         var  markerSymbol = {
             type: "picture-marker",
             url: img[0].src,
             width: img[0].imgwidth,
             height: img[0].imgHeight
         };
        var  markerSymbol1 = {
            type: "picture-marker",
            url: img[1].src,
            width: img[1].imgwidth,
            height: img[1].imgHeight
        };
        var clusterLayer = new FeatureLayer({
            id: "clusterByJsonLayer",
            fields: [{
                name: "name",
                alias: "name",
                type: "string"
            },{
                name: "id",
                alias: "id",
                type: "double"
             },{
                name: "cameraIndexCode",
                alias: "cameraIndexCode",
                type: "string"
            },{
                name: "cjX",
                alias: "cjX",
                type: "double"
            },{
                name: "cjY",
                alias: "cjY",
                type: "double"
            },{
                name: "latitude",
                alias: "latitude",
                type: "double"
            } ,{
                name: "longitude",
                alias: "longitude",
                type: "double"
            }],
            labelingInfo:[{
                symbol: {
                    type: "text", // autocasts as new TextSymbol()
                    color: "white",
                    font: {
                        size:10
                    }
                },
                labelPlacement: "above-center",
                labelExpressionInfo: {
                    expression: "$feature.name"
                }
            } ],
            outFields: ["*"],
            visible: true,
            objectIdField: "id", // inferred from fields array if not specified
            geometryType: "point",
            source: graphics,
            featureReduction: clusterConfig,
            labelsVisible: true,
           renderer: {
            type: "class-breaks",
                field: "cluster_count",
                classBreakInfos: [ {
                minValue:1,
                maxValue: 1,
                symbol: markerSymbol
            },
                {
                    minValue:2,
                    maxValue: 999999999,
                    symbol: markerSymbol1
                }]
        }
        });


        m_map.add(clusterLayer);

    });
}