Невозможно прочитать свойство 'demographics' undefined в ArcGIS API - PullRequest
0 голосов
/ 14 апреля 2020

Я создал пользовательскую страницу HTML для анализа поиска существующего местоположения по этой ссылке https://developers.arcgis.com/javascript/3/jsapi/findexistinglocations-amd.html#event -job-submit Я могу выполнить атрибутивный и пространственный запрос в опубликованном слое объектов. Когда Я загружаю безопасный слой объектов (предоставленный организации) на карту с помощью токена. Таким образом, слой загружается на карту, а «Добавить выражение» также добавляется к слою в виджете findexistinglocations. Но всякий раз, когда загружается слой, эта ошибка приходит. [Невозможно прочитать свойство 'demographics' undefined] [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
...