AnsweredAssumed Answered

consuming dotnet core webapi geojson data

Question asked by nasser.owen@gmail.com on May 30, 2020

You help is greatly appreciated.  I am trying to load sample school data as a geojson feature collection from dotnet core 3.1 MVC rest api.  And of course create GeoJSONLayer.   I was able to it on leaflet. But not able to do it in Esri javascript 4.15 api. 

I was able to extract the data from MVC controller  and lint correctly.

client side code :

const url = "https://localhost:44332/Map/schools";

  
const geojsonLayer = new GeoJSONLayer({
        url: url
        popupTemplate: schoolTemplate(),
        renderer: myRenderer() 
      });
       map = new Map({
        basemap: "gray",
        layers: [geojsonLayer]
      });

 

server side code :

 

var result = await _dbContext.Schools.Where(s => s.countyid == 24).ToListAsync();
Feature f = null;

SchoolsDataMV res = new SchoolsDataMV();

var fc = new FeatureCollection();
var geometryFactory = NtsGeometryServices.Instance.CreateGeometryFactory(srid: 4326);

foreach (var item in result)
{
f = new Feature();
f.Attributes = new AttributesTable();
f.Attributes.Add("id", item.id);
f.Attributes.Add("name", item.name);
f.Attributes.Add("address", item.address);
f.Attributes.Add("schoolType", item.schooltype);
f.Attributes.Add("schoolMaster", item.schoolmaster);
f.Attributes.Add("staffCount", item.staffcount);
f.Attributes.Add("studentsCount", item.studentscount);
// f.Geometry = item.geom;
f.Geometry = geometryFactory.CreatePoint(new Coordinate(item.geom.X, item.geom.Y));
fc.Add(f);
}
GeoJsonWriter writer = new GeoJsonWriter();
var geoJson = writer.Write(fc);

return Ok(geoJson);

 

I get the below errors:

 

dojo.js:253 [esri.layers.GeoJSONLayer] #load() Failed to load layer (title: 'GeoJSON', id: '17266b2f6e4-layer-0')

  1. d
    1. details: {data: "{"type":"FeatureCollection","features":[{"type":"F…Thomson","staffCount":24,"studentsCount":1574}}]}"}
    2. message: "missing or not supported GeoJSON object type"
    3. name: "geojson-layer:unsupported-geojson-object"

 

Thank You

Outcomes