Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Tweeted twitter.com/StackGIS/status/1069154209864523777
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
added tags, and changed java to javascript
Source Link
Ian Turton
  • 83.2k
  • 6
  • 89
  • 189

I am using javaJavaScript 4.7 and I am able to retrieve json using esriRequest from our ArcGIS server.

the call map.addLayer(featureLayer);map.addLayer(featureLayer); is not working. Here is the code I am using

I am using java 4.7 and I am able to retrieve json using esriRequest from our ArcGIS server.

the call map.addLayer(featureLayer); is not working. Here is the code I am using

I am using JavaScript 4.7 and I am able to retrieve json using esriRequest from our ArcGIS server.

the call map.addLayer(featureLayer); is not working. Here is the code I am using

Request Testhtml, body,#viewDiv{height: 100%;width: 100%;margin: 0;padding: 0;}body{background-color: #FFF;overflow: hidden;font-family: "Trebuchet MS";}#header{height: 3%;overflow: auto;}require(["esri/request","dojo/on","esri/Map","esri/layers/FeatureLayer","esri/renderers/support/jsonUtils","esri/views/MapView","esri/symbols/SimpleMarkerSymbol","esri/Color", "esri/renderers/SimpleRenderer","esri/tasks/support/FeatureSet","dojo/domReady!"
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no" />
    <title>Request Test</title>
    <link rel="stylesheet" href="http://js.arcgis.com/4.2/esri/css/main.css">
    <link rel="stylesheet" type="text/css" href="http://js.arcgis.com/4.2/dijit/themes/claro/claro.css">
    <style>
        html,        body,
        #viewDiv {
            height: 100%;
            width: 100%;
            margin: 0;
            padding: 0;
        }
        body {
            background-color: #FFF;
            overflow: hidden;
            font-family: "Trebuchet MS";
        }
        #header {
            height: 3%;
            overflow: auto;
        }
    </style>
    
    <script src="http://js.arcgis.com/4.7/"></script>
    <script>
       
        require([
        "esri/request",
        "dojo/on",
        "esri/Map",
        "esri/layers/FeatureLayer",
        "esri/renderers/support/jsonUtils",
      "esri/views/MapView",
      "esri/symbols/SimpleMarkerSymbol",
      "esri/Color", "esri/renderers/SimpleRenderer",
            "esri/tasks/support/FeatureSet",
      "dojo/domReady!"

        ], function (
        esriRequest,
        on,
        Map,
        FeatureLayer,
        rendererJsonUtils, MapView, SimpleMarkerSymbol, Color, SimpleRenderer,  
            FeatureSet
      ) {

            var map = new Map({
                basemap: "streets"
            });

            var view = new MapView({
                container: "viewDiv",
                map: map,
                zoom: 4,
                center: [15, 65] // longitude, latitude
            });
            var input = document.getElementById("inputUrl");

            /************************************************
             *
             * Define the 'options' for our request.
             *
             *************************************************/
            var options = {
                query: {
                    f: 'json'
                } 
                responseType: 'json'
            };

            // Make the request on a button click using the
            // value of the 'input' text.
            on(btnQuery, "click", function () {
                var url = input.value;
                esriRequest(url, options).then(function (response) {
                    var responseJSON = JSON.stringify(response, null, 2);
                 
                    var search_layer_result = JSON.parse(responseJSON);
                    var fs = new FeatureSet(search_layer_result);
                    var layerDefinition = {
                        "displayFieldName": "NAME",
                        "geometryType": "esriGeometryPoint",
                        "spatialReference": {
                            "wkid": 32633
                        },
                        "fields": [
                          {
                              "name": "OBJECTID",
                              "type": "esriFieldTypeOID",
                              "alias": "OBJECTID"
                          },
                          {
                              "name": "NAME",
                              "type": "esriFieldTypeString",
                              "alias": "NAME",
                              "length": 50
                          }
                        ]
                    };
                    var featureCollection = {
                        layerDefinition: layerDefinition,
                        featureSet: fs
                    };
                    var featureLayer = new FeatureLayer(featureCollection);
                   map.addLayer(featureLayer);
                  
                });
            });
        });
    </script>
</head>

<body>
    <div class="container">
        <div>
            <h2>Using esri/request</h2>
            <button id="btnQuery">Make Request</button>
            <input id="inputUrl" type="text" value="https://arcgisserver/map">
        </div>        
    </div>
    <div id="viewDiv">MAP HERE</div>
</body>

</html>

Using esri/request

