Add new fields to the FeatureLayer dynamically - arcgis JS API Version 4.7 The 2019 Stack Overflow Developer Survey Results Are InFeatureLayer creating in javascript ArcGIS APIHow to Zoom to a FeatureLayer Using ArcGIS Javascript APIArcGIS javascript api - layer reordering - how to add new layers?How to upload a csv file into esri map with coordinates and plot in an esri mapCannot read property 'on' of undefinedMapbox Error: Style is not done loadingError loading geoJSON into map using OpenLayers v4.2.0XY Points incorrect on map (ArcGIS Javascript API 4.7)Workaround for no point clustering in ArcGIS Javascript API 4.7How to add labels using featurelayer and sceneview in ArcGIS API for JavaScript 4.3
Is this food a bread or a loaf?
Why could you hear an Amstrad CPC working?
Where does the "burst of radiance" from Holy Weapon originate?
Are USB sockets on wall outlets live all the time, even when the switch is off?
Why is it "Tumoren" and not "Tumore"?
Carnot-Caratheodory metric
Why is Grand Jury testimony secret?
What does "sndry explns" mean in one of the Hitchhiker's guide books?
How to manage monthly salary
What do hard-Brexiteers want with respect to the Irish border?
aging parents with no investments
Can't find the latex code for the ⍎ (down tack jot) symbol
Landlord wants to switch my lease to a "Land contract" to "get back at the city"
How come people say “Would of”?
How are circuits which use complex ICs normally simulated?
Is three citations per paragraph excessive for undergraduate research paper?
Manuscript was "unsubmitted" because the manuscript was deposited in Arxiv Preprints
What is the steepest angle that a canal can be traversable without locks?
Why do UK politicians seemingly ignore opinion polls on Brexit?
How to deal with fear of taking dependencies
Access elements in std::string where positon of string is greater than its size
"Riffle" two strings
Why isn't airport relocation done gradually?
Does light intensity oscillate really fast since it is a wave?
Add new fields to the FeatureLayer dynamically - arcgis JS API Version 4.7
The 2019 Stack Overflow Developer Survey Results Are InFeatureLayer creating in javascript ArcGIS APIHow to Zoom to a FeatureLayer Using ArcGIS Javascript APIArcGIS javascript api - layer reordering - how to add new layers?How to upload a csv file into esri map with coordinates and plot in an esri mapCannot read property 'on' of undefinedMapbox Error: Style is not done loadingError loading geoJSON into map using OpenLayers v4.2.0XY Points incorrect on map (ArcGIS Javascript API 4.7)Workaround for no point clustering in ArcGIS Javascript API 4.7How to add labels using featurelayer and sceneview in ArcGIS API for JavaScript 4.3
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I've uploaded GeoJSON to Esri cloud and created a feature layer. Now I'm able to plot the featurelayer into my map. I'm trying to color each feature based on measures which comes from my DB. Here is link to jsfiddle
Let's say we are going to add a measure, i.e., Profit of the state Texas is 100. So I'd like to add 'Profit':100 as a field to the Feature.
Here is the code,
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<title>Data-driven continuous color - 4.7</title>
<link rel="stylesheet" href="https://js.arcgis.com/4.7/esri/css/main.css">
<script>
var dojoConfig =
has:
"esri-featurelayer-webgl": 1
</script>
<script src="https://js.arcgis.com/4.7/"></script>
<style>
html,
body,
#viewDiv
padding: 0;
margin: 0;
height: 100%;
width: 100%;
</style>
<script>
require([
"esri/Map",
"esri/views/MapView",
"esri/layers/FeatureLayer",
"esri/widgets/Legend",
"esri/Graphic",
"esri/tasks/support/Query",
"esri/tasks/QueryTask",
"dojo/domReady!"
], function(
Map, MapView, FeatureLayer, Legend, Graphic, Query, QueryTask,
)
var defaultSym =
type: "simple-fill", // autocasts as new SimpleFillSymbol()
outline: // autocasts as new SimpleLineSymbol()
color: "lightgray",
width: 0.5
;
var map = new Map(
basemap: "streets"
);
var view = new MapView(
container: "viewDiv",
map: map,
center: [-85.050200, 33.125524],
zoom: 6
);
var openSpacesRenderer =
"type": "class-breaks",
"field": "CENSUSAREA",
"classBreakInfos": [
"symbol":
"color": [
45,128,120,255
],
"outline":
"width": 0
,
"type": "simple-fill",
"style": "solid"
,
"label": "0 to 1,629",
"minValue": 0,
"maxValue": 100000
,
"symbol":
"color": [
173,212,106,255
],
"outline":
"width": 0
,
"type": "simple-fill",
"style": "solid"
,
"label": "> 1,629 to 3,754",
"minValue": 100001,
"maxValue": 200000
,
"symbol":
"color": [
226,235,211,255
],
"outline":
"width": 0
,
"type": "simple-fill",
"style": "solid"
,
"label": "> 3,754 to 11,438",
"minValue": 200001,
"maxValue": 1000000
]
var featureLayer = new FeatureLayer(
url: "https://services9.arcgis.com/JPp8avz1ETW9XJJr/arcgis/rest/services/USA_Outline/FeatureServer/0",
outFields: ["*"],
renderer: openSpacesRenderer
);
map.add(featureLayer);
let graphics;
view.when(featureLayer).then(function(layerView)
//debugger;
layerView.watch("updating", function(value)
if (!value) // wait for the layer view to finish updating
// query all the features available for drawing.
layerView.queryFeatures(
geometry: view.extent,
outFields: ["*"],
returnGeometry: true
).then(function(results)
for(var r in results)
results[r].attributes['profit']= Math.random()*100
console.log(results[r].attributes);
).catch(function(e)
console.error("query failed: ", e);
);
);
);
);
</script>
</head>
<body>
<div id="viewDiv"></div>
</body>
</html>
Now in the for loop I'm trying to add a attribute profit with what we have. Then if I change field variable of openSpacesRenderer as profit, it is not working. How can I add a new field to the existing feature layer?
javascript arcgis-javascript-api arcgis-javascript-api-4
add a comment |
I've uploaded GeoJSON to Esri cloud and created a feature layer. Now I'm able to plot the featurelayer into my map. I'm trying to color each feature based on measures which comes from my DB. Here is link to jsfiddle
Let's say we are going to add a measure, i.e., Profit of the state Texas is 100. So I'd like to add 'Profit':100 as a field to the Feature.
Here is the code,
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<title>Data-driven continuous color - 4.7</title>
<link rel="stylesheet" href="https://js.arcgis.com/4.7/esri/css/main.css">
<script>
var dojoConfig =
has:
"esri-featurelayer-webgl": 1
</script>
<script src="https://js.arcgis.com/4.7/"></script>
<style>
html,
body,
#viewDiv
padding: 0;
margin: 0;
height: 100%;
width: 100%;
</style>
<script>
require([
"esri/Map",
"esri/views/MapView",
"esri/layers/FeatureLayer",
"esri/widgets/Legend",
"esri/Graphic",
"esri/tasks/support/Query",
"esri/tasks/QueryTask",
"dojo/domReady!"
], function(
Map, MapView, FeatureLayer, Legend, Graphic, Query, QueryTask,
)
var defaultSym =
type: "simple-fill", // autocasts as new SimpleFillSymbol()
outline: // autocasts as new SimpleLineSymbol()
color: "lightgray",
width: 0.5
;
var map = new Map(
basemap: "streets"
);
var view = new MapView(
container: "viewDiv",
map: map,
center: [-85.050200, 33.125524],
zoom: 6
);
var openSpacesRenderer =
"type": "class-breaks",
"field": "CENSUSAREA",
"classBreakInfos": [
"symbol":
"color": [
45,128,120,255
],
"outline":
"width": 0
,
"type": "simple-fill",
"style": "solid"
,
"label": "0 to 1,629",
"minValue": 0,
"maxValue": 100000
,
"symbol":
"color": [
173,212,106,255
],
"outline":
"width": 0
,
"type": "simple-fill",
"style": "solid"
,
"label": "> 1,629 to 3,754",
"minValue": 100001,
"maxValue": 200000
,
"symbol":
"color": [
226,235,211,255
],
"outline":
"width": 0
,
"type": "simple-fill",
"style": "solid"
,
"label": "> 3,754 to 11,438",
"minValue": 200001,
"maxValue": 1000000
]
var featureLayer = new FeatureLayer(
url: "https://services9.arcgis.com/JPp8avz1ETW9XJJr/arcgis/rest/services/USA_Outline/FeatureServer/0",
outFields: ["*"],
renderer: openSpacesRenderer
);
map.add(featureLayer);
let graphics;
view.when(featureLayer).then(function(layerView)
//debugger;
layerView.watch("updating", function(value)
if (!value) // wait for the layer view to finish updating
// query all the features available for drawing.
layerView.queryFeatures(
geometry: view.extent,
outFields: ["*"],
returnGeometry: true
).then(function(results)
for(var r in results)
results[r].attributes['profit']= Math.random()*100
console.log(results[r].attributes);
).catch(function(e)
console.error("query failed: ", e);
);
);
);
);
</script>
</head>
<body>
<div id="viewDiv"></div>
</body>
</html>
Now in the for loop I'm trying to add a attribute profit with what we have. Then if I change field variable of openSpacesRenderer as profit, it is not working. How can I add a new field to the existing feature layer?
javascript arcgis-javascript-api arcgis-javascript-api-4
add a comment |
I've uploaded GeoJSON to Esri cloud and created a feature layer. Now I'm able to plot the featurelayer into my map. I'm trying to color each feature based on measures which comes from my DB. Here is link to jsfiddle
Let's say we are going to add a measure, i.e., Profit of the state Texas is 100. So I'd like to add 'Profit':100 as a field to the Feature.
Here is the code,
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<title>Data-driven continuous color - 4.7</title>
<link rel="stylesheet" href="https://js.arcgis.com/4.7/esri/css/main.css">
<script>
var dojoConfig =
has:
"esri-featurelayer-webgl": 1
</script>
<script src="https://js.arcgis.com/4.7/"></script>
<style>
html,
body,
#viewDiv
padding: 0;
margin: 0;
height: 100%;
width: 100%;
</style>
<script>
require([
"esri/Map",
"esri/views/MapView",
"esri/layers/FeatureLayer",
"esri/widgets/Legend",
"esri/Graphic",
"esri/tasks/support/Query",
"esri/tasks/QueryTask",
"dojo/domReady!"
], function(
Map, MapView, FeatureLayer, Legend, Graphic, Query, QueryTask,
)
var defaultSym =
type: "simple-fill", // autocasts as new SimpleFillSymbol()
outline: // autocasts as new SimpleLineSymbol()
color: "lightgray",
width: 0.5
;
var map = new Map(
basemap: "streets"
);
var view = new MapView(
container: "viewDiv",
map: map,
center: [-85.050200, 33.125524],
zoom: 6
);
var openSpacesRenderer =
"type": "class-breaks",
"field": "CENSUSAREA",
"classBreakInfos": [
"symbol":
"color": [
45,128,120,255
],
"outline":
"width": 0
,
"type": "simple-fill",
"style": "solid"
,
"label": "0 to 1,629",
"minValue": 0,
"maxValue": 100000
,
"symbol":
"color": [
173,212,106,255
],
"outline":
"width": 0
,
"type": "simple-fill",
"style": "solid"
,
"label": "> 1,629 to 3,754",
"minValue": 100001,
"maxValue": 200000
,
"symbol":
"color": [
226,235,211,255
],
"outline":
"width": 0
,
"type": "simple-fill",
"style": "solid"
,
"label": "> 3,754 to 11,438",
"minValue": 200001,
"maxValue": 1000000
]
var featureLayer = new FeatureLayer(
url: "https://services9.arcgis.com/JPp8avz1ETW9XJJr/arcgis/rest/services/USA_Outline/FeatureServer/0",
outFields: ["*"],
renderer: openSpacesRenderer
);
map.add(featureLayer);
let graphics;
view.when(featureLayer).then(function(layerView)
//debugger;
layerView.watch("updating", function(value)
if (!value) // wait for the layer view to finish updating
// query all the features available for drawing.
layerView.queryFeatures(
geometry: view.extent,
outFields: ["*"],
returnGeometry: true
).then(function(results)
for(var r in results)
results[r].attributes['profit']= Math.random()*100
console.log(results[r].attributes);
).catch(function(e)
console.error("query failed: ", e);
);
);
);
);
</script>
</head>
<body>
<div id="viewDiv"></div>
</body>
</html>
Now in the for loop I'm trying to add a attribute profit with what we have. Then if I change field variable of openSpacesRenderer as profit, it is not working. How can I add a new field to the existing feature layer?
javascript arcgis-javascript-api arcgis-javascript-api-4
I've uploaded GeoJSON to Esri cloud and created a feature layer. Now I'm able to plot the featurelayer into my map. I'm trying to color each feature based on measures which comes from my DB. Here is link to jsfiddle
Let's say we are going to add a measure, i.e., Profit of the state Texas is 100. So I'd like to add 'Profit':100 as a field to the Feature.
Here is the code,
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<title>Data-driven continuous color - 4.7</title>
<link rel="stylesheet" href="https://js.arcgis.com/4.7/esri/css/main.css">
<script>
var dojoConfig =
has:
"esri-featurelayer-webgl": 1
</script>
<script src="https://js.arcgis.com/4.7/"></script>
<style>
html,
body,
#viewDiv
padding: 0;
margin: 0;
height: 100%;
width: 100%;
</style>
<script>
require([
"esri/Map",
"esri/views/MapView",
"esri/layers/FeatureLayer",
"esri/widgets/Legend",
"esri/Graphic",
"esri/tasks/support/Query",
"esri/tasks/QueryTask",
"dojo/domReady!"
], function(
Map, MapView, FeatureLayer, Legend, Graphic, Query, QueryTask,
)
var defaultSym =
type: "simple-fill", // autocasts as new SimpleFillSymbol()
outline: // autocasts as new SimpleLineSymbol()
color: "lightgray",
width: 0.5
;
var map = new Map(
basemap: "streets"
);
var view = new MapView(
container: "viewDiv",
map: map,
center: [-85.050200, 33.125524],
zoom: 6
);
var openSpacesRenderer =
"type": "class-breaks",
"field": "CENSUSAREA",
"classBreakInfos": [
"symbol":
"color": [
45,128,120,255
],
"outline":
"width": 0
,
"type": "simple-fill",
"style": "solid"
,
"label": "0 to 1,629",
"minValue": 0,
"maxValue": 100000
,
"symbol":
"color": [
173,212,106,255
],
"outline":
"width": 0
,
"type": "simple-fill",
"style": "solid"
,
"label": "> 1,629 to 3,754",
"minValue": 100001,
"maxValue": 200000
,
"symbol":
"color": [
226,235,211,255
],
"outline":
"width": 0
,
"type": "simple-fill",
"style": "solid"
,
"label": "> 3,754 to 11,438",
"minValue": 200001,
"maxValue": 1000000
]
var featureLayer = new FeatureLayer(
url: "https://services9.arcgis.com/JPp8avz1ETW9XJJr/arcgis/rest/services/USA_Outline/FeatureServer/0",
outFields: ["*"],
renderer: openSpacesRenderer
);
map.add(featureLayer);
let graphics;
view.when(featureLayer).then(function(layerView)
//debugger;
layerView.watch("updating", function(value)
if (!value) // wait for the layer view to finish updating
// query all the features available for drawing.
layerView.queryFeatures(
geometry: view.extent,
outFields: ["*"],
returnGeometry: true
).then(function(results)
for(var r in results)
results[r].attributes['profit']= Math.random()*100
console.log(results[r].attributes);
).catch(function(e)
console.error("query failed: ", e);
);
);
);
);
</script>
</head>
<body>
<div id="viewDiv"></div>
</body>
</html>
Now in the for loop I'm trying to add a attribute profit with what we have. Then if I change field variable of openSpacesRenderer as profit, it is not working. How can I add a new field to the existing feature layer?
javascript arcgis-javascript-api arcgis-javascript-api-4
javascript arcgis-javascript-api arcgis-javascript-api-4
edited Jul 10 '18 at 12:32
Vignesh Gopalakrishnan
asked Jul 10 '18 at 11:28
Vignesh GopalakrishnanVignesh Gopalakrishnan
14816
14816
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can use Arcade expressions to calculatenew (temporary) fields, and then use them for popups and/or labeling.
https://developers.arcgis.com/javascript/latest/guide/arcade/index.html
https://developers.arcgis.com/javascript/latest/sample-code/index.html?search=arcade
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "79"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f288974%2fadd-new-fields-to-the-featurelayer-dynamically-arcgis-js-api-version-4-7%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use Arcade expressions to calculatenew (temporary) fields, and then use them for popups and/or labeling.
https://developers.arcgis.com/javascript/latest/guide/arcade/index.html
https://developers.arcgis.com/javascript/latest/sample-code/index.html?search=arcade
add a comment |
You can use Arcade expressions to calculatenew (temporary) fields, and then use them for popups and/or labeling.
https://developers.arcgis.com/javascript/latest/guide/arcade/index.html
https://developers.arcgis.com/javascript/latest/sample-code/index.html?search=arcade
add a comment |
You can use Arcade expressions to calculatenew (temporary) fields, and then use them for popups and/or labeling.
https://developers.arcgis.com/javascript/latest/guide/arcade/index.html
https://developers.arcgis.com/javascript/latest/sample-code/index.html?search=arcade
You can use Arcade expressions to calculatenew (temporary) fields, and then use them for popups and/or labeling.
https://developers.arcgis.com/javascript/latest/guide/arcade/index.html
https://developers.arcgis.com/javascript/latest/sample-code/index.html?search=arcade
answered Jul 19 '18 at 23:38
Bjorn SvenssonBjorn Svensson
2,2141429
2,2141429
add a comment |
add a comment |
Thanks for contributing an answer to Geographic Information Systems Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f288974%2fadd-new-fields-to-the-featurelayer-dynamically-arcgis-js-api-version-4-7%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown