0

我已经按照此链接https://developers.arcgis.com/javascript/3/jsapi/findexistinglocations-amd.html#event-job-submit创建了一个用于查找现有位置分析的自定义 HTML 页面 我能够执行属性和已发布要素图层的空间查询。当我使用令牌在地图上加载安全要素图层(与组织共享)时。因此图层正在地图上加载,并且“添加表达式”也正在添加到 findexistinglocations 小部件中的图层。但是每当加载图层时,就会出现这个错误。[无法读取未定义的属性“人口统计”] [1]

https://i.stack.imgur.com/CGlZD.jpg

<script>
var _token;     
require([
    "dojo/ready","dojo/on",
    "dojo/_base/array",
    "dojo/dom",
    "dijit/registry",
    "dojo/dom-style",
    "dojo/parser","dojo/dom",
    "dijit/layout/BorderContainer",
    "dijit/layout/ContentPane",
    "esri/map",
    "esri/IdentityManager",
    "esri/arcgis/Portal",
    "esri/arcgis/utils",
    "esri/toolbars/draw",
    "esri/graphic",
    "esri/layers/GraphicsLayer",
     "esri/symbols/SimpleFillSymbol",
    "esri/urlUtils",
    "esri/config",
    "esri/dijit/HomeButton", 
    "esri/domUtils",
    "esri/request",
    "dojo/query",
    "esri/layers/FeatureLayer",
    "esri/InfoTemplate",
    "esri/arcgis/Portal",
    "dojo/_base/array",
    "esri/dijit/editing/Editor",
    "esri/dijit/analysis/FindExistingLocations",
    "esri/dijit/Legend",
    "dojo/domReady!"    
], function(
    ready,
    on,
    array,
    dom,
    registry,
    domStyle,
    parser,
    dom,
    BorderContainer,
    ContentPane,
    Map,
    esriId,
    arcgisPortal,
    arcgisUtils,
    Draw,
    Graphic,
    GraphicsLayer,
    SimpleFillSymbol,
    urlUtils,
    esriConfig,
    HomeButton, 
    domUtils,
    esriRequest,
    query,
    FeatureLayer,
    InfoTemplate,
    arcgisPortal,
    arrayUtils,
    Editor,
    FindExistingLocations,
    Legend

    )
    {           
        ready(function(){
            parser.parse();
             esri.config.defaults.io.proxyUrl = "proxy.ashx";  
            //when close button is clicked for details panel show tool
            on(dom.byId("closeBtn"), "click", function(){
                domUtils.hide(dom.byId("infoPanel"));
                domUtils.show(dom.byId("toolPanel"));
            });

        var map = new Map("mapDiv",{
            basemap: "streets",
            center: [],
            zoom: 12
        });

            var home = new HomeButton({
             map:map
             }, "HomeButton");
            home.startup();

            _token = localStorage.getItem("Tokenfile");         
            var token =
                {userId: "username",
                server: "https://test.arcgis.com/sharing/rest/",
                token: _token,
                expires:60,
                ssl: false
                }   
            //console.log(token);
            esriId.registerToken(token);    

        var content = "<b>FID</b>: ${FID}" ;  
        var infoTemplate = new InfoTemplate("Information", content);    
        var source = new FeatureLayer("https://test.arcgis.com/e2CkmW5zjy3NzZyL7/ArcGIS/rest/services/test1/FeatureServer/0",{
            id: "analysisLayer",
            name: "CR",
            outFields: ["*"],
            infoTemplate: infoTemplate
        });
        var content = "<b>FID</b>: ${FID}" ;  
        var infoTemplate = new InfoTemplate("Information", content);
        var target = new FeatureLayer("https://test.arcgis.com/e2CkmW5ncfgzf3NzZyL7/ArcGIS/rest/services/test2/FeatureServer/0",{
            name: "village",
            infoTemplate: infoTemplate

        });

        map.addLayers([source,target]);


       map.on("layers-add-result", initializeTool);

        function initializeTool()
        {   debugger;   
            showToolPanel();
            //Define the default inputs for the Find Location widget
            var findLocationParams = {
                id: "analysisTool",
                analysisLayer: source,
                portalUrl: "https://www.arcgis.com",
                inputLayers: [source, target],
                showHelp: false,
                showSelectAnalysisLayer: false,
                outputLayerName : "test",
                showCredits: false,
                map: map,
                returnFeatureCollection: true
            };

            var findLocation = new FindExistingLocations(findLocationParams, "findLocationDiv");
            findLocation.startup();

            //If any errors occur reset the widget (Not Working...troubleshoot)
            on(findLocation, "job-fail", function(params){
                resetTool("error");
            });
            on(findLocation, "job-status", function(status){
              if(status.jobStatus === 'esriJobFailed'){
              alert("Job Failed: " + status.messages[0].description);
                resetTool("error");
              }

            });
            on(findLocation, "job-cancel", function(){
                resetTool("error");

            });
            on(findLocation, "job-submit", function(result){
                //display the loading icon
                domUtils.show(dom.byId("loader"));
                resetTool("submit");


            });
            //The findLocation analysis has finished successfully - display the results
            on(findLocation, "job-result", function(result){

                //hide the loading icon
                domUtils.hide(dom.byId("loader"));

                //add the results to the map and display the legend.
                if(result.value){
                    var template = new InfoTemplate("Results", "${*}");
                    var resultLayer = new FeatureLayer(result.value.url || result.value, {
                        infoTemplate: template,
                        outFields: ["*"],
                        opacity: 0.7, //default too transparent
                        id: "resultLayer"
                    });
                    map.addLayer(resultLayer);                  
                    alert("Done");                 
                }                
                if(result.analysisReport){
                    //hide the find existing location panel and show the analysis info.
                    domUtils.hide(dom.byId("toolPanel"));
                    domUtils.show(dom.byId("infoPanel"));
                    dom.byId("analysisInfo").innerHTML = result.analysisReport;
                }

                //re-enable the find existing location tool
                findLocation.set("disableRunAnalysis", false);

            });
        }        
        map.on("load", createToolbar);

        // loop through all dijits, connect onClick event
        // listeners for buttons to activate drawing tools
        registry.forEach(function(d) {

          if ( d.declaredClass === "dijit.form.Button" ) {
            d.on("click", activateTool);
          }
        });

        function activateTool() {
          var tool = this.label.toUpperCase().replace(/ /g, "_");
          toolbar.activate(Draw[tool]);
          map.hideZoomSlider();
        }

        function createToolbar(themap) {
          toolbar = new Draw(map);
          toolbar.on("draw-end", addToMap);
        }

        function addToMap(evt) {
          //console.log(evt);
          var symbol;
          toolbar.deactivate();
          map.showZoomSlider();
          symbol = new SimpleFillSymbol();
          var graphic = new Graphic(evt.geometry, symbol);
          //emptyLayer.add(graphic);
          //console.log(emptyLayer);
        }

        function resetTool(status){
            if(status === "error"){
                var tool = registry.byId("analysisTool");
                tool.set("disableRunAnalysis", false);
            }
            //Analysis started lets clean up any old results
            //Hide the legend, remove the results layer
            var layer = map.getLayer("resultLayer");
            if(layer){
                map.removeLayer(layer);
            }
          //  domUtils.hide(dom.byId("legendContainer"));
        }
        function showToolPanel(){
          //expand the right panel to display the content
            var cp = registry.byId("rightPanel");
            domStyle.set(cp.domNode, {width: "20%"});
            registry.byId("mainWin").resize();

            map.reposition();
            map.resize();
        }
    });
});
</script>````



  [1]: https://i.stack.imgur.com/1TY4Y.jpg
4

0 回答 0