Make RequestMAP HERE
Request Testhtml, body,#viewDiv{height: 100%;width: 100%;margin: 0;padding: 0;}body{background-color: #FFF;overflow: hidden;font-family: "Trebuchet MS";}#header{height: 3%;overflow: auto;}require(["esri/request","dojo/on","esri/Map","esri/layers/FeatureLayer","esri/renderers/support/jsonUtils","esri/views/MapView","esri/symbols/SimpleMarkerSymbol","esri/Color", "esri/renderers/SimpleRenderer","esri/tasks/support/FeatureSet","dojo/domReady!"
    ], function (
    esriRequest,
    on,
    Map,
    FeatureLayer,
    rendererJsonUtils, MapView, SimpleMarkerSymbol, Color, SimpleRenderer,  
        FeatureSet
  ) {

        var map = new Map({
            basemap: "streets"
        });

        var view = new MapView({
            container: "viewDiv",
            map: map,
            zoom: 4,
            center: [15, 65] // longitude, latitude
        });
        var input = document.getElementById("inputUrl");

        /************************************************
         *
         * Define the 'options' for our request.
         *
         *************************************************/
        var options = {
            query: {
                f: 'json'
            } 
            responseType: 'json'
        };

        // Make the request on a button click using the
        // value of the 'input' text.
        on(btnQuery, "click", function () {
            var url = input.value;
            esriRequest(url, options).then(function (response) {
                var responseJSON = JSON.stringify(response, null, 2);
             
                var search_layer_result = JSON.parse(responseJSON);
                var fs = new FeatureSet(search_layer_result);
                var layerDefinition = {
                    "displayFieldName": "NAME",
                    "geometryType": "esriGeometryPoint",
                    "spatialReference": {
                        "wkid": 32633
                    },
                    "fields": [
                      {
                          "name": "OBJECTID",
                          "type": "esriFieldTypeOID",
                          "alias": "OBJECTID"
                      },
                      {
                          "name": "NAME",
                          "type": "esriFieldTypeString",
                          "alias": "NAME",
                          "length": 50
                      }
                    ]
                };
                var featureCollection = {
                    layerDefinition: layerDefinition,
                    featureSet: fs
                };
                var featureLayer = new FeatureLayer(featureCollection);
               map.addLayer(featureLayer);
              
            });
        });
    });
</script>

Using esri/request

Make RequestMAP HERE
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no" />
    <title>Request Test</title>
    <link rel="stylesheet" href="http://js.arcgis.com/4.2/esri/css/main.css">
    <link rel="stylesheet" type="text/css" href="http://js.arcgis.com/4.2/dijit/themes/claro/claro.css">
    <style>
        html,        body,
        #viewDiv {
            height: 100%;
            width: 100%;
            margin: 0;
            padding: 0;
        }
        body {
            background-color: #FFF;
            overflow: hidden;
            font-family: "Trebuchet MS";
        }
        #header {
            height: 3%;
            overflow: auto;
        }
    </style>
    
    <script src="http://js.arcgis.com/4.7/"></script>
    <script>
       
        require([
        "esri/request",
        "dojo/on",
        "esri/Map",
        "esri/layers/FeatureLayer",
        "esri/renderers/support/jsonUtils",
      "esri/views/MapView",
      "esri/symbols/SimpleMarkerSymbol",
      "esri/Color", "esri/renderers/SimpleRenderer",
            "esri/tasks/support/FeatureSet",
      "dojo/domReady!"

        ], function (
        esriRequest,
        on,
        Map,
        FeatureLayer,
        rendererJsonUtils, MapView, SimpleMarkerSymbol, Color, SimpleRenderer,  
            FeatureSet
      ) {

            var map = new Map({
                basemap: "streets"
            });

            var view = new MapView({
                container: "viewDiv",
                map: map,
                zoom: 4,
                center: [15, 65] // longitude, latitude
            });
            var input = document.getElementById("inputUrl");

            /************************************************
             *
             * Define the 'options' for our request.
             *
             *************************************************/
            var options = {
                query: {
                    f: 'json'
                } 
                responseType: 'json'
            };

            // Make the request on a button click using the
            // value of the 'input' text.
            on(btnQuery, "click", function () {
                var url = input.value;
                esriRequest(url, options).then(function (response) {
                    var responseJSON = JSON.stringify(response, null, 2);
                 
                    var search_layer_result = JSON.parse(responseJSON);
                    var fs = new FeatureSet(search_layer_result);
                    var layerDefinition = {
                        "displayFieldName": "NAME",
                        "geometryType": "esriGeometryPoint",
                        "spatialReference": {
                            "wkid": 32633
                        },
                        "fields": [
                          {
                              "name": "OBJECTID",
                              "type": "esriFieldTypeOID",
                              "alias": "OBJECTID"
                          },
                          {
                              "name": "NAME",
                              "type": "esriFieldTypeString",
                              "alias": "NAME",
                              "length": 50
                          }
                        ]
                    };
                    var featureCollection = {
                        layerDefinition: layerDefinition,
                        featureSet: fs
                    };
                    var featureLayer = new FeatureLayer(featureCollection);
                   map.addLayer(featureLayer);
                  
                });
            });
        });
    </script>
</head>

<body>
    <div class="container">
        <div>
            <h2>Using esri/request</h2>
            <button id="btnQuery">Make Request</button>
            <input id="inputUrl" type="text" value="https://arcgisserver/map">
        </div>        
    </div>
    <div id="viewDiv">MAP HERE</div>
</body>

</html>
Source Link
Loading