Skip to main content
1 of 4

esriRequest json response to feature layer

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

However, I have difficulty in showing this data on the map layer.

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

Request Test 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; } 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 Request MAP HERE