/**
 * Created by gqs on 2020/8/7.
 */
var loadLayerCount = 0;// 图层加载总数
var currentMapLoadCount = 0;
var groundColor = [0, 0, 0];
var currentMapMode;
var currentExtent;
var ecxtentChanged;
var isSetMapZoom = false;

var GraphicsLayer_labelLayer;
var GraphicsLayer_myLayer;
var GraphicsLayer_identityLayer;
var GraphicsLayer_extendLayer;
var GraphicsLayer_fickerLayer;
var GraphicsLayer_DrawLayer;
var GraphicsLayer_flyTipLayer;
var m_sceneLayerViewArr = [];
function init3DScene(){
    currentMapMode = "3D";
    require(["esri/Map", "esri/Graphic", "esri/geometry/Extent", "esri/geometry/Polygon","esri/geometry/Polyline",
            "esri/geometry/Point", "esri/views/MapView", "esri/views/SceneView", "esri/layers/MapImageLayer",
            "esri/layers/TileLayer", "esri/layers/VectorTileLayer", "esri/layers/GraphicsLayer",
            "esri/tasks/GeometryService", "esri/portal/Portal", "esri/WebScene", "esri/widgets/LayerList","esri/widgets/Legend",
            "esri/widgets/Expand", "esri/config", "esri/widgets/ScaleBar", "esri/layers/FeatureLayer", "esri/layers/SceneLayer",
            "esri/layers/support/LabelClass", "esri/widgets/NavigationToggle", "esri/widgets/Zoom", "esri/widgets/Compass",
            "esri/Color", "esri/core/watchUtils", "esri/symbols/TextSymbol", "esri/Camera", "dojo/domReady!"],
        function(Map, Graphic, Extent, Polygon,Polyline, Point, MapView, SceneView, MapImageLayer, TileLayer, VectorTileLayer, GraphicsLayer, GeometryService, Portal, WebScene, LayerList, Legend, Expand,
                 esriConfig, ScaleBar, FeatureLayer, SceneLayer, LabelClass, NavigationToggle, Zoom, Compass, Color, watchUtils, TextSymbol, Camera) {
            m_map = new Map({
                ground: {
                    surfaceColor: groundColor
                }
            });
            dyAddMapLayerByConfig();
            AddMapGraphicLayers();
            m_view = new SceneView({
                container: "mapDiv",
                constraints: {
                    collision: {
                        enabled: false
                    },
                    tilt: {
                        max:85,
                        min: 0
                    }
                },
                map: m_map,
                viewingMode: "local",
                alphaCompositingEnabled: true,
                environment: {
                    background: {
                        type: "color",
                        color: [255, 255, 255, 1]
                    },
                    starsEnabled: true,
                    atmosphereEnabled: true
                },
                ui: {
                    components: ["attribution"]
                }
            });
            m_view.environment.lighting.date = new Date("August 10, 2020 14:00:00 UTC");
            m_view.environment.lighting.directShadowsEnabled = true; //建筑物阴影
            AddSceneViewWidget();
            m_view.when(function() {
                //初始化sceneLayerView
                m_view.map.layers.forEach(function(layer, index) {
                    m_view.whenLayerView(layer)
                        .then(function(layerView) {
                            if (layer.type === "scene") {
                                m_sceneLayerViewArr.push(layerView);
                            }
                        }).catch(console.error);
                });
                //初始化视点
                var initCameraJSON=global_config_json.map.initCamera;
                if(initCameraJSON){
                    setCamera(0,initCameraJSON.position[0],initCameraJSON.position[1],initCameraJSON.position[2],initCameraJSON.heading,initCameraJSON.tilt);
                }
                else
                {
                    var centerPoint = new Point({
                        x: 2514,
                        y: 2169,
                        z: 662,
                        spatialReference: m_view.spatialReference
                    });
                    setCameraBypoint(0, centerPoint, 337, 70, currentScale);
                }
                //onMapLoaded();
                var displaynoneDiv1 = document.getElementsByClassName("esri-attribution__powered-by");
                for (var i = 0; i < displaynoneDiv1.length; i++) {
                    displaynoneDiv1[i].style.display = "none"
                }
                var displaynoneDiv2 = document.getElementsByClassName("esri-widget-button");
                for (var i = 0; i < displaynoneDiv2.length; i++) {
                    displaynoneDiv2[i].style.display = "none"
                }
                m_view.watch("camera", updateIndicator);
                watchUtils.when(m_view, "animation", watchAnimation);
                m_zoom = new Zoom({
                    view: m_view
                });
                if (currentExtent != null) {
                    m_view.extent = currentExtent;
                    setCameraBypoint(1, currentExtent.center, 0, 45, currentScale)
                }
            });

            function dyAddMapLayerByConfig() {
                var serverUrl = "";
                var serverType = "";
                var serverLabel = "";
                var serverVisible = "";
                //fullextent参数加载
                var extentArray = global_config_json.map.fullextent;
                fullExtent = new Extent(parseFloat(extentArray[0]), parseFloat(extentArray[1]), parseFloat(extentArray[2]), parseFloat(extentArray[3]));
                //geometryservice加载
                serverType = "geometryservice";
                serverUrl = global_config_json.map.geometryservice;
                dyAddMapLayer(serverUrl, serverType, serverLabel, serverVisible)
                //3D,2D地图加载
                var mapJson;
                if(global_config_json.map.maptype == "3D"){
                    mapJson = global_config_json.map.basemaps3D;
                }else{
                    mapJson = global_config_json.map.basemaps;
                }
                for(var i=0;i<mapJson.length;i++) {
                    loadLayerCount++;
                    serverUrl = mapJson[i].Layer.url;
                    serverType = mapJson[i].Layer.type;
                    serverLabel = mapJson[i].Layer.label;
                    serverVisible = mapJson[i].Layer.visible;
                    dyAddMapLayer(serverUrl, serverType, serverLabel, serverVisible)
                }
            }


            function AddMapGraphicLayers() {
                GraphicsLayer_labelLayer = new GraphicsLayer;
                GraphicsLayer_myLayer = new GraphicsLayer;
                GraphicsLayer_identityLayer = new GraphicsLayer;
                GraphicsLayer_identityLayer.elevationInfo = {
                    mode: "relative-to-scene"
                };
                GraphicsLayer_extendLayer = new GraphicsLayer;
                GraphicsLayer_extendLayer.listMode = "hide";
                GraphicsLayer_fickerLayer = new GraphicsLayer;
                GraphicsLayer_DrawLayer = new GraphicsLayer;
                GraphicsLayer_flyTipLayer = new GraphicsLayer;
                m_map.add(GraphicsLayer_labelLayer);
                m_map.add(GraphicsLayer_identityLayer);
                m_map.add(GraphicsLayer_extendLayer);
                m_map.add(GraphicsLayer_DrawLayer);
                m_map.add(GraphicsLayer_myLayer);
                m_map.add(GraphicsLayer_flyTipLayer);
                m_map.add(GraphicsLayer_fickerLayer);
            }

            function dyAddMapLayer(serverUrl, serverType, serverLabel, serverVisible) {
                var layer;
                switch (serverType) {
                    case "geometryservice":{
                        geometryService = new GeometryService(serverUrl);
                        break;
                    }
                    case "tiled":{
                        layer = new TileLayer({
                            url: serverUrl,
                            id: serverLabel
                        });
                        layer.visible = serverVisible;
                        layer.when(function () {
                            isCompleteLoadMap();
                        });
                        m_map.add(layer);
                        break;
                    }
                    case "dynamic":{
                        dyLayer = new MapImageLayer({
                            url: serverUrl,
                            id: serverLabel
                        });
                        dyLayer.visible = serverVisible;
                        var currentElevationInfo = {
                            mode: "relative-to-ground",
                            offset: -1,
                            unit: "meters"
                        };
                        dyLayer.elevationInfo = currentElevationInfo;
                        dyLayer.when(function () {
                            isCompleteLoadMap();
                        });
                        m_map.add(dyLayer);
                        break;
                    }
                    case "featurelayer":{
                        if(serverLabel.indexOf("水系")>-1){
                            layer = new FeatureLayer({
                                url:serverUrl,
                                id:serverLabel,
                                renderer: {
                                    type: "simple",
                                    symbol: {
                                        type: "polygon-3d",
                                        symbolLayers: [{
                                            type: "water",
                                            waveDirection: 180,
                                            color: "#b3ccfe",
                                            waveStrength: "moderate",
                                            waterbodySize: "large"
                                        }]
                                    }
                                }
                            });
                        }
                        else{
                            layer = new FeatureLayer({
                                url:serverUrl,
                                id:serverLabel
                            });
                        }
                        layer.when(function () {
                            isCompleteLoadMap();
                        });
                        m_map.add(layer);
                        break;
                    }
                    case "scene":{
                        m_sceneLayer = new SceneLayer({
                            url: serverUrl,
                            id: serverLabel,
                            popupEnabled: true
                        });
                        if(serverLabel.indexOf("建筑物")>0){
                            var locationRenderer = {
                                type: "simple",
                                symbol: {
                                    type: "mesh-3d",
                                    symbolLayers: [{
                                        type: "fill",
                                        material: {
                                            color: [255,255,255,0.9],
                                            colorMixMode: "replace"
                                        },
                                        edges: {
                                            type: "solid",
                                            color: [200, 200, 200, 1],
                                            size: 1
                                        }
                                    }]
                                }
                            };
                            if(serverLabel=="高层建筑物"){
                                var locationRenderer1 = {
                                    type: "unique-value",
                                    // attribute of interest - Earthquake magnitude
                                    //field: "备注",
                                    valueExpression:"When($feature.OBJECTID==8406 || $feature.OBJECTID==120||$feature.OBJECTID==1593,'HIDDEN','SHOW')",
                                    defaultSymbol:{
                                        type: "mesh-3d",
                                        symbolLayers: [{
                                            type: "fill",
                                            material: {
                                                color: [255,255,255,0.9],
                                                colorMixMode: "replace"
                                            },
                                            edges: {
                                                type: "solid",
                                                color: [200, 200, 200, 1],
                                                size: 1
                                            }
                                        }]
                                    },
                                    uniqueValueInfos: [
                                        {
                                            value: "HIDDEN",  // 0 acres
                                            symbol: {
                                                type: "mesh-3d", // autocasts as new MeshSymbol3D()
                                                symbolLayers: [{
                                                    type: "fill", // autocasts as new FillSymbol3DLayer()
                                                    material: {
                                                        color: [0,0,0,0],
                                                        colorMixMode: "replace"
                                                    }
                                                }]
                                            },
                                            label: "fewer than 200,00 acres"
                                        }
                                    ]
                                };
                                m_sceneLayer.renderer = locationRenderer1;
                            }
                            else {
                                m_sceneLayer.renderer = locationRenderer;
                            }

                        }
                        m_sceneLayer.when(function () {
                            isCompleteLoadMap();
                        });
                        m_map.add(m_sceneLayer);
                        break;
                    }
                    case "vector":
                    {
                        var vlayer = new VectorTileLayer({
                            url: serverUrl,
                            id: serverLabel
                        });
                        vlayer.when(function () {
                            isCompleteLoadMap();
                        });
                        m_map.add(vlayer);
                        break;
                    }
                }
            }
            function isCompleteLoadMap() {
                currentMapLoadCount++;
                if(currentMapLoadCount==loadLayerCount){
                    onMapLoaded();
                }
            }
            function onMapLoaded()
            {

            }

            function AddSceneViewWidget() {
                var viewTest = document.getElementById("viewTest");
                m_view.ui.add(viewTest, "bottom-right")
            }
        });
    function setCamera(isAnimation, pointX, pointY, pointZ, headingValue, tiltValue, scaleValue) {
        require(["esri/Camera", "esri/geometry/Point"],
            function(Camera, Point) {
                var pt = new Point({
                    x: pointX,
                    y: pointY,
                    z: pointZ,
                    spatialReference: m_view.spatialReference
                });
                if (isAnimation) {
                    m_view.goTo({
                        target: pt,
                        heading: headingValue,
                        tilt: tiltValue,
                        scale: scaleValue
                    })
                } else {
                    var cam = new Camera({
                        heading: headingValue,
                        tilt: tiltValue,
                        position: pt
                    });
                    m_view.camera = cam
                }
            })
    }
}

function initMap() {
    currentMapMode = "2D";
    require(["esri/Map", "esri/views/MapView", "esri/layers/MapImageLayer", "esri/layers/TileLayer", "esri/layers/VectorTileLayer","esri/geometry/Geometry", "esri/geometry/Extent",
            "esri/tasks/GeometryService", "esri/layers/GraphicsLayer", "esri/layers/FeatureLayer", "esri/widgets/ScaleBar",
            "esri/WebMap", "esri/geometry/SpatialReference", "esri/Graphic", "esri/views/2d/draw/Draw",
            "esri/geometry/Polygon", "esri/widgets/Zoom", "esri/widgets/Compass", "esri/widgets/LayerList","esri/widgets/Legend",
            "esri/widgets/Expand",
            "esri/geometry/geometryEngine","esri/tasks/QueryTask", "esri/tasks/support/Query",
            "esri/geometry/Point","esri/core/watchUtils","dojo/on"],
        function(Map, MapView, MapImageLayer, TileLayer,VectorTileLayer, Geometry, Extent, GeometryService,
                 GraphicsLayer, FeatureLayer, ScaleBar, WebMap, SpatialReference, Graphic, Draw, Polygon,
                 Zoom, Compass, LayerList, Legend, Expand, geometryEngine,QueryTask,Query,Point,watchUtils,on) {
            m_map = new Map({
                logo:false,
                slider:false
            });
            dyAddMapLayerByConfig();
            AddMapGraphicLayers();
            var viewxmax = global_config_json.map.viewxmax;
            var viewxmin = global_config_json.map.viewxmin;
            var viewymax = global_config_json.map.viewymax;
            var viewymin = global_config_json.map.viewymin;
            m_view = new MapView({
                container: "mapDiv",
                map: m_map,
                popup: {
                    dockEnabled: false,
                    dockOptions: {
                        position: "top-right",
                        breakpoint: false
                    }
                }
            });
            m_view.constraints = {
                rotationEnabled: false  // Disables map rotation
            };
            layerList = new LayerList({
                view: m_view
            });
            AddSceneViewWidget();
            m_view.when(function(evt) {
                doCustomPopUp();
                var displaynoneDiv1 = document.getElementsByClassName("esri-attribution__powered-by");
                for (var i = 0; i < displaynoneDiv1.length; i++) {
                    displaynoneDiv1[i].style.display = "none"
                }
                var displaynoneDiv2 = document.getElementsByClassName("esri-widget-button");
                for (var i = 0; i < displaynoneDiv2.length; i++) {
                    displaynoneDiv2[i].style.display = "none"
                }
                m_zoom = new Zoom({
                    view: m_view
                });
                m_view.ui.move([ "zoom", m_zoom ], "top-right");
                var m_compass = new Compass({
                    view: m_view
                });
                m_view.ui.add(m_compass, {
                    position: "top-right"
                });
                m_view.ui.remove('attribution');
                m_drawtool = new Draw({
                    view: m_view
                })
                var centerx = m_view.center.x;
                var centery = m_view.center.y;
                var infoDiv = document.getElementById("infoDiv");
                m_view.ui.add(
                    new Expand({
                        view: m_view,
                        content: infoDiv,
                        expandIconClass: "esri-icon-layer-list",
                        expanded: true
                    }),
                    "top-right"
                );
                var legend = new Legend({
                    view: m_view,
                    container: "legendDiv",

                });
                m_view.watch("animation", function(response){
                    if(response && response.state === "running"){
                        window.parent.postMessage(
                            {
                                method: "mapAnimationInProgressCallback"
                            },
                            '*'
                        );
                    }
                });
                m_view.on("drag",function (event) {
                    if(event.action == 'end'){
                    }
                    else{
                        window.parent.postMessage(
                            {
                                method: "mapDragingCallback"
                            },
                            '*'
                        );
                    }
                });
            });
            var scaleBar = new ScaleBar({
                view: m_view
            });
            if (currentExtent != null) {
                currentExtent.spatialReference = m_view.spatialReference;
                m_view.extent = currentExtent
            }
            function dyAddMapLayerByConfig() {
                var serverUrl = "";
                var serverType = "";
                var serverLabel = "";
                var serverVisible = "";
                //fullextent参数加载
                var extentArray = global_config_json.map.fullextent;
                fullExtent = new Extent(parseFloat(extentArray[0]), parseFloat(extentArray[1]), parseFloat(extentArray[2]), parseFloat(extentArray[3]));
                if (currentExtent == null) currentExtent = fullExtent;
                //geometryservice加载
                serverType = "geometryservice";
                serverUrl = global_config_json.map.geometryservice;
                dyAddMapLayer(serverUrl, serverType, serverLabel, serverVisible)
                //3D,2D地图加载
                var mapJson;
                if(currentMapMode == "3D"){
                    mapJson = global_config_json.map.basemaps3D;
                }else{
                    mapJson = global_config_json.map.basemaps;
                }
                for(var i=0;i<mapJson.length;i++) {
                    loadLayerCount++;
                    serverUrl = mapJson[i].Layer.url;
                    serverType = mapJson[i].Layer.type;
                    serverLabel = mapJson[i].Layer.label;
                    serverVisible = mapJson[i].Layer.visible;
                    dyAddMapLayer(serverUrl, serverType, serverLabel, serverVisible)
                }
            }
             function dyAddMapLayer(serverUrl, serverType, serverLabel, serverVisible) {
                var layer;
                switch (serverType) {
                    case "geometryservice":
                    {
                        geometryService = new GeometryService(serverUrl);
                        break
                    }
                    case "tiled":
                    {
                        layer = new TileLayer({
                            url: serverUrl,
                            id: serverLabel
                        });
                        layer.visible = serverVisible;
                        m_map.add(layer);
                        break;
                    }
                    case "dynamic":
                    {
                        if (serverLabel == "卫监所动态数据") {

                        } else {
                            dyLayer = new MapImageLayer({
                                url: serverUrl,
                                id: serverLabel
                            });
                            dyLayer.visible = serverVisible;
                        }
                        m_map.add(dyLayer);
                        on(dyLayer, "load",
                            function(evt) {
                                dynamicLayerLoaded(evt)
                            });
                        dyLayer.when(function() {
                            var layerInfo = GetDynamicServiceLayer();
                            for (var i = 0; i < layerInfo.length; i++) {
                                GetLayerRestData(i)
                            }
                        });
                        break;
                    }
                    case "featurelayer":
                    {
                        var restUrl = serverUrl + "?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);
                                if (LayerJsonData != "") {
                                    var layers = LayerJsonData.layers;
                                    if (layers.length > 0) {
                                        for (var i = 0; i < layers.length; i++) {
                                            if (layers[i].subLayerIds == null) {
                                                var layerId = layers[i].id;
                                                var layername = layers[i].name;
                                                if(layername)
                                                    var dyLayer = new FeatureLayer({
                                                        url: serverUrl+"/"+layerId,
                                                        id: layerId
                                                    });
                                                dyLayer.visible = serverVisible;
                                                // if(layername == "上水井盖")
                                                //     dyLayer.visible = true;
                                                m_map.add(dyLayer);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    }
                    case "vector":
                    {
                        var vlayer = new VectorTileLayer({
                            url: serverUrl,
                            id: serverLabel
                        });
                        m_map.add(vlayer);
                        break;
                    }
                }
            }
            function dynamicLayerLoaded(event) {
                m_view.zoom = 3
            }
            function AddMapGraphicLayers() {
                GraphicsLayer_labelLayer = new GraphicsLayer;
                GraphicsLayer_myLayer = new GraphicsLayer({id:"myGLayer"});
                GraphicsLayer_identityLayer = new GraphicsLayer;
                GraphicsLayer_extendLayer = new GraphicsLayer;
                GraphicsLayer_extendLayer.listMode = "hide";
                GraphicsLayer_fickerLayer = new GraphicsLayer;
                GraphicsLayer_DrawLayer = new GraphicsLayer({id:"myDrawGLayer"});
                GraphicsLayer_flyTipLayer = new GraphicsLayer;
                m_map.add(GraphicsLayer_labelLayer);
                m_map.add(GraphicsLayer_identityLayer);
                m_map.add(GraphicsLayer_DrawLayer);
                m_map.add(GraphicsLayer_flyTipLayer);
                m_map.add(GraphicsLayer_myLayer);
                m_map.add(GraphicsLayer_extendLayer);
                m_map.add(GraphicsLayer_fickerLayer);
            }
            function AddSceneViewWidget() {
                var viewTest = document.getElementById("viewTest");
                m_view.ui.add(viewTest, "top-left");
            }
            watchUtils.whenTrue(m_view,"stationary",function(){
                if (m_view.center) {
                    var xmax = m_view.extent.xmax;
                    var xmin = m_view.extent.xmin;
                    var ymax = m_view.extent.ymax;
                    var ymin = m_view.extent.ymin;
                    var extent = m_view.extent;
                    if (ecxtentChanged !== undefined && ecxtentChanged.xmin === extent.xmin && ecxtentChanged.ymin === extent.ymin
                        && ecxtentChanged.xmax === extent.xmax && ecxtentChanged.ymax === extent.ymax)
                        return;
                    var precision = 5000;//可以忽略超出的精度
                    var diff = 0;
                    var hasChanged = false;
                    if(isSetMapZoom){
                        m_maxZoom = m_view.zoom;
                        isSetMapZoom = false;
                    }
                    if (viewxmin - xmin > precision) {
                        hasChanged = true;
                        diff = viewxmin - xmin;
                        xmin += diff;
                        xmax += diff;
                        //如果调整过后最大值超出，则调整回来，并把对应的y值也调整，否则会死循环
                        if (xmax > viewxmax) {
                            diff = xmax - viewxmax;
                            diff = (ymax - ymin) * diff / (xmax - xmin);
                            xmax = viewxmax;
                            ymin += diff / 2;
                            ymax -= diff / 2;
                        }
                    }
                    if (viewymin - ymin > precision) {
                        hasChanged = true;
                        diff = viewymin - ymin;
                        ymin += diff;
                        ymax += diff;
                        //如果调整过后最大值超出，则调整回来，并把对应的x值也调整，否则会死循环
                        if (ymax > viewymax) {
                            diff = ymax - viewymax;
                            diff = (xmax - xmin) * diff / (ymax - ymin);
                            ymax = viewymax;
                            xmin += diff / 2;
                            xmax -= diff / 2;
                        }
                    }
                    if (xmax - viewymax > precision) {
                        hasChanged = true;
                        diff = xmax - viewymax;
                        xmin -= diff;
                        xmax -= diff;
                        //如果调整过后最小值超出，则调整回来，并把对应的y值也调整，否则会死循环
                        if (xmin < viewxmin) {
                            diff = viewxmin - xmin;
                            diff = (ymax - ymin) * diff / (xmax - xmin);
                            xmin = viewxmin;
                            ymin += diff / 2;
                            ymax -= diff / 2;
                        }
                    }
                    if (ymax - viewymax > precision) {
                        hasChanged = true;
                        diff = ymax - viewymax;
                        ymin -= diff;
                        ymax -= diff;
                        //如果调整过后最小值超出，则调整回来，并把对应的x值也调整，否则会死循环
                        if (ymin < viewymin) {
                            diff = viewymin - ymin;
                            diff = (xmax - xmin) * diff / (ymax - ymin);
                            ymin = viewymin;
                            xmin += diff / 2;
                            xmax -= diff / 2;
                        }
                    }
                    if (hasChanged) {
                        ecxtentChanged = extent;
                        m_view.extent = new Extent({
                            xmin: xmin ,
                            ymin: ymin,
                            xmax: xmax,
                            ymax: ymax,
                            spatialReference: m_view.spatialReference
                        });
                        return;
                    }
                    window.parent.postMessage(
                        {
                            method: "resizeCallback"
                        },
                        '*'
                    );
                    x=m_view.center.x;
                    y=m_view.center.y;
                    document.addEventListener("touchstart", function (e) {
                        x=m_view.center.x;
                        y=m_view.center.y;
                        x=x-0;
                        y=y-0;
                    });
                    //监听 touchmove 事件 手指 移动时 做的事情
                    document.addEventListener("touchmove", function (e) {
                        e.preventDefault();
                        // 2 根 手指执行 目标元素放大操作
                        if (e.touches.length >= 2) {
                            x=x-0;
                            y=y-0;
                            m_view.center=new Point({
                                x: x-0,
                                y: y-0,
                                spatialReference: m_view.spatialReference
                            });
                        };
                    });
                    //监听 手指离开屏幕时
                    document.addEventListener("touchend", function (e) {
                    });
                }
            });
        });

}

function setExtent(xmin, ymin, xmax, ymax) {
    require(["esri/geometry/Extent"],
        function(Extent) {
            var ext = new Extent({
                xmin: xmin,
                ymin: ymin,
                xmax: xmax,
                ymax: ymax,
                spatialReference: m_view.spatialReference
            });
            m_view.extent = ext
        })
}

function GetXmlHttpObject() {
    var xmlHttpRest = null;
    try {
        xmlHttpRest = new XMLHttpRequest
    } catch(e) {
        try {
            xmlHttpRest = new ActiveXObject("Msxml2.XMLHTTP")
        } catch(e) {
            xmlHttpRest = new ActiveXObject("Microsoft.XMLHTTP")
        }
    }
    if (xmlHttpRest == null) {
        return
    }
    return xmlHttpRest
}