How to use applyedits on a client FeatureLayer, with renderers

04-05-2019 07:38 AM
New Contributor II


For a project, I am working on an app based on multiples FeatureLayers with the version 4.11.

The changes on the map are send with a WebSocket to the others clients online.

We must be able to see the changes on the view without any action, so without any refresh.

I tried, on recommandation, to separate the actions, one FeatureLayer interacting with the serveur and its "copy" managing the client. We could theoretically use applyEdits on both every time we update or add a feature from the view or from the WebSocket.

This is how I create the new client FeatureLayer (remember that we have multiple FeatureLayers) :

async function clientFeaturelayerList(layers: FeatureLayer[]) {
let clientFL = (layer) =>
await layer
.then((results) => {
let collection = new Collection<Graphic>();

let clientFL = new FeatureLayer({
source: collection,
title: layer.title,
id: `client_${layer.layerId}`,
layerId: layer.layerId,
objectIdField: layer.objectIdField,
fields: layer.fields,
renderer: layer.renderer,
opacity: layer.opacity,
return clientFL;
const clientFLList = await Promise.all(clientFL);
return clientFLList;

But it doesn't work. at least not when I use the featureTemplate to add a new feature.

I don't see the templates in the featureTemplates, just a blank space.

If I use the serverFeatureLayer for the featureTemplates, I do see the templates with the renderer but the function doesn't work. The new feature doesn't appear in the view even if it is send to the server and appear in the client graphics collection.

The problems may come from the templates :

templates.on("select", evtTemplate => {
const Id = evtTemplate.item.layer.layerId;
const newTemplate = new Graphic();
newTemplate.attributes = evtTemplate.template.prototype.attributes;

or from the applyedits, or even the treatments of the renderers

const editFeature = new Graphic({
geometry: event.mapPoint,
attributes: newTemplate.attributes

const edits = {
addFeatures: [editFeature]

clientFL.then(value => {
let FL = value.find(layer => layer.layerId === serveurFL.layerId);
FL.applyEdits(edits).then((result) => {
I don't know what to do.
Can someone help me, please?
0 Kudos
0 Replies