Select to view content in your preferred language

How to Update a feature layer without loading Map

867
3
06-11-2019 11:22 PM
NadirHussain
Frequent Contributor

Dear All.

I want to applyedits on feature layer without showing or loading map window.i want as user perform action no map should open or load window and featurelayer.appyedits should work silently witout loading map and adding feature layer on the map.please help.

Thanks in advance.

0 Kudos
3 Replies
irtizahussain
Regular Contributor

Nadir,

This is  what you want.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="initial-scale=1,maximum-scale=1,user-scalable=no"
/>
<title>Intro to FeatureLayer - 4.11</title>

<link
rel="stylesheet"
href="https://js.arcgis.com/4.11/esri/themes/light/main.css"
/>
<script src="https://js.arcgis.com/4.11/"></script>

<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
</style>

<script>
require([
"esri/Map",
"esri/views/MapView",
"esri/layers/FeatureLayer"
], function(Map, MapView, FeatureLayer) {
var map = new Map({
basemap: ""
});

var view = new MapView({
container: "viewDiv",
map: map,

extent: {
// autocasts as new Extent()
xmin: -9177811,
ymin: 4247000,
xmax: -9176791,
ymax: 4247784,
spatialReference: 102100
}
});

/********************
* Add feature layer
********************/

// Carbon storage of trees in Warren Wilson College.
var featureLayer = new FeatureLayer({
url:
"https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0"
});

map.add(featureLayer);
});
</script>
</head>

<body>
<div id="viewDiv"></div>
</body>
</html>

0 Kudos
NadirHussain
Frequent Contributor

Dear Irtiza Hussain

 Thanks for your reply.But the problem is that you are adding feature layer on map and opening map on html page.I dont want this.I just want to do this in java script file.

 I hope you have understand.I dont want to open map window.My user just want to click the button on one of my page.In response featurelayer shoukd update without adding adding layer on the map and no need of opening map window.Just an alert come data updated.

Thanks

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Nadir,

   Here is a working sample:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="initial-scale=1,maximum-scale=1,user-scalable=no"
    />
    <title>Intro to FeatureLayer - 4.11</title>

    <link
      rel="stylesheet"
      href="https://js.arcgis.com/4.11/esri/themes/light/main.css"
    />
    <script src="https://js.arcgis.com/4.11/"></script>

    <style>
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }
    </style>

    <script>
      require([
        "esri/layers/FeatureLayer",
        "esri/Graphic"
      ], function(FeatureLayer, Graphic) {
        var featureLayer = new FeatureLayer({
          url:
            "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/ArcGIS/rest/services/IncidentsReport/FeatureServer/0"
        });
        editFeature = new Graphic({
          geometry: {"x":-13045225.476165969,"y":4037520.6326898774},
          attributes: {
            IncidentType: 1
          }
        });
        const edits = {
          addFeatures: [editFeature]
        };
        featureLayer.load().then(function(){
          featureLayer.applyEdits(edits).then(function(editsResult) {
            if (editsResult.addFeatureResults.length > 0) {
              objectId = editsResult.addFeatureResults[0].objectId;
              console.info("Feature sucessfully added with ObjectId of: " + objectId);
            }
          });
        });
      });
    </script>
  </head>

  <body>
    <div></div>
  </body>
</html>