Hi,
Using ESRI JS API Core 4.24
I have created a project on Next JS and trying to load the data(polygon) from a JSON source, which I have kept in a local folder. I am getting the json from getStaticProps and passing it to EsriMap component using bellow code..
import dynamic from "next/dynamic";
import React, { useState } from "react";
import fs from "fs/promises";
import path from "path";
const EsriMap = dynamic(() => import("../../components/esri_map"), {
ssr: false,
});
export default function index({district}) {
return (
<>
<EsriMap districts={district}/>
</>
);
}
export async function getStaticProps() {
const filePath = path.join(process.cwd(), "data", "district.json");
const jsonData = await fs.readFile(filePath);
const data = JSON.parse(jsonData);
return {
props: {
district: data,
},
};
}
First Try
import React from "react";
import { useRef, useEffect } from "react";
import ArcGISMap from "@arcgis/core/Map";
import MapView from "@arcgis/core/views/MapView";
import LayerView from "@arcgis/core/views/layers/LayerView";
import SpatialReference from "@arcgis/core/geometry/SpatialReference";
import FeatureLayer from "@arcgis/core/layers/FeatureLayer";
import Polygon from "@arcgis/core/geometry/Polygon";
import Graphic from "@arcgis/core/Graphic";
import SimpleFillSymbol from "@arcgis/core/symbols/SimpleFillSymbol";
import SimpleLineSymbol from "@arcgis/core/symbols/SimpleLineSymbol";
import Color from "@arcgis/core/Color";
import SimpleRenderer from "@arcgis/core/renderers/SimpleRenderer";
import Sidebar from "./sidebar";
export default function EsriMap({ districts }) {
var map, view;
const mapRef = useRef(null);
const {
displayFieldName,
features,
fieldAliases,
fields,
geometryType,
spatialReference,
} = districts;
// I am getting features properly
console.log(features);
useEffect(() => {
const map = new ArcGISMap({
basemap: "topo-vector",
});
const view = new MapView({
map,
container: mapRef.current,
extent: {
spatialReference: {
wkid: 102100,
},
xmax: 9318041.682582326,
xmin: 7685897.199114412,
ymax: 2134999.5715922136,
ymin: 1257953.6118566156,
},
zoom: 7,
});
// like this i can add the map service also, so scope is fine
// const districtLayer = new FeatureLayer({
// url: "http://XXXXXXXXXXXXXX/MapServer/1"
// });
// map.add(districtLayer);
const districtFeatureLayer = new FeatureLayer({
objectIdField:"OBJECTID",
geometryType:geometryType,
fields:fields,
spatialReference:spatialReference,
source:features,
});
map.add(districtFeatureLayer);
});
return (
<>
<div className="flex flex-row h-full">
{/* <aside className="w-1/5">Table of content</aside> */}
<Sidebar/>
<div className="w-4/5" ref={mapRef}></div>
</div>
</>
);
};
It is giving the error like this (firsttry.png enclosed)
Second Try
var graphicsD =[
{geometry:
{features:features,
geometryType: geometryType,
spatialReference: new SpatialReference(spatialReference)},
attribute:fields
}
];
let featureD = [
{
id:"districts",
geometryType:geometryType,
spatialReference:new SpatialReference(spatialReference),
fields:fields,
source: graphicsD,
}
];
let layerD = new FeatureLayer({
title:"s",
id:"d",
source:featureD,
objectIdField:"OBJECTID"
})
map.add(layerD);
It is giving error like this(secondtry.png enclosed)
Can anybody guide where I am committing a mistake. in feature layer creation or preparing data for feature layer creation.
Solved! Go to Solution.
In ESRI JS API 4.24, using the json data, feature layer can be created using bellow code. Which renders, with default symbology, the symbology can be changed using renderer or json.
const {features,fields,geometryType,spatialReference} = districts;
var districtsFeatureLayer = new FeatureLayer({
id: "districts",
source: features.map((feature) => {
return {
attributes: feature.attributes,
geometry: {
type: 'polygon',
rings: feature.geometry.rings,
spatialReference: new SpatialReference({ wkid: spatialReference.wkid })
}
};
}),
outFields: ["*"],
objectIdField: "OBJECTID",
geometryType: "polygon",
spatialReference: new SpatialReference({ wkid: spatialReference.wkid })
});
map.add(districtsFeatureLayer);
Hi this is the json file with one ring, after reading the file, if I console log the features, I am getting the bellow results, screen shot provided.
{
"displayFieldName": "OBJECTID",
"fieldAliases": {
"FID": "FID",
"OBJECTID": "OBJECTID",
"KGISDistrictCode": "KGISDistrictCode",
"KGISDistrictName": "KGISDistrictName",
"BhuCodeDis": "BhuCodeDis",
"SHAPE_Leng": "SHAPE_Leng",
"SHAPE_Area": "SHAPE_Area"
},
"geometryType": "esriGeometryPolygon",
"spatialReference": { "wkid": 102100, "latestWkid": 3857 },
"fields": [
{ "name": "FID", "type": "esriFieldTypeOID", "alias": "FID" },
{ "name": "OBJECTID", "type": "esriFieldTypeInteger", "alias": "OBJECTID" },
{
"name": "KGISDistrictCode",
"type": "esriFieldTypeString",
"alias": "KGISDistrictCode",
"length": 2
},
{
"name": "KGISDistrictName",
"type": "esriFieldTypeString",
"alias": "KGISDistrictName",
"length": 30
},
{
"name": "BhuCodeDis",
"type": "esriFieldTypeString",
"alias": "BhuCodeDis",
"length": 2
},
{
"name": "SHAPE_Leng",
"type": "esriFieldTypeDouble",
"alias": "SHAPE_Leng"
},
{
"name": "SHAPE_Area",
"type": "esriFieldTypeDouble",
"alias": "SHAPE_Area"
}
],
"features": [
{
"attributes": {
"FID": 0,
"OBJECTID": 1,
"KGISDistrictCode": "01",
"KGISDistrictName": "Belagavi",
"BhuCodeDis": "01",
"SHAPE_Leng": 1008729.89777,
"SHAPE_Area": 13393941679.9
},
"geometry": {
"rings": [
[
[8272602.8877369082, 1781168.6974798122],
[8271469.4757582778, 1780253.2798111972],
[8270580.2308112225, 1780944.2739405686],
[8269718.4766434291, 1780156.0765665986],
[8267308.2561494801, 1781289.4170124291],
[8267541.7231793851, 1783341.4453024301],
[8266906.8653022703, 1784976.7043788226],
[8270213.8552803472, 1785299.7014001305],
[8272040.7979063801, 1781933.3299525555],
[8272602.8877369082, 1781168.6974798122]
],
[
[8353622.22053569, 1857373.9843678209],
[8353549.6284096939, 1855612.880076559],
[8353126.1126473341, 1855648.7738658153],
[8353622.22053569, 1857373.9843678209]
],
[
[8386293.7881848402, 1906019.5947838936],
[8386550.1827982003, 1905677.2375666345],
[8388904.4673479851, 1905831.8356136479],
[8392877.1667051669, 1904651.9076249683],
[8391155.7702609934, 1900359.169648292],
[8391099.089991495, 1897680.1704191524],
[8391863.6651064064, 1893178.7134605984],
[8389923.8108037319, 1892927.6723799561],
[8389242.7971151508, 1887629.1679924545],
[8384396.4850854063, 1888080.61527206],
[8381158.4870982636, 1887670.7634962332],
[8378513.5037490968, 1885133.3278914453],
[8378218.2520170556, 1883650.0002705336],
[8378804.0561771225, 1879032.4739152917],
[8378119.4533742433, 1876793.1910269139],
[8377395.1903978232, 1876362.2611853536],
[8377603.0505169211, 1875136.5911601887],
[8376839.6625328436, 1874902.5029742045],
[8374889.1659543682, 1875933.1707916982],
[8373138.6076304596, 1876042.6343794444],
[8368544.7447276767, 1874579.3442661844],
[8366640.4789980426, 1872708.1000699773],
[8366649.8632083358, 1870500.4811883054],
[8367486.142839537, 1868888.9085742568],
[8367121.5867228284, 1866657.6199670509],
[8366259.2288290234, 1865860.5857114836],
[8363656.4193517203, 1865186.5271695261],
[8362169.0248884615, 1863415.6034352882],
[8360580.3934960216, 1863962.8007285998],
[8360022.2125425451, 1865847.4157801187],
[8358913.9057112262, 1867174.9378652482],
[8358506.6635034578, 1869071.6464210702],
[8357197.0996044502, 1870289.4883449806],
[8356846.2058340823, 1870307.1919624726],
[8356121.8302684864, 1867303.1159761033],
[8349775.5362827796, 1867134.0033447875],
[8347647.2728283638, 1862599.4585533165],
[8347403.7682493683, 1858742.4260026976],
[8348110.6873558806, 1857336.9731950711],
[8350388.0357843759, 1857862.0858826991],
[8350891.3969007712, 1855799.7838201199],
[8352214.9171146154, 1854928.1656598989],
[8357534.8155315639, 1855252.4260752592],
[8356977.3083775751, 1851709.5775170021],
[8353193.7164362157, 1850388.2228654576],
[8352692.4254798926, 1847305.2209906138],
[8352772.7939832052, 1843939.4227745044],
[8353687.1563432962, 1842067.0440357365],
[8355277.8230452323, 1843099.8247419267],
[8356271.1311455267, 1842515.5123817781],
[8357523.9539731275, 1843198.9432300299],
[8359605.5122776171, 1842377.961776614],
[8363516.8887414308, 1843086.8369165075],
[8364277.2906441512, 1842238.68265811],
[8363334.0670273034, 1839050.0473262633],
[8363475.8412601193, 1837956.2491287724],
[8371855.7676992649, 1836272.1444266855],
[8375006.822747251, 1834696.9860198612],
[8375388.0848793518, 1833550.9803902295],
[8374539.6707010763, 1831545.4825372933],
[8374830.4308871906, 1829012.9048220334],
[8376711.1731165191, 1828397.7549056148],
[8379098.0980127063, 1828741.2685245813],
[8380894.9534691609, 1827817.2237500504],
[8380722.3038031766, 1825305.3449123022],
[8381453.4781243997, 1824432.4245240653],
[8379747.2697022641, 1818655.4805192777],
[8385395.7122262185, 1818126.8883753009],
[8388077.6742700785, 1819404.5480906523],
[8388808.1657901928, 1818014.0963751394],
[8393606.7163973562, 1817865.6479810155],
[8394840.1987443715, 1819814.2136331035],
[8395528.4884636309, 1816657.4866866642],
[8396470.9501935132, 1816051.261638646],
[8396853.6653246749, 1814188.6298099705],
[8396543.9262496624, 1811661.8289408551],
[8395296.1187427584, 1810764.0861299597],
[8395313.5523013882, 1808810.3769972357],
[8396104.3257780299, 1808175.8677632085],
[8396563.472292969, 1805605.7795920055],
[8397713.9856765773, 1805267.6614203763],
[8396971.9186600074, 1801613.1152235474],
[8397858.6522823628, 1800604.2268129189],
[8396348.2063281741, 1795933.3871394899],
[8397954.1148338448, 1795038.8396700539],
[8397641.1329530571, 1792563.1077690122],
[8399018.0986190643, 1791662.5413769481],
[8399197.8497667089, 1789109.8391584232],
[8399910.1358206049, 1788333.1916714669],
[8399924.2329645585, 1783790.5739243519],
[8398826.7175524663, 1781037.5725429768],
[8397812.6041097902, 1780672.3728382769],
[8397400.9760561436, 1779091.0319765029],
[8395116.9193341881, 1779960.6547151504],
[8396176.0446468387, 1784636.148360878],
[8396096.0649320949, 1786472.9668754176],
[8391849.2603907492, 1786033.5565077602],
[8390730.7657889128, 1786740.2324729387],
[8389585.414699953, 1782205.9305760455],
[8389200.876170747, 1782074.6116688119],
[8387151.2193799624, 1782113.7623732821],
[8386447.0688729715, 1784680.7044425288],
[8385909.3559082188, 1784473.7184684393],
[8385977.4304108899, 1783600.13705316],
[8385339.6845808662, 1783072.8281382248],
[8382691.8039409108, 1783010.0813522963],
[8382952.600730367, 1777766.7531037934],
[8384317.8191332174, 1777100.1641625543],
[8384305.1071421113, 1775123.9520722157],
[8383933.0884869648, 1773727.1378196196],
[8382335.459472863, 1773222.1652196599],
[8381557.8201281438, 1773525.0463535918],
[8381395.330195507, 1774781.3723131479],
[8379600.7969054226, 1774710.7907239588],
[8379967.7232655631, 1768850.793304973],
[8379105.2776410421, 1764016.3719821146],
[8376626.9625618439, 1763986.4439141725],
[8374947.9856715696, 1767549.568850752],
[8373327.3669156618, 1767394.8583507002],
[8373096.7355191242, 1767815.7192177954],
[8371831.9223620119, 1767864.3739734187],
[8371237.9801729489, 1764140.3255568163],
[8369920.0795269618, 1764141.8257073157],
[8369516.9160979372, 1764895.8792731743],
[8367982.8179639103, 1765402.6315711299],
[8363654.0983568905, 1765459.7467955926],
[8362576.5785381086, 1766385.5999550861],
[8361197.561997571, 1766711.3411413573],
[8360110.8401890108, 1765243.1305554318],
[8359060.7653124267, 1759535.8745707194],
[8357775.6530478448, 1761076.1703704356],
[8356348.5412360076, 1761389.4453423512],
[8355204.7302303286, 1762412.0661891513],
[8355973.236881366, 1766378.0402795104],
[8355292.872523318, 1768052.330022719],
[8354446.4870927846, 1767763.8079987972],
[8354051.1791431839, 1766581.6442493373],
[8352281.2446367163, 1766535.9529282381],
[8352019.7764505334, 1764549.3448586038],
[8351156.0380506553, 1763721.2149302191],
[8348029.3130882932, 1764337.1668898943],
[8345269.2134009507, 1764411.0987058105],
[8344730.6522206981, 1761477.4528629202],
[8341468.7699479563, 1761064.2958944351],
[8339226.38356297, 1761969.5913106229],
[8336810.5971290944, 1761968.7269433376],
[8335186.3064985638, 1760382.8086433597],
[8332899.2361939419, 1759860.194887314],
[8331659.6661816044, 1759363.5211781303],
[8330828.9723986071, 1759806.898487736],
[8329946.0524942074, 1759472.9472017318],
[8329992.1255572448, 1757712.930867828],
[8330917.6761340071, 1755370.6593701541],
[8329651.2244217284, 1754917.1235961795],
[8327347.276384661, 1752663.1045595403],
[8326599.3273126632, 1752488.0989050565],
[8327882.6051613186, 1749428.4411673504],
[8328094.7327776318, 1747585.8446463486],
[8327104.7865399541, 1746488.8630648274],
[8325280.3647458991, 1745274.7945371305],
[8324389.4174294127, 1742399.6406089237],
[8322947.8972502667, 1743674.172951709],
[8322292.8813560111, 1743629.5991127952],
[8320851.6741043413, 1746344.3337945088],
[8320298.9885024764, 1746213.7023340999],
[8318560.6837212481, 1745279.1670250339],
[8319141.72442172, 1743348.7342836182],
[8320348.4855056759, 1742691.7893949],
[8320287.9323398927, 1741476.8495190276],
[8318941.2907969169, 1738936.9504269951],
[8320098.3171305982, 1737461.0807725396],
[8320121.7057329342, 1736675.3783124487],
[8319414.5829216074, 1736318.1223587268],
[8315322.3628417207, 1736387.7434587756],
[8314333.0821601078, 1735188.7514768944],
[8309892.7909112098, 1734247.7985366322],
[8308436.3535122545, 1731798.3618290753],
[8305969.821345143, 1730642.1605144092],
[8301653.4150204221, 1734348.7515994266],
[8300673.2456976669, 1735802.1845283243],
[8298323.3157337299, 1737114.3664532613],
[8297189.1245222054, 1737438.5024611952],
[8295136.8941772114, 1735574.7777720736],
[8294387.1246318026, 1735718.9416235159],
[8293984.2381084124, 1736783.9055559954],
[8294373.5461353697, 1738525.8301065501],
[8293005.5246985415, 1739640.4200555023],
[8291869.9691530634, 1739815.6995021387],
[8291264.0347377881, 1738846.6721759178],
[8290663.6586516388, 1738730.6349420126],
[8289148.9435277442, 1738986.5149867758],
[8287460.2117463183, 1737761.235042426],
[8287702.1475555459, 1736173.1847179013],
[8286429.6375576658, 1735806.2747040556],
[8285762.1881574299, 1734937.2783601566],
[8284750.2603164231, 1737808.8398822818],
[8284633.2378056804, 1742619.7983739099],
[8283520.3279576022, 1743909.4707119775],
[8280709.002708164, 1744828.7422985074],
[8279232.2047484284, 1744530.6748860592],
[8275853.0656073922, 1748903.0905281859],
[8273926.0132203372, 1748786.4776017291],
[8270007.9355223067, 1749607.7552968787],
[8268641.6477225805, 1749371.2492685632],
[8269029.9403053056, 1750420.9503426517],
[8268550.668932884, 1752209.1682728061],
[8266994.8319142405, 1754059.6056780182],
[8266424.6845651511, 1753911.2716491933],
[8265395.0349895125, 1754581.5620669147],
[8265326.8356034178, 1755997.2876278758],
[8266417.5770280445, 1757568.1326632993],
[8267033.5069846045, 1760299.8359730719],
[8266124.4070571652, 1761266.0645902699],
[8265018.3490040842, 1761107.285063528],
[8265695.3186661107, 1764627.0335320304],
[8264053.0855190838, 1766059.9285848844],
[8262415.7999424981, 1766289.8948252019],
[8261897.7678927742, 1765747.1275025224],
[8262441.3931233259, 1764903.1214445441],
[8260520.803160564, 1764270.5518608906],
[8260421.9046867136, 1765743.5857274118],
[8258669.2114909431, 1766056.8166870798],
[8258386.125132909, 1767005.3350841985],
[8258796.3587666722, 1767381.0770249411],
[8257818.9185108393, 1767877.3290621622],
[8256186.3182028383, 1766755.0906314193],
[8255867.8631618563, 1764723.8112573966],
[8252788.7015547026, 1764099.1941958384],
[8248863.9767134385, 1765074.7610880178],
[8247265.8087878814, 1766548.5504449036],
[8247679.8850756781, 1766979.7673689513],
[8249709.8599253315, 1766788.5565647357],
[8251405.560314361, 1767679.1056282984],
[8252495.2626145715, 1770373.6821846485],
[8251780.8674428668, 1772195.4899485477],
[8251247.54974123, 1772419.5202919187],
[8254289.8879743209, 1774125.9601954685],
[8255382.6482447861, 1775725.339587962],
[8257996.8049892318, 1775959.1949251301],
[8260199.87345374, 1776748.1085970313],
[8260853.3084045993, 1779137.889510619],
[8261925.2760801744, 1779884.3459352562],
[8263122.2074525803, 1780318.0950187217],
[8263512.7675362257, 1780033.958746894],
[8263774.3621714357, 1779156.0353401515],
[8263033.2756234827, 1777800.5159198914],
[8263041.3825992495, 1776550.6661632112],
[8264492.5018129926, 1774994.3757871022],
[8267436.2909981636, 1776163.9703333387],
[8269664.0696260976, 1774779.1139573469],
[8271849.0837326655, 1775727.4124552803],
[8273048.9536910476, 1776934.8553332216],
[8273497.7223059991, 1778237.9548527023],
[8275541.4999025017, 1777485.477127742],
[8277030.8111431468, 1778233.2032877365],
[8278571.0988826891, 1779902.0497313875],
[8278972.0489982506, 1781896.1969192023],
[8278130.6105877059, 1783729.4528421541],
[8280327.5284198625, 1786382.4636540436],
[8280284.6095384508, 1787219.508113943],
[8275874.3945187917, 1787469.3885428323],
[8275767.1467437558, 1788186.8221597939],
[8278029.5667909654, 1790400.2294467366],
[8278221.655798356, 1792402.6223435206],
[8279671.7237094762, 1790982.1812098701],
[8280745.6080507692, 1788148.7994449157],
[8281785.4862711122, 1787500.4832041305],
[8282843.300067923, 1788094.393794196],
[8282910.9628141494, 1788817.958108268],
[8281575.1974325152, 1790327.6984211036],
[8281550.0279678237, 1792963.4974163226],
[8280740.5424581785, 1793772.2864615708],
[8285602.2685546661, 1799712.8486658954],
[8286992.2271011556, 1803069.7925856845],
[8287183.2818869306, 1804919.4639021319],
[8289214.4181471746, 1809417.2935003415],
[8289176.3797111847, 1810438.1552801048],
[8288515.802006986, 1810233.3300076833],
[8285741.8566295728, 1811508.0784731412],
[8283812.9416263336, 1811112.3939811368],
[8280093.7235241234, 1808854.4138522574],
[8278903.0429893825, 1809190.8117379632],
[8279818.8547682669, 1810952.6513798363],
[8277974.5444261339, 1810765.6218861872],
[8277854.4545466509, 1811149.5073170734],
[8279522.7494788729, 1813821.4447743832],
[8280774.0744360117, 1814170.7471831001],
[8281301.6610702733, 1815193.9806079026],
[8283067.0482124276, 1815693.6956817599],
[8283393.7190224929, 1816618.2744269059],
[8285225.7423127359, 1817758.2958150944],
[8286975.5017811079, 1816960.7306483542],
[8288724.89752784, 1816868.4677844027],
[8288765.780090984, 1816352.050572613],
[8290308.0337153152, 1815239.10081735],
[8291521.3334765127, 1815247.0892866061],
[8292311.3408886325, 1817588.7813135211],
[8291612.4279111745, 1821203.300112746],
[8291045.7402204312, 1821841.1116583124],
[8292051.9530827543, 1823150.3942104513],
[8292304.7501874911, 1825699.2172814996],
[8292720.9777152305, 1826391.1789198385],
[8294052.7505174642, 1826850.6076480958],
[8294063.1739485282, 1828001.1053592344],
[8292833.8577362411, 1829343.9602915642],
[8293468.3564945171, 1830936.7440854444],
[8291082.0797830196, 1833615.2005721894],
[8289521.9432431525, 1832589.6451008068],
[8288407.8277642438, 1833046.2303260528],
[8287952.3476272579, 1834009.8123195365],
[8286381.4207482729, 1833844.0205589843],
[8286247.2701307759, 1834409.1973633501],
[8284074.8068834404, 1834820.5744488793],
[8283881.6302000191, 1837262.5432731262],
[8283416.4035756588, 1837616.1404929103],
[8280812.7243962632, 1836973.1170092898],
[8280205.9839024106, 1838536.5366563608],
[8279390.1511808196, 1839005.963011564],
[8276008.1985948943, 1838615.8923022819],
[8276913.5745989913, 1837371.9511467007],
[8276585.487418713, 1836806.3352830112],
[8274171.7930915197, 1835806.9635795054],
[8273648.7190020764, 1837842.3808942274],
[8274142.9731708597, 1838560.4103772948],
[8274909.1462458801, 1838327.1083334342],
[8275752.3786755484, 1838873.495360092],
[8275501.3222343121, 1839795.5510305671],
[8273804.0080361078, 1841387.3208594315],
[8274761.573619131, 1841824.6600778126],
[8274393.6657400709, 1842507.297196805],
[8273403.1332995798, 1842147.6546382301],
[8272674.1332844635, 1842565.5521362987],
[8273361.1429640269, 1843151.7090017439],
[8272938.6312183226, 1844346.6881036172],
[8274077.3909140984, 1844389.026107712],
[8273004.7418888574, 1845653.6990731577],
[8273786.3325392157, 1846221.5997593647],
[8273271.0334788309, 1848303.8882126682],
[8274145.3171974579, 1849173.4106745177],
[8274076.3369865194, 1849928.2925369802],
[8275122.9031704711, 1850271.9799756082],
[8276354.1040893476, 1847277.4900382215],
[8276770.2267545694, 1847265.9067813372],
[8278074.3560397904, 1851505.8500637349],
[8276783.4984356072, 1851839.0578349729],
[8274926.0255547995, 1851484.8420883545],
[8274250.8926931713, 1853365.6047334902],
[8275069.7439313149, 1854674.9413445315],
[8274399.2943941085, 1857528.2857858005],
[8272476.4993458372, 1857254.3773221173],
[8270692.8391477708, 1858515.312354486],
[8269918.0492207306, 1858408.2538072681],
[8270091.252567512, 1863066.7318994612],
[8268720.9828071864, 1863111.9794916159],
[8268024.3255549381, 1860847.9335341854],
[8266829.7447100114, 1860389.4862458757],
[8265500.6354523748, 1862060.4546618883],
[8265572.9202326862, 1862655.2395765651],
[8268602.5595846316, 1863418.1839613121],
[8268347.3237309698, 1864954.2531440407],
[8267616.6981919166, 1865417.4673414335],
[8267059.6621303717, 1867279.0769012759],
[8267320.4488596134, 1867741.7066068796],
[8267745.6804781491, 1868276.1106331774],
[8268671.2548340484, 1867824.5160535942],
[8269069.6217538938, 1865943.9952603623],
[8269518.7274735225, 1865785.1616491296],
[8270210.0830150871, 1866548.2732627266],
[8271243.5846219379, 1866064.4017569751],
[8271899.6930583054, 1863159.877296115],
[8272765.9987724936, 1863399.8280586628],
[8272847.3842556439, 1868836.1912961081],
[8273705.2162845777, 1869375.1687196533],
[8275278.8746159887, 1868393.0545696614],
[8277399.9045157023, 1869580.7080814857],
[8277576.2759114308, 1867376.579788306],
[8280094.5075164409, 1866115.8030530147],
[8280777.875174012, 1866996.57360854],
[8280869.5719024148, 1869824.1757916696],
[8281973.7229743823, 1872359.5217752978],
[8284635.521916694, 1872535.9991357499],
[8285097.8507976802, 1873842.6752141432],
[8286085.4111971762, 1874418.9486020503],
[8289450.050846858, 1874920.2556572556],
[8289494.709671271, 1877126.9011707702],
[8288429.3262426388, 1879917.1695112209],
[8288506.3352055606, 1880612.6751204205],
[8289973.9359264262, 1881827.2193742418],
[8290540.8522118349, 1879833.1914201481],
[8292191.4946303982, 1877830.8318863262],
[8298269.650666195, 1878240.6065975528],
[8298293.7592787957, 1873779.1286683786],
[8299674.5210827235, 1873802.3374831853],
[8300709.4867111836, 1872719.6800442555],
[8299467.9099991983, 1870428.0667673342],
[8301131.6728403009, 1869196.8680858666],
[8302432.2316438565, 1869577.8636373256],
[8303181.7399947606, 1870422.5960636912],
[8304681.992121771, 1870382.9489274318],
[8306787.1511873035, 1872338.4777169146],
[8307769.7972242339, 1871891.9017612152],
[8308220.3820178024, 1872414.9375920084],
[8308131.7673731307, 1875107.4863029665],
[8308893.52321178, 1875759.4746902967],
[8311133.7806189926, 1874911.1923064562],
[8312469.75603469, 1875535.4229649275],
[8313784.3518536435, 1875309.4763483019],
[8314230.1020290451, 1875701.0052737859],
[8313781.4719323199, 1876542.7790738265],
[8310798.0579029443, 1877986.9584704335],
[8310357.3507903377, 1878868.4967736595],
[8311630.3291043499, 1881700.1632850645],
[8313194.9763355711, 1881997.2332709779],
[8313374.4504528781, 1882862.4891297524],
[8314334.4506246764, 1883477.4439996877],
[8313474.6874182159, 1884120.6014812938],
[8314353.3382901829, 1884765.2955795296],
[8314461.1979840342, 1887911.3586105152],
[8318492.4761980493, 1887899.4032547339],
[8321440.5248726616, 1889659.3265770224],
[8323736.7361747995, 1891863.5245238682],
[8326254.7068079198, 1891524.4192458862],
[8326502.2262850916, 1892179.7429877666],
[8331629.4934569634, 1893141.0200215536],
[8332493.6316393837, 1894209.7186159096],
[8333806.3988327365, 1893480.1869826727],
[8334603.7227872312, 1894525.0599396804],
[8339993.5746261533, 1894387.3707920008],
[8338978.4648386165, 1896372.6402240663],
[8338926.1036870535, 1901860.2064819741],
[8338256.1501962822, 1904867.3438511728],
[8340323.0176096503, 1904958.6378979932],
[8340766.8104772605, 1905956.5893815963],
[8341748.1862405641, 1905809.6593749868],
[8341792.0446754908, 1906736.574364993],
[8342211.6599280061, 1906925.4945382315],
[8344549.0730582643, 1907041.5525357458],
[8344861.1368718734, 1909998.9961012276],
[8344093.7507033302, 1909808.3647184509],
[8343737.3702639788, 1910408.8147334969],
[8342739.1169422092, 1910456.3924242551],
[8341599.5848065251, 1911979.0499890526],
[8340452.7482857015, 1912532.0924787631],
[8340374.6235899068, 1913428.977760704],
[8341418.2015702361, 1914395.9862766797],
[8342913.8195896428, 1913903.3056753671],
[8344429.1154426085, 1912421.2230020401],
[8344477.6020868542, 1913516.6798413927],
[8345275.7852444565, 1914820.4280985582],
[8348238.3589626187, 1915262.4286395996],
[8351964.4166985694, 1914228.1240479539],
[8351830.0028273351, 1912529.2136445746],
[8353839.9173260722, 1914045.1113068666],
[8356029.1905391989, 1914105.3798172681],
[8357255.8092028284, 1915055.4921624942],
[8358664.1291840132, 1915270.3237400092],
[8359614.9155735336, 1910951.6567421372],
[8361963.459511078, 1910756.506580231],
[8362476.422339851, 1909379.8798039879],
[8363609.8720403183, 1908714.1353800381],
[8364129.228451007, 1906211.9535389263],
[8367418.2509267572, 1905358.7531977021],
[8369600.441101281, 1906100.1992601582],
[8369889.192779283, 1905627.3583053688],
[8369219.091524573, 1902792.5711055228],
[8373172.5902966904, 1902429.3887884864],
[8374403.2424823297, 1902797.9539881176],
[8375449.6073249904, 1905424.6086502557],
[8378371.4378355481, 1904894.3152566087],
[8380447.1695515923, 1907060.3140370937],
[8381163.2038478609, 1909833.8667771732],
[8380498.68870096, 1910418.5373492376],
[8380134.1805403046, 1911946.4834283444],
[8380306.5796302147, 1915814.0316560098],
[8386987.3395153405, 1915728.1743072921],
[8386217.2899032794, 1910732.8852629857],
[8386293.7881848402, 1906019.5947838936]
]
]
}
},
when I print the features in console, I will get the info like this
and single polygon ring like this
and single attributes like this
then I changed the code to prepare the polygon first and created the feature layer like this
let districtLayer=[{
geometry:new Polygon({
rings:features[13].geometry.rings,
spatialReference: { wkid: 102100 }
}),
attributes:features[13].attributes
}];
let districtLayerService = new FeatureLayer({
source: districtLayer,
objectIdField: "OBJECTID"
});
map.add(districtLayerService);
so I could able to render one polygon successfully. If I have 10,000 polygon, Is there any short circuit to render the all the polygon with out that much iteration.
Is there any way, where I can pass the feature directly to new FeatureLayer class instead of iterating, to render on map.
In ESRI JS API 4.24, using the json data, feature layer can be created using bellow code. Which renders, with default symbology, the symbology can be changed using renderer or json.
const {features,fields,geometryType,spatialReference} = districts;
var districtsFeatureLayer = new FeatureLayer({
id: "districts",
source: features.map((feature) => {
return {
attributes: feature.attributes,
geometry: {
type: 'polygon',
rings: feature.geometry.rings,
spatialReference: new SpatialReference({ wkid: spatialReference.wkid })
}
};
}),
outFields: ["*"],
objectIdField: "OBJECTID",
geometryType: "polygon",
spatialReference: new SpatialReference({ wkid: spatialReference.wkid })
});
map.add(districtsFeatureLayer);