bulk applyEdits to a GeoJSONLayer

590
1
Jump to solution
02-23-2022 05:38 AM
ArnauForner
New Contributor II

Hello,

I am trying to partially reuse the example described in this sample:
https://developers.arcgis.com/javascript/latest/sample-code/layers-featurelayer-collection-edits/

But using a GeoJSONlayer instead of a FeatureLayer.

In the code snippet below, the "geojson" variable is just a geojson object that contain 25 features (points).

When using featurelayer.applyEdits(), it plots all the points on the map.

While using geojsonlayer.applyEdits(), it just plots either 1 point, sometimes 2 points.

When inspecting the "console.log(editsResult)" in both cases 25 items have been added ("editsResult.addFeatureResults" property), but with geojsonlayer the objectids are the same

 

Any idea why this happens?

Thanks!

 

for (feature of geojson.features){
 let point = {
  type: "point",  
  longitude: feature.geometry.coordinates[0],
  latitude: feature.geometry.coordinates[1]
 }

 let pointGraphic = new Graphic({
  geometry: point
 })	 
 addFeatures.push(pointGraphic)
}

geojsonlayer.applyEdits({
 addFeatures:addFeatures
}).then((editsResult) => {
 console.log(editsResult)
})

 

console.log(editResults):

{
    "addFeatureResults": [
        {
            "objectId": "__OBJECTID-17f26c9a7de",
            "globalId": null,
            "error": null
        },
        {
            "objectId": "__OBJECTID-17f26c9a7de",
            "globalId": null,
            "error": null
        },
        {
            "objectId": "__OBJECTID-17f26c9a7de",
            "globalId": null,
            "error": null
        },
        {
            "objectId": "__OBJECTID-17f26c9a7de",
            "globalId": null,
            "error": null
        },
        {
            "objectId": "__OBJECTID-17f26c9a7de",
            "globalId": null,
            "error": null
        },
        {
            "objectId": "__OBJECTID-17f26c9a7de",
            "globalId": null,
            "error": null
        },
        {
            "objectId": "__OBJECTID-17f26c9a7de",
            "globalId": null,
            "error": null
        },
        {
            "objectId": "__OBJECTID-17f26c9a7de",
            "globalId": null,
            "error": null
        },
        {
            "objectId": "__OBJECTID-17f26c9a7de",
            "globalId": null,
            "error": null
        },
        {
            "objectId": "__OBJECTID-17f26c9a7de",
            "globalId": null,
            "error": null
        },
        {
            "objectId": "__OBJECTID-17f26c9a7de",
            "globalId": null,
            "error": null
        },
        {
            "objectId": "__OBJECTID-17f26c9a7de",
            "globalId": null,
            "error": null
        },
        {
            "objectId": "__OBJECTID-17f26c9a7de",
            "globalId": null,
            "error": null
        },
        {
            "objectId": "__OBJECTID-17f26c9a7de",
            "globalId": null,
            "error": null
        },
        {
            "objectId": "__OBJECTID-17f26c9a7de",
            "globalId": null,
            "error": null
        },
        {
            "objectId": "__OBJECTID-17f26c9a7de",
            "globalId": null,
            "error": null
        },
        {
            "objectId": "__OBJECTID-17f26c9a7de",
            "globalId": null,
            "error": null
        },
        {
            "objectId": "__OBJECTID-17f26c9a7de",
            "globalId": null,
            "error": null
        },
        {
            "objectId": "__OBJECTID-17f26c9a7de",
            "globalId": null,
            "error": null
        },
        {
            "objectId": "__OBJECTID-17f26c9a7de",
            "globalId": null,
            "error": null
        },
        {
            "objectId": "__OBJECTID-17f26c9a7de",
            "globalId": null,
            "error": null
        },
        {
            "objectId": "__OBJECTID-17f26c9a7de",
            "globalId": null,
            "error": null
        },
        {
            "objectId": "__OBJECTID-17f26c9a7de",
            "globalId": null,
            "error": null
        },
        {
            "objectId": "__OBJECTID-17f26c9a7de",
            "globalId": null,
            "error": null
        },
        {
            "objectId": "__OBJECTID-17f26c9a7de",
            "globalId": null,
            "error": null
        }
    ],
    "updateFeatureResults": [],
    "deleteFeatureResults": [],
    "addAttachmentResults": [],
    "updateAttachmentResults": [],
    "deleteAttachmentResults": []
}
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
UndralBatsukh
Esri Regular Contributor

Hi there, 

Looks like the issue exists when you initialize the GeoJSONLayer with geojson features that have string feature.ids. In this case, features will have string objectIds. Then you are passing in graphics without attributes and applyEdits return inconsistent and incorrect results. We created an issue for this and I will update you here once it is fixed. 

This issue will go away if you remove the string feature.ids from your initial geojson feed. This app shows this scenario: 

Or set up your geojson objects to be added via applyEdits to match the geojson objects from the initial feed. This app shows this scenario.

 

Hope this helps,

-Undral

View solution in original post

1 Reply
UndralBatsukh
Esri Regular Contributor

Hi there, 

Looks like the issue exists when you initialize the GeoJSONLayer with geojson features that have string feature.ids. In this case, features will have string objectIds. Then you are passing in graphics without attributes and applyEdits return inconsistent and incorrect results. We created an issue for this and I will update you here once it is fixed. 

This issue will go away if you remove the string feature.ids from your initial geojson feed. This app shows this scenario: 

Or set up your geojson objects to be added via applyEdits to match the geojson objects from the initial feed. This app shows this scenario.

 

Hope this helps,

-Undral