1

I'm new to ESRI Map. I'm working on latest version of JavaScript API.

I'm trying to load GeoJSON from https://bit.ly/2IZk4Nj into my Map. I'm able to load GeoJSON from ESRI Feature Service URL.

I wanted to load GeoJSON from an object. My code goes like this.

require([
      "esri/Map",
      "esri/views/MapView",
      "esri/layers/FeatureLayer",
      "esri/widgets/Legend",
      "dojo/domReady!"
    ], function(
      Map, MapView, FeatureLayer, Legend
    ) {

      var defaultSym = {
        type: "simple-fill", // autocasts as new SimpleFillSymbol()
        outline: { // autocasts as new SimpleLineSymbol()
          color: "lightgray",
          width: 0.5
        }
      };

      var renderer = {
        type: "simple", // autocasts as new SimpleRenderer()
        symbol: defaultSym
      };

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

      var view = new MapView({
        container: "viewDiv",
        map: map,
        center: [-85.050200, 33.125524],
        zoom: 4
      });

      var usOutline = ...... A single feature from the feature collection in link.
      var featureLayer = new FeatureLayer({
        source: usOutline.geometry,
        title: 'Hello',
        geometryType: "Polygon",
        renderer: renderer
      });

      map.add(featureLayer);


    });

Hope my question is clear. How can I load the GeoJSON?

3

Check out this code snippet/post:

Importing GeoJSON data in ArcGIS Javascript maps

function requestData() {
  var requestHandle = esriRequest({
    url: "data/sample.json",
    callbackParamName: "jsoncallback"
  });
  requestHandle.then(requestSucceeded, requestFailed);
}

function requestSucceeded(response, io) {
  //loop through the items and add to the feature layer
  var features = [];
  array.forEach(response.features, function(item) {
    var attr = {};
    //pull in any additional attributes if required
    attr["some_other_field"] = item.properties.<some_chosen_field>;

    var geometry = new Point(item.geometry.coordinates[0], item.geometry.coordinates[1]);

    var graphic = new Graphic(geometry);
    graphic.setAttributes(attr);
    features.push(graphic);
  });

  featureLayer.applyEdits(features, null, null);
}

function requestFailed(error) {
  console.log('failed');
}
  • Thank you so much for the effort. Unable to plot geojson with this code. This plot's points from the each co-ordinates in geojson. Moreover this doesn't support version 4.7. – Vignesh Gopalakrishnan Jul 9 '18 at 5:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